Class: Build::Files::List

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/build/files/list.rb,
lib/build/files/system.rb

Overview

A list of paths, where #each yields instances of Path.

Direct Known Subclasses

Composite, Difference, Directory, Glob, Paths, State

Constant Summary collapse

NONE =
Composite.new([]).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.coerce(arg) ⇒ Object

Coerce an argument to a List instance.



104
105
106
107
108
109
110
# File 'lib/build/files/list.rb', line 104

def self.coerce(arg)
	if arg.kind_of? self
		arg
	else
		Paths.new(arg)
	end
end

Instance Method Details

#+(list) ⇒ Object

Create a composite list out of two other lists:



21
22
23
# File 'lib/build/files/list.rb', line 21

def +(list)
	Composite.new([self, list])
end

#-(list) ⇒ Object

Subtract a list from this list.



28
29
30
# File 'lib/build/files/list.rb', line 28

def -(list)
	Difference.new(self, list)
end

#==(other) ⇒ Object

This isn’t very efficient, but it IS generic.



33
34
35
36
37
38
39
40
41
# File 'lib/build/files/list.rb', line 33

def ==(other)
	if self.class == other.class
		self.eql?(other)
	elsif other.kind_of? self.class
		self.to_a.sort == other.to_a.sort
	else
		super
	end
end

#copy(destination) ⇒ Object

Copy all files in the list to a destination.



125
126
127
128
129
# File 'lib/build/files/system.rb', line 125

def copy(destination)
	each do |path|
		path.copy(destination / path.relative_path)
	end
end

#createObject

Recursively create paths for all listed paths.



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

def create
	each(&:create)
end

#deleteObject

Recursively delete all paths and all contents within those paths.



119
120
121
# File 'lib/build/files/system.rb', line 119

def delete
	each(&:delete)
end

#empty?Boolean

Check if the list is empty.

Returns:

  • (Boolean)


50
51
52
53
54
55
56
# File 'lib/build/files/list.rb', line 50

def empty?
	each do
		return false
	end
	
	return true
end

#exist?Boolean

Check that all files listed exist.

Returns:

  • (Boolean)


109
110
111
# File 'lib/build/files/system.rb', line 109

def exist?
	all?(&:exist?)
end

#intersects?(other) ⇒ Boolean

Does this list of files include the path of any other?

Returns:

  • (Boolean)


44
45
46
# File 'lib/build/files/list.rb', line 44

def intersects? other
	other.any?{|path| include?(path)}
end

#mapObject

Map over the list and return a Paths instance.



97
98
99
# File 'lib/build/files/list.rb', line 97

def map
	Paths.new(super)
end

#rebase(root) ⇒ Object

Rebase all paths in the list to a new root.



83
84
85
# File 'lib/build/files/list.rb', line 83

def rebase(root)
	Paths.new(self.collect{|path| path.rebase(root)}, [root])
end

#rootsObject

Get all unique root paths from the list.



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

def roots
	collect{|path| path.root}.sort.uniq
end

#to_pathsObject

Convert the list to a Paths instance.



89
90
91
# File 'lib/build/files/list.rb', line 89

def to_paths
	Paths.new(each.to_a)
end

#to_sObject

Convert the list to a string.



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

def to_s
	inspect
end

#touchObject

Touch all listed files.



104
105
106
# File 'lib/build/files/system.rb', line 104

def touch
	each(&:touch)
end

#with(**options) ⇒ Object

Transform paths with modified attributes.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/build/files/list.rb', line 64

def with(**options)
	return to_enum(:with, **options) unless block_given?
	
	paths = []
	
	self.each do |path|
		updated_path = path.with(**options)
		
		yield path, updated_path
		
		paths << updated_path
	end
	
	return Paths.new(paths)
end