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

Constant Summary collapse

NONE =
Composite.new([]).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.coerce(arg) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/build/files/list.rb', line 86

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:



34
35
36
# File 'lib/build/files/list.rb', line 34

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

#-(list) ⇒ Object



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

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

#==(other) ⇒ Object

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



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

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

#createObject

Recursively create paths for all listed paths.



111
112
113
# File 'lib/build/files/system.rb', line 111

def create
	each(&:create)
end

#deleteObject

Recursively delete all paths and all contents within those paths.



116
117
118
# File 'lib/build/files/system.rb', line 116

def delete
	each(&:delete)
end

#exist?Boolean

Check that all files listed exist.

Returns:

  • (Boolean)


106
107
108
# File 'lib/build/files/system.rb', line 106

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

#intersects?(other) ⇒ Boolean

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

Returns:

  • (Boolean)


54
55
56
# File 'lib/build/files/list.rb', line 54

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

#mapObject



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

def map
	Paths.new(super)
end

#rebase(root) ⇒ Object



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

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

#rootsObject



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

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

#to_pathsObject



78
79
80
# File 'lib/build/files/list.rb', line 78

def to_paths
	Paths.new(each.to_a)
end

#to_sObject



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

def to_s
	inspect
end

#touchObject

Touch all listed files.



101
102
103
# File 'lib/build/files/system.rb', line 101

def touch
	each(&:touch)
end

#with(**options) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/build/files/list.rb', line 58

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