Class: Build::Files::Directory
- Defined in:
- lib/build/files/directory.rb
Overview
Represents a directory of files.
Constant Summary
Constants inherited from List
Class Method Summary collapse
-
.join(*args) ⇒ Object
Join path components and create a directory.
Instance Method Summary collapse
-
#each ⇒ Object
Iterate over all files in the directory recursively.
-
#eql?(other) ⇒ Boolean
Check equality with another directory.
-
#hash ⇒ Object
Compute the hash value for this directory.
-
#include?(path) ⇒ Boolean
Check if the directory includes a specific path.
-
#initialize(root) ⇒ Directory
constructor
Initialize a directory with a root path.
-
#rebase(root) ⇒ Object
Rebase the directory to a new root.
-
#root ⇒ Object
Get the root path of the directory.
-
#roots ⇒ Object
Get the root paths as an array.
-
#to_path ⇒ Object
Convert the directory to a path object.
-
#to_s ⇒ Object
Convert the directory to a string.
-
#to_str ⇒ Object
Convert the directory to a string for use as a command argument.
Methods inherited from List
#+, #-, #==, coerce, #copy, #create, #delete, #empty?, #exist?, #intersects?, #map, #to_paths, #touch, #with
Constructor Details
Class Method Details
Instance Method Details
#each ⇒ Object
Iterate over all files in the directory recursively.
40 41 42 43 44 45 46 47 |
# File 'lib/build/files/directory.rb', line 40 def each return to_enum(:each) unless block_given? # We match both normal files with * and dotfiles with .?* Dir.glob(@root + "**/{*,.?*}") do |path| yield Path.new(path, @root) end end |
#eql?(other) ⇒ Boolean
Check equality with another directory.
52 53 54 |
# File 'lib/build/files/directory.rb', line 52 def eql?(other) self.class.eql?(other.class) and @root.eql?(other.root) end |
#hash ⇒ Object
Compute the hash value for this directory.
58 59 60 |
# File 'lib/build/files/directory.rb', line 58 def hash @root.hash end |
#include?(path) ⇒ Boolean
Check if the directory includes a specific path.
65 66 67 68 |
# File 'lib/build/files/directory.rb', line 65 def include?(path) # Would be true if path is a descendant of full_path. path.start_with?(@root) end |
#rebase(root) ⇒ Object
Rebase the directory to a new root.
73 74 75 |
# File 'lib/build/files/directory.rb', line 73 def rebase(root) self.class.new(@root.rebase(root)) end |
#root ⇒ Object
Get the root path of the directory.
27 28 29 |
# File 'lib/build/files/directory.rb', line 27 def root @root end |
#roots ⇒ Object
Get the root paths as an array.
33 34 35 |
# File 'lib/build/files/directory.rb', line 33 def roots [root] end |
#to_path ⇒ Object
Convert the directory to a path object.
91 92 93 |
# File 'lib/build/files/directory.rb', line 91 def to_path @root end |
#to_s ⇒ Object
Convert the directory to a string.
85 86 87 |
# File 'lib/build/files/directory.rb', line 85 def to_s to_str end |
#to_str ⇒ Object
Convert the directory to a string for use as a command argument.
79 80 81 |
# File 'lib/build/files/directory.rb', line 79 def to_str @root.to_str end |