Class: Covered::Config
- Inherits:
-
Object
- Object
- Covered::Config
- Defined in:
- lib/covered/config.rb
Constant Summary collapse
- PATH =
"config/covered.rb"
Instance Attribute Summary collapse
-
#coverage ⇒ Object
readonly
Returns the value of attribute coverage.
Class Method Summary collapse
- .load(root: self.root, reports: self.reports) ⇒ Object
- .path(root) ⇒ Object
- .reports ⇒ Object
- .root ⇒ Object
Instance Method Summary collapse
-
#call(output) ⇒ Object
Generate coverage reports to the given output.
- #each(&block) ⇒ Object
-
#finish ⇒ Object
Finish coverage tracking.
-
#ignore_paths ⇒ Object
Which paths to ignore when computing coverage for a given project.
-
#include_patterns ⇒ Object
Which paths to include when computing coverage for a given project.
-
#initialize(root, reports) ⇒ Config
constructor
A new instance of Config.
-
#make_policy(policy) ⇒ Object
Override this method to implement your own policy.
- #output ⇒ Object
- #policy ⇒ Object
- #report? ⇒ Boolean (also: #record?)
-
#start ⇒ Object
Start coverage tracking.
Constructor Details
Instance Attribute Details
#coverage ⇒ Object (readonly)
Returns the value of attribute coverage.
54 55 56 |
# File 'lib/covered/config.rb', line 54 def coverage @coverage end |
Class Method Details
.load(root: self.root, reports: self.reports) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/covered/config.rb', line 28 def self.load(root: self.root, reports: self.reports) derived = Class.new(self) if path = self.path(root) config = Module.new config.module_eval(::File.read(path), path) derived.prepend(config) end return derived.new(root, reports) end |
.path(root) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/covered/config.rb', line 16 def self.path(root) path = ::File.(PATH, root) if ::File.exist?(path) return path end end |
.reports ⇒ Object
24 25 26 |
# File 'lib/covered/config.rb', line 24 def self.reports ENV['COVERAGE'] end |
.root ⇒ Object
12 13 14 |
# File 'lib/covered/config.rb', line 12 def self.root ENV['COVERED_ROOT'] || Dir.pwd end |
Instance Method Details
#call(output) ⇒ Object
Generate coverage reports to the given output.
86 87 88 |
# File 'lib/covered/config.rb', line 86 def call(output) policy.call(output) end |
#each(&block) ⇒ Object
90 91 92 |
# File 'lib/covered/config.rb', line 90 def each(&block) policy.each(&block) end |
#finish ⇒ Object
Finish coverage tracking.
75 76 77 78 79 80 81 82 |
# File 'lib/covered/config.rb', line 75 def finish # Finish coverage tracking: policy.finish # Restore the environment: ENV.replace(@environment) @environment = nil end |
#ignore_paths ⇒ Object
Which paths to ignore when computing coverage for a given project.
96 97 98 |
# File 'lib/covered/config.rb', line 96 def ignore_paths ['test/', 'fixtures/', 'spec/', 'vendor/', 'config/'] end |
#include_patterns ⇒ Object
Which paths to include when computing coverage for a given project.
102 103 104 |
# File 'lib/covered/config.rb', line 102 def include_patterns ["lib/**/*.rb"] end |
#make_policy(policy) ⇒ Object
Override this method to implement your own policy.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/covered/config.rb', line 107 def make_policy(policy) # Only files in the root would be tracked: policy.root(@root) patterns = ignore_paths.map do |path| File.join(@root, path) end # We will ignore any files in the test or spec directory: policy.skip(Regexp.union(patterns)) # We will include all files under lib, even if they aren't loaded: include_patterns.each do |pattern| policy.include(pattern) end policy.persist! policy.reports!(@reports) end |
#output ⇒ Object
60 61 62 |
# File 'lib/covered/config.rb', line 60 def output policy.output end |
#policy ⇒ Object
56 57 58 |
# File 'lib/covered/config.rb', line 56 def policy @policy ||= Policy.new.tap{|policy| make_policy(policy)}.freeze end |
#report? ⇒ Boolean Also known as: record?
48 49 50 |
# File 'lib/covered/config.rb', line 48 def report? !!@reports end |
#start ⇒ Object
Start coverage tracking.
65 66 67 68 69 70 71 72 |
# File 'lib/covered/config.rb', line 65 def start # Save and setup the environment: @environment = ENV.to_h autostart! # Start coverage tracking: policy.start end |