Class: Covered::Capture

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

Constant Summary collapse

EVAL_PATHS =
{
	"(eval)" => true,
	"(irb)" => true,
	"eval" => true
}

Instance Attribute Summary

Attributes inherited from Wrapper

#output

Instance Method Summary collapse

Methods inherited from Wrapper

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

Methods inherited from Base

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

Constructor Details

This class inherits a constructor from Covered::Wrapper

Instance Method Details

#clearObject



18
19
20
21
22
# File 'lib/covered/capture.rb', line 18

def clear
	super
	
	::Coverage.result(stop: false, clear: true)
end

#execute(source, binding: TOPLEVEL_BINDING) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/covered/capture.rb', line 50

def execute(source, binding: TOPLEVEL_BINDING)
	start
	
	eval(source.code!, binding, source.path, source.line_offset)
ensure
	finish
end

#finishObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/covered/capture.rb', line 30

def finish
	results = ::Coverage.result
	
	results.each do |path, result|
		next if EVAL_PATHS.include?(path)
		
		path = self.expand_path(path)
		
		# Skip files which don't exist. This can happen if `eval` is used with an invalid/incorrect path.
		if File.exist?(path)
			@output.mark(path, 1, result[:lines])
		else
			# warn "Skipping coverage for #{path.inspect} because it doesn't exist!"
			# Ignore.
		end
	end
	
	super
end

#startObject



12
13
14
15
16
# File 'lib/covered/capture.rb', line 12

def start
	super
	
	::Coverage.start(lines: true, eval: true)
end