Class: Build::Files::Composite

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

Constant Summary

Constants inherited from List

List::NONE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from List

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

Constructor Details

#initialize(files, roots = nil) ⇒ Composite

Returns a new instance of Composite.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/build/files/composite.rb', line 11

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.



29
30
31
# File 'lib/build/files/composite.rb', line 29

def files
  @files
end

Instance Method Details

#+(list) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/build/files/composite.rb', line 57

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

#eachObject



37
38
39
40
41
42
43
# File 'lib/build/files/composite.rb', line 37

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)


49
50
51
# File 'lib/build/files/composite.rb', line 49

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

#freezeObject



31
32
33
34
35
# File 'lib/build/files/composite.rb', line 31

def freeze
	self.roots
	
	super
end

#hashObject



53
54
55
# File 'lib/build/files/composite.rb', line 53

def hash
	@files.hash
end

#include?(path) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/build/files/composite.rb', line 65

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

#inspectObject



77
78
79
# File 'lib/build/files/composite.rb', line 77

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

#rebase(root) ⇒ Object



69
70
71
# File 'lib/build/files/composite.rb', line 69

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

#rootsObject



45
46
47
# File 'lib/build/files/composite.rb', line 45

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

#to_pathsObject



73
74
75
# File 'lib/build/files/composite.rb', line 73

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