CoveredSourceCoveredPolicy

class Policy

Configures coverage collection, filtering, persistence and reports.

Nested

Definitions

def initialize

Initialize a policy with an empty file collection.

Implementation

def initialize
	super(Files.new)
	
	@reports = []
	@capture = nil
end

attr :output

Signature

attribute Covered::Base

The current output pipeline.

def freeze

Freeze the policy and eagerly build the capture pipeline.

Signature

returns Covered::Policy

This frozen policy.

Implementation

def freeze
	return self if frozen?
	
	capture
	@reports.freeze
	
	super
end

def include(...)

Include files matching the given pattern in coverage results. Arguments are forwarded to Covered::Include#initialize.

Implementation

def include(...)
	@output = Include.new(@output, ...)
end

def skip(...)

Exclude files matching the given pattern from coverage results. Arguments are forwarded to Covered::Skip#initialize.

Implementation

def skip(...)
	@output = Skip.new(@output, ...)
end

def only(...)

Restrict coverage results to files matching the given pattern. Arguments are forwarded to Covered::Only#initialize.

Implementation

def only(...)
	@output = Only.new(@output, ...)
end

def root(...)

Restrict coverage results to the given project root. Arguments are forwarded to Covered::Root#initialize.

Implementation

def root(...)
	@output = Root.new(@output, ...)
end

def persist!(...)

Persist coverage results to a database. Arguments are forwarded to Covered::Persist#initialize.

Implementation

def persist!(...)
	@output = Persist.new(@output, ...)
end

def capture

The runtime capture pipeline for this policy.

Signature

returns Covered::Forks

The memoized capture pipeline.

Implementation

def capture
	@capture ||= Forks.new(
		Capture.new(@output)
	)
end

def start

Start collecting coverage.

Implementation

def start
	capture.start
end

def finish

Finish collecting coverage.

Implementation

def finish
	capture.finish
end

attr :reports

Signature

attribute Array

The configured report objects or autoloaders.

def reports!(reports)

Configure reports from names, booleans, arrays or report objects.

Signature

parameter reports String | Boolean | Array | Object | Nil

The reports to configure.

Implementation

def reports!(reports)
	if reports.nil?
		return
	elsif reports.is_a?(String)
		names = reports.split(",")
		
		names.each do |name|
			begin
				klass = Covered.const_get(name)
				@reports << klass.new
			rescue NameError
				@reports << Autoload.new(name)
			end
		end
	elsif reports == true
		@reports << Covered::BriefSummary.new
	elsif reports == false
		@reports.clear
	elsif reports.is_a?(Array)
		@reports.concat(reports)
	else
		@reports << reports
	end
end

def call(...)

Generate all configured reports. Arguments are forwarded to each report.

Implementation

def call(...)
	@reports.each do |report|
		report.call(self, ...)
	end
end