Class: Build::Files::Glob
Overview
Represents a glob pattern for matching files.
Constant Summary
Constants inherited from List
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Enumerate all paths matching the pattern.
-
#eql?(other) ⇒ Boolean
Check equality with another glob.
-
#full_pattern ⇒ Object
Get the full pattern including the root path.
-
#hash ⇒ Object
Compute the hash value for this glob.
-
#include?(path) ⇒ Boolean
Check if a path matches this glob pattern.
-
#initialize(root, pattern) ⇒ Glob
constructor
Initialize a glob with a root path and pattern.
-
#inspect ⇒ Object
Generate a string representation for debugging.
-
#rebase(root) ⇒ Object
Rebase the glob to a new root.
-
#roots ⇒ Object
Get the root paths for this glob.
Methods inherited from List
#+, #-, #==, coerce, #copy, #create, #delete, #empty?, #exist?, #intersects?, #map, #to_paths, #to_s, #touch, #with
Constructor Details
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
30 31 32 |
# File 'lib/build/files/glob.rb', line 30 def pattern @pattern end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
29 30 31 |
# File 'lib/build/files/glob.rb', line 29 def root @root end |
Instance Method Details
#each(&block) ⇒ Object
Enumerate all paths matching the pattern.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/build/files/glob.rb', line 45 def each(&block) return to_enum unless block_given? ::Dir.glob(full_pattern, ::File::FNM_DOTMATCH) do |path| # Ignore `.` and `..` entries. next if path =~ /\/..?$/ yield Path.new(path, @root) end end |
#eql?(other) ⇒ Boolean
Check equality with another glob.
59 60 61 |
# File 'lib/build/files/glob.rb', line 59 def eql?(other) self.class.eql?(other.class) and @root.eql?(other.root) and @pattern.eql?(other.pattern) end |
#full_pattern ⇒ Object
Get the full pattern including the root path.
40 41 42 |
# File 'lib/build/files/glob.rb', line 40 def full_pattern Path.join(@root, @pattern) end |
#hash ⇒ Object
Compute the hash value for this glob.
65 66 67 |
# File 'lib/build/files/glob.rb', line 65 def hash [@root, @pattern].hash end |
#include?(path) ⇒ Boolean
Check if a path matches this glob pattern.
72 73 74 |
# File 'lib/build/files/glob.rb', line 72 def include?(path) File.fnmatch(full_pattern, path) end |
#inspect ⇒ Object
Generate a string representation for debugging.
85 86 87 |
# File 'lib/build/files/glob.rb', line 85 def inspect "<Glob #{full_pattern.inspect}>" end |
#rebase(root) ⇒ Object
Rebase the glob to a new root.
79 80 81 |
# File 'lib/build/files/glob.rb', line 79 def rebase(root) self.class.new(root, @pattern) end |
#roots ⇒ Object
Get the root paths for this glob.
34 35 36 |
# File 'lib/build/files/glob.rb', line 34 def roots [@root] end |