Class: Covered::Include

Inherits:
Wrapper show all
Defined in:
lib/covered/files.rb

Overview

Includes coverage for files matching a glob pattern.

Instance Attribute Summary collapse

Attributes inherited from Wrapper

#The wrapped output., #output

Instance Method Summary collapse

Methods inherited from Wrapper

#accept?, #add, #clear, #expand_path, #finish, #mark, #relative_path, #start, #to_h

Methods inherited from Base

#accept?, #add, #clear, #expand_path, #finish, #mark, #relative_path, #start

Constructor Details

#initialize(output, pattern, base = "") ⇒ Include

Initialize an include filter for the given glob pattern.



84
85
86
87
88
89
# File 'lib/covered/files.rb', line 84

def initialize(output, pattern, base = "")
	super(output)
	
	@pattern = pattern
	@base = base
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



92
93
94
# File 'lib/covered/files.rb', line 92

def pattern
  @pattern
end

#The glob pattern to include.(globpatterntoinclude.) ⇒ Object (readonly)



92
# File 'lib/covered/files.rb', line 92

attr :pattern

Instance Method Details

#each(&block) ⇒ Object

Enumerate existing coverage and synthesize empty coverage for unmatched included files.



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/covered/files.rb', line 113

def each(&block)
	paths = glob
	
	super do |coverage|
		paths.delete(coverage.path)
		
		yield coverage
	end
	
	paths.each do |path|
		yield Coverage.for(path)
	end
end

#globObject

Resolve the include pattern to real file paths.



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/covered/files.rb', line 96

def glob
	paths = Set.new
	root = self.expand_path(@base)
	pattern = File.expand_path(@pattern, root)
	
	Dir.glob(pattern) do |path|
		unless File.directory?(path)
			paths << File.realpath(path)
		end
	end
	
	return paths
end