Class: Build::Files::Glob

Inherits:
List
  • Object
show all
Defined in:
lib/build/files/glob.rb

Overview

Represents a glob pattern for matching files.

Constant Summary

Constants inherited from List

List::NONE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from List

#+, #-, #==, coerce, #copy, #create, #delete, #empty?, #exist?, #intersects?, #map, #to_paths, #to_s, #touch, #with

Constructor Details

#initialize(root, pattern) ⇒ Glob

Initialize a glob with a root path and pattern.



24
25
26
27
# File 'lib/build/files/glob.rb', line 24

def initialize(root, pattern)
	@root = root
	@pattern = pattern
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



30
31
32
# File 'lib/build/files/glob.rb', line 30

def pattern
  @pattern
end

#rootObject (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.

Returns:

  • (Boolean)


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_patternObject

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

#hashObject

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.

Returns:

  • (Boolean)


72
73
74
# File 'lib/build/files/glob.rb', line 72

def include?(path)
	File.fnmatch(full_pattern, path)
end

#inspectObject

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

#rootsObject

Get the root paths for this glob.



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

def roots
	[@root]
end