Class: Covered::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/covered/config.rb

Constant Summary collapse

PATH =
"config/covered.rb"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, coverage) ⇒ Config

Returns a new instance of Config.



53
54
55
56
57
# File 'lib/covered/config.rb', line 53

def initialize(root, coverage)
	@root = root
	@coverage = coverage
	@policy = nil
end

Instance Attribute Details

#coverageObject (readonly)

Returns the value of attribute coverage.



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

def coverage
  @coverage
end

Class Method Details

.coverageObject



37
38
39
# File 'lib/covered/config.rb', line 37

def self.coverage
	ENV['COVERAGE']
end

.load(root: Dir.pwd, coverage: self.coverage) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/covered/config.rb', line 41

def self.load(root: Dir.pwd, coverage: self.coverage)
	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, coverage)
end

.path(root) ⇒ Object



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

def self.path(root)
	path = ::File.join(root, PATH)
	
	if ::File.exist?(path)
		return path
	end
end

Instance Method Details

#call(output) ⇒ Object



85
86
87
# File 'lib/covered/config.rb', line 85

def call(output)
	policy.call(output)
end

#disableObject



77
78
79
# File 'lib/covered/config.rb', line 77

def disable
	policy.disable
end

#each(&block) ⇒ Object



89
90
91
# File 'lib/covered/config.rb', line 89

def each(&block)
	policy.each(&block)
end

#enableObject



73
74
75
# File 'lib/covered/config.rb', line 73

def enable
	policy.enable
end

#flushObject



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

def flush
	policy.flush
end

#make_policy(policy) ⇒ Object

Override this method to implement your own policy.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/covered/config.rb', line 94

def make_policy(policy)
	policy.cache!
	
	# Only files in the root would be tracked:
	policy.root(@root)
	
	# We will ignore any files in the test or spec directory:
	policy.skip(/^.*\/(test|spec|vendor|config)\//)
	
	# We will include all files under lib, even if they aren't loaded:
	policy.include("lib/**/*.rb")
	
	policy.persist!
	
	policy.source
	
	policy.reports!(@coverage)
end

#outputObject



69
70
71
# File 'lib/covered/config.rb', line 69

def output
	policy.output
end

#policyObject



65
66
67
# File 'lib/covered/config.rb', line 65

def policy
	@policy ||= Policy.new.tap{|policy| make_policy(policy)}.freeze
end

#record?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/covered/config.rb', line 59

def record?
	!!@coverage
end