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, #intersects?, #map, #with

Constructor Details

#initialize(files, roots = nil) ⇒ Composite

Returns a new instance of Composite.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/build/files/list.rb', line 129

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.



147
148
149
# File 'lib/build/files/list.rb', line 147

def files
  @files
end

Instance Method Details

#+(list) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/build/files/list.rb', line 169

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

#eachObject



149
150
151
152
153
154
155
# File 'lib/build/files/list.rb', line 149

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)


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

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

#hashObject



165
166
167
# File 'lib/build/files/list.rb', line 165

def hash
	@files.hash
end

#include?(path) ⇒ Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/build/files/list.rb', line 177

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

#inspectObject



189
190
191
# File 'lib/build/files/list.rb', line 189

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

#rebase(root) ⇒ Object



181
182
183
# File 'lib/build/files/list.rb', line 181

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

#rootsObject



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

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

#to_pathsObject



185
186
187
# File 'lib/build/files/list.rb', line 185

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