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, #copy, #create, #delete, #empty?, #exist?, #intersects?, #map, #to_paths, #to_s, #touch, #with

Constructor Details

#initialize(root, pattern) ⇒ Glob

Returns a new instance of Glob.



17
18
19
20
# File 'lib/build/files/glob.rb', line 17

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

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



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

def pattern
  @pattern
end

#rootObject (readonly)

Returns the value of attribute root.



22
23
24
# File 'lib/build/files/glob.rb', line 22

def root
  @root
end

Instance Method Details

#each(&block) ⇒ Object

Enumerate all paths matching the pattern.



34
35
36
37
38
39
40
41
42
43
# File 'lib/build/files/glob.rb', line 34

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)


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

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

#full_patternObject



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

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

#hashObject



49
50
51
# File 'lib/build/files/glob.rb', line 49

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

#include?(path) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/build/files/glob.rb', line 53

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

#inspectObject



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

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

#rebase(root) ⇒ Object



57
58
59
# File 'lib/build/files/glob.rb', line 57

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

#rootsObject



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

def roots
	[@root]
end