class Covered::Capture

Captures Ruby coverage data and forwards it to another coverage output.

def clear

Clear any collected coverage data without stopping coverage.
def clear
	super
	
	::Coverage.result(stop: false, clear: true)
end

def execute(source, binding: TOPLEVEL_BINDING)

@returns [Object] The result of evaluating the source.
@parameter binding [Binding] The binding used to evaluate the source.
@parameter source [Covered::Source] The source to execute.
Execute the given source while capturing coverage for it.
def execute(source, binding: TOPLEVEL_BINDING)
	start
	
	eval(source.code!, binding, source.path, source.line_offset)
ensure
	finish
end

def finish

Ignores Ruby's anonymous eval paths and files that no longer exist.
Stop coverage collection and add the collected results to the output.
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

def start

Start Ruby coverage collection.
def start
	super
	
	::Coverage.start(lines: true, eval: true)
end