Class: Rubble::FileSet

Inherits:
Object
  • Object
show all
Defined in:
lib/rubble/file_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, *files) ⇒ FileSet

Returns a new instance of FileSet.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubble/file_set.rb', line 8

def initialize(dir, *files)
    @dir = Pathname.pwd + Pathname(dir)
    if files.nil? then
        @files = []
    else
        flattened_files = (files || []).collect {|f| Array(f)}.flatten

        @files = flattened_files.map do |f|
            p = (@dir + Pathname(f)).relative_path_from(@dir)
            if p.to_s.start_with?('../') or p.to_s == '.' then
                raise ArgumentError, "File name '#{f}' must be relative to base directory #{@dir} of the file set."
            end
            p
        end

        @files.sort!
    end

    @files.freeze
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



5
6
7
# File 'lib/rubble/file_set.rb', line 5

def dir
  @dir
end

#filesObject (readonly)

Returns the value of attribute files.



6
7
8
# File 'lib/rubble/file_set.rb', line 6

def files
  @files
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rubble/file_set.rb', line 33

def empty?
    @files.empty?
end

#pathsObject



29
30
31
# File 'lib/rubble/file_set.rb', line 29

def paths
    @files.map {|f| @dir + f}
end

#to_sObject



37
38
39
# File 'lib/rubble/file_set.rb', line 37

def to_s
    to_yaml
end