Class: Build::Files::Paths

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

Overview

Represents an explicit list of file paths.

Constant Summary

Constants inherited from List

List::NONE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from List

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

Constructor Details

#initialize(list, roots = nil) ⇒ Paths

Initialize a paths list.



15
16
17
18
# File 'lib/build/files/paths.rb', line 15

def initialize(list, roots = nil)
	@list = Array(list).freeze
	@roots = roots
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



20
21
22
# File 'lib/build/files/paths.rb', line 20

def list
  @list
end

Class Method Details

.directory(root, relative_paths) ⇒ Object

Create a paths list from a directory root and relative paths.



71
72
73
74
75
76
77
# File 'lib/build/files/paths.rb', line 71

def self.directory(root, relative_paths)
	paths = relative_paths.collect do |path|
		Path.join(root, path)
	end
	
	self.new(paths, [root])
end

Instance Method Details

#countObject

Get the count of paths in the list.



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

def count
	@list.count
end

#eachObject

Iterate over all paths in the list.



36
37
38
39
40
# File 'lib/build/files/paths.rb', line 36

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

#eql?(other) ⇒ Boolean

Check equality with another paths list.

Returns:

  • (Boolean)


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

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

#hashObject

Compute the hash value for this paths list.



51
52
53
# File 'lib/build/files/paths.rb', line 51

def hash
	@list.hash
end

#inspectObject

Generate a string representation for debugging.



63
64
65
# File 'lib/build/files/paths.rb', line 63

def inspect
	"<Paths #{@list.inspect}>"
end

#rootsObject

The list of roots for a given list of immutable files is also immutable, so we cache it for performance:



23
24
25
# File 'lib/build/files/paths.rb', line 23

def roots
	@roots ||= super
end

#to_pathsObject

Return this paths list unchanged.



57
58
59
# File 'lib/build/files/paths.rb', line 57

def to_paths
	self
end