Class: Build::Files::Composite
- Defined in:
- lib/build/files/composite.rb
Overview
Represents a composite list of files from multiple sources.
Constant Summary
Constants inherited from List
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
-
#+(list) ⇒ Object
Combine this composite with another list.
-
#each ⇒ Object
Iterate over all files in the composite list.
-
#eql?(other) ⇒ Boolean
Check equality with another composite list.
-
#freeze ⇒ Object
Freeze the composite list and its dependencies.
-
#hash ⇒ Object
Compute the hash value for this composite.
-
#include?(path) ⇒ Boolean
Check if the composite includes a specific path.
-
#initialize(files, roots = nil) ⇒ Composite
constructor
Initialize a composite list with multiple file lists.
-
#inspect ⇒ Object
Generate a string representation for debugging.
-
#rebase(root) ⇒ Object
Rebase all lists in the composite to a new root.
-
#roots ⇒ Object
Get all root paths for all lists in the composite.
-
#to_paths ⇒ Object
Convert all lists in the composite to paths.
Methods inherited from List
#-, #==, coerce, #copy, #create, #delete, #empty?, #exist?, #intersects?, #map, #to_s, #touch, #with
Constructor Details
#initialize(files, roots = nil) ⇒ Composite
Initialize a composite list with multiple file lists.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/build/files/composite.rb', line 15 def initialize(files, roots = nil) @files = [] files.each do |list| if list.kind_of? Composite @files += list.files elsif list.kind_of? List @files << list else # Try to convert into a explicit paths list: @files << Paths.new(list) end end @files.freeze @roots = roots end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
33 34 35 |
# File 'lib/build/files/composite.rb', line 33 def files @files end |
Instance Method Details
#+(list) ⇒ Object
Combine this composite with another list.
75 76 77 78 79 80 81 |
# File 'lib/build/files/composite.rb', line 75 def +(list) if list.kind_of? Composite self.class.new(@files + list.files) else self.class.new(@files + [list]) end end |
#each ⇒ Object
Iterate over all files in the composite list.
45 46 47 48 49 50 51 |
# File 'lib/build/files/composite.rb', line 45 def each return to_enum(:each) unless block_given? @files.each do |files| files.each{|path| yield path} end end |
#eql?(other) ⇒ Boolean
Check equality with another composite list.
62 63 64 |
# File 'lib/build/files/composite.rb', line 62 def eql?(other) self.class.eql?(other.class) and @files.eql?(other.files) end |
#freeze ⇒ Object
Freeze the composite list and its dependencies.
36 37 38 39 40 |
# File 'lib/build/files/composite.rb', line 36 def freeze self.roots super end |
#hash ⇒ Object
Compute the hash value for this composite.
68 69 70 |
# File 'lib/build/files/composite.rb', line 68 def hash @files.hash end |
#include?(path) ⇒ Boolean
Check if the composite includes a specific path.
86 87 88 |
# File 'lib/build/files/composite.rb', line 86 def include?(path) @files.any?{|list| list.include?(path)} end |
#inspect ⇒ Object
Generate a string representation for debugging.
105 106 107 |
# File 'lib/build/files/composite.rb', line 105 def inspect "<Composite #{@files.inspect}>" end |
#rebase(root) ⇒ Object
Rebase all lists in the composite to a new root.
93 94 95 |
# File 'lib/build/files/composite.rb', line 93 def rebase(root) self.class.new(@files.collect{|list| list.rebase(root)}, [root]) end |
#roots ⇒ Object
Get all root paths for all lists in the composite.
55 56 57 |
# File 'lib/build/files/composite.rb', line 55 def roots @roots ||= @files.collect(&:roots).flatten.uniq end |
#to_paths ⇒ Object
Convert all lists in the composite to paths.
99 100 101 |
# File 'lib/build/files/composite.rb', line 99 def to_paths self.class.new(@files.collect(&:to_paths), roots: @roots) end |