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, 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



82
83
84
85
86
87
88
# File 'lib/build/files/list.rb', line 82

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

#==(other) ⇒ Object

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



39
40
41
42
43
44
45
46
47
# File 'lib/build/files/list.rb', line 39

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.



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

def create
	each(&:create)
end

#deleteObject

Recursively delete all paths and all contents within those paths.



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

def delete
	each(&:delete)
end

#exist?Boolean

Check that all files listed exist.

Returns:

  • (Boolean)


90
91
92
# File 'lib/build/files/system.rb', line 90

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

#intersects?(other) ⇒ Boolean

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

Returns:

  • (Boolean)


50
51
52
# File 'lib/build/files/list.rb', line 50

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

#mapObject



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

def map
	Paths.new(super)
end

#rebase(root) ⇒ Object



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

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



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

def to_paths
	Paths.new(each.to_a)
end

#to_sObject



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

def to_s
	inspect
end

#touchObject

Touch all listed files.



85
86
87
# File 'lib/build/files/system.rb', line 85

def touch
	each(&:touch)
end

#with(**args) ⇒ Object



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

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