Class: Build::Files::Composite

Inherits:
List
  • Object
show all
Defined in:
lib/build/files/list.rb

Constant Summary

Constants inherited from List

List::NONE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from List

#==, coerce, #create, #delete, #exist?, #intersects?, #map, #to_s, #touch, #with

Constructor Details

#initialize(files, roots = nil) ⇒ Composite

Returns a new instance of Composite.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/build/files/list.rb', line 96

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

#filesObject (readonly)

Returns the value of attribute files.



114
115
116
# File 'lib/build/files/list.rb', line 114

def files
  @files
end

Instance Method Details

#+(list) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/build/files/list.rb', line 142

def +(list)
	if list.kind_of? Composite
		self.class.new(@files + list.files)
	else
		self.class.new(@files + [list])
	end
end

#eachObject



122
123
124
125
126
127
128
# File 'lib/build/files/list.rb', line 122

def each
	return to_enum(:each) unless block_given?
	
	@files.each do |files|
		files.each{|path| yield path}
	end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/build/files/list.rb', line 134

def eql?(other)
	self.class.eql?(other.class) and @files.eql?(other.files)
end

#freezeObject



116
117
118
119
120
# File 'lib/build/files/list.rb', line 116

def freeze
	self.roots
	
	super
end

#hashObject



138
139
140
# File 'lib/build/files/list.rb', line 138

def hash
	@files.hash
end

#include?(path) ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/build/files/list.rb', line 150

def include?(path)
	@files.any? {|list| list.include?(path)}
end

#inspectObject



162
163
164
# File 'lib/build/files/list.rb', line 162

def inspect
	"<Composite #{@files.inspect}>"
end

#rebase(root) ⇒ Object



154
155
156
# File 'lib/build/files/list.rb', line 154

def rebase(root)
	self.class.new(@files.collect{|list| list.rebase(root)}, [root])
end

#rootsObject



130
131
132
# File 'lib/build/files/list.rb', line 130

def roots
	@roots ||= @files.collect(&:roots).flatten.uniq
end

#to_pathsObject



158
159
160
# File 'lib/build/files/list.rb', line 158

def to_paths
	self.class.new(@files.collect(&:to_paths), roots: @roots)
end