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



79
80
81
82
83
84
85
# File 'lib/build/files/list.rb', line 79

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:



19
20
21
# File 'lib/build/files/list.rb', line 19

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

#-(list) ⇒ Object



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

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

#==(other) ⇒ Object

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



28
29
30
31
32
33
34
35
36
# File 'lib/build/files/list.rb', line 28

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



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

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

#createObject

Recursively create paths for all listed paths.



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

def create
	each(&:create)
end

#deleteObject

Recursively delete all paths and all contents within those paths.



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

def delete
	each(&:delete)
end

#empty?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
# File 'lib/build/files/list.rb', line 43

def empty?
	each do
		return false
	end
	
	return true
end

#exist?Boolean

Check that all files listed exist.

Returns:

  • (Boolean)


99
100
101
# File 'lib/build/files/system.rb', line 99

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

#intersects?(other) ⇒ Boolean

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

Returns:

  • (Boolean)


39
40
41
# File 'lib/build/files/list.rb', line 39

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

#mapObject



75
76
77
# File 'lib/build/files/list.rb', line 75

def map
	Paths.new(super)
end

#rebase(root) ⇒ Object



67
68
69
# File 'lib/build/files/list.rb', line 67

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

#rootsObject



14
15
16
# File 'lib/build/files/list.rb', line 14

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

#to_pathsObject



71
72
73
# File 'lib/build/files/list.rb', line 71

def to_paths
	Paths.new(each.to_a)
end

#to_sObject



87
88
89
# File 'lib/build/files/list.rb', line 87

def to_s
	inspect
end

#touchObject

Touch all listed files.



94
95
96
# File 'lib/build/files/system.rb', line 94

def touch
	each(&:touch)
end

#with(**options) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/build/files/list.rb', line 51

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