Class: Build::Files::List
- Inherits:
-
Object
- Object
- Build::Files::List
- 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.
Constant Summary collapse
Class Method Summary collapse
-
.coerce(arg) ⇒ Object
Coerce an argument to a List instance.
Instance Method Summary collapse
-
#+(list) ⇒ Object
Create a composite list out of two other lists:.
-
#-(list) ⇒ Object
Subtract a list from this list.
-
#==(other) ⇒ Object
This isn’t very efficient, but it IS generic.
-
#copy(destination) ⇒ Object
Copy all files in the list to a destination.
-
#create ⇒ Object
Recursively create paths for all listed paths.
-
#delete ⇒ Object
Recursively delete all paths and all contents within those paths.
-
#empty? ⇒ Boolean
Check if the list is empty.
-
#exist? ⇒ Boolean
Check that all files listed exist.
-
#intersects?(other) ⇒ Boolean
Does this list of files include the path of any other?.
-
#map ⇒ Object
Map over the list and return a Paths instance.
-
#rebase(root) ⇒ Object
Rebase all paths in the list to a new root.
-
#roots ⇒ Object
Get all unique root paths from the list.
-
#to_paths ⇒ Object
Convert the list to a Paths instance.
-
#to_s ⇒ Object
Convert the list to a string.
-
#touch ⇒ Object
Touch all listed files.
-
#with(**options) ⇒ Object
Transform paths with modified attributes.
Class Method Details
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 |
#create ⇒ Object
Recursively create paths for all listed paths.
114 115 116 |
# File 'lib/build/files/system.rb', line 114 def create each(&:create) end |
#delete ⇒ Object
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.
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.
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?
44 45 46 |
# File 'lib/build/files/list.rb', line 44 def intersects? other other.any?{|path| include?(path)} end |
#map ⇒ Object
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 |
#roots ⇒ Object
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_paths ⇒ Object
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_s ⇒ Object
Convert the list to a string.
114 115 116 |
# File 'lib/build/files/list.rb', line 114 def to_s inspect end |
#touch ⇒ Object
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(**) return to_enum(:with, **) unless block_given? paths = [] self.each do |path| updated_path = path.with(**) yield path, updated_path paths << updated_path end return Paths.new(paths) end |