Class: Build::Files::Glob

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

Constant Summary

Constants inherited from List

List::NONE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from List

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

Constructor Details

#initialize(root, pattern) ⇒ Glob

Returns a new instance of Glob.



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

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

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



38
39
40
# File 'lib/build/files/glob.rb', line 38

def pattern
  @pattern
end

#rootObject (readonly)

Returns the value of attribute root.



37
38
39
# File 'lib/build/files/glob.rb', line 37

def root
  @root
end

Instance Method Details

#each(&block) ⇒ Object

Enumerate all paths matching the pattern.



49
50
51
52
53
54
55
56
57
58
# File 'lib/build/files/glob.rb', line 49

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

Returns:

  • (Boolean)


60
61
62
# File 'lib/build/files/glob.rb', line 60

def eql?(other)
	self.class.eql?(other.class) and @root.eql?(other.root) and @pattern.eql?(other.pattern)
end

#full_patternObject



44
45
46
# File 'lib/build/files/glob.rb', line 44

def full_pattern
	Path.join(@root, @pattern)
end

#hashObject



64
65
66
# File 'lib/build/files/glob.rb', line 64

def hash
	[@root, @pattern].hash
end

#include?(path) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/build/files/glob.rb', line 68

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

#inspectObject



76
77
78
# File 'lib/build/files/glob.rb', line 76

def inspect
	"<Glob #{full_pattern.inspect}>"
end

#rebase(root) ⇒ Object



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

def rebase(root)
	self.class.new(root, @pattern)
end

#rootsObject



40
41
42
# File 'lib/build/files/glob.rb', line 40

def roots
	[@root]
end