Class: Build::Files::Composite

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

Overview

Represents a composite list of files from multiple sources.

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

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

#filesObject (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

#eachObject

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.

Returns:

  • (Boolean)


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

#freezeObject

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

#hashObject

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.

Returns:

  • (Boolean)


86
87
88
# File 'lib/build/files/composite.rb', line 86

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

#inspectObject

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

#rootsObject

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_pathsObject

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