CoveredSourceCoveredInclude

class Include

Includes coverage for files matching a glob pattern.

Definitions

def initialize(output, pattern, base = "")

Initialize an include filter for the given glob pattern.

Signature

parameter output Covered::Base

The output to wrap.

parameter pattern String

The glob pattern to include.

parameter base String

The base path used to expand the glob.

Implementation

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

attr :pattern

Signature

attribute String

The glob pattern to include.

def glob

Resolve the include pattern to real file paths.

Signature

returns Set(String)

The real paths matched by the include pattern.

Implementation

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

def each(&block)

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

Signature

yields {|coverage| ...}

Each existing or synthesized coverage object.

parameter coverage Covered::Coverage

The current coverage object.

Implementation

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