Class: Covered::Policy

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

Overview

Configures coverage collection, filtering, persistence and reports.

Defined Under Namespace

Classes: Autoload

Instance Attribute Summary collapse

Attributes inherited from Wrapper

#The wrapped output.

Instance Method Summary collapse

Methods inherited from Wrapper

#accept?, #add, #clear, #each, #expand_path, #mark, #relative_path, #to_h

Methods inherited from Base

#accept?, #add, #clear, #each, #expand_path, #mark, #relative_path

Constructor Details

#initializePolicy

Initialize a policy with an empty file collection.



16
17
18
19
20
21
# File 'lib/covered/policy.rb', line 16

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

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



24
25
26
# File 'lib/covered/policy.rb', line 24

def output
  @output
end

#reportsObject (readonly)

Returns the value of attribute reports.



86
87
88
# File 'lib/covered/policy.rb', line 86

def reports
  @reports
end

#The configured report objects or autoloaders.(configuredreportobjects) ⇒ Object (readonly)



86
# File 'lib/covered/policy.rb', line 86

attr :reports

#The current output pipeline.(currentoutputpipeline.) ⇒ Object (readonly)



24
# File 'lib/covered/policy.rb', line 24

attr :output

Instance Method Details

#callObject

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



162
163
164
165
166
# File 'lib/covered/policy.rb', line 162

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

#captureObject

The runtime capture pipeline for this policy.



69
70
71
72
73
# File 'lib/covered/policy.rb', line 69

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

#finishObject

Finish collecting coverage.



81
82
83
# File 'lib/covered/policy.rb', line 81

def finish
	capture.finish
end

#freezeObject

Freeze the policy and eagerly build the capture pipeline.



28
29
30
31
32
33
34
35
# File 'lib/covered/policy.rb', line 28

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

#includeObject

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



39
40
41
# File 'lib/covered/policy.rb', line 39

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

#onlyObject

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



51
52
53
# File 'lib/covered/policy.rb', line 51

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

#persist!Object

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



63
64
65
# File 'lib/covered/policy.rb', line 63

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

#reports!(reports) ⇒ Object

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



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/covered/policy.rb', line 135

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

#rootObject

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



57
58
59
# File 'lib/covered/policy.rb', line 57

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

#skipObject

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



45
46
47
# File 'lib/covered/policy.rb', line 45

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

#startObject

Start collecting coverage.



76
77
78
# File 'lib/covered/policy.rb', line 76

def start
	capture.start
end