Class: Covered::Capture
Instance Attribute Summary
Attributes inherited from Wrapper
Instance Method Summary collapse
- #disable ⇒ Object
- #enable ⇒ Object
-
#initialize(output) ⇒ Capture
constructor
A new instance of Capture.
Methods inherited from Wrapper
#accept?, #each, #expand_path, #flush, #mark, #relative_path, #to_h
Methods inherited from Base
#accept?, #each, #expand_path, #flush, #mark, #relative_path
Constructor Details
#initialize(output) ⇒ Capture
Returns a new instance of Capture.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/covered/capture.rb', line 27 def initialize(output) super(output) begin @trace = TracePoint.new(:line, :call, :c_call) do |trace| if trace.event == :call # Ruby doesn't always mark call-sites in sub-expressions, so we use this approach to compute a call site and mark it: if location = caller_locations(2, 1).first and path = location.path @output.mark(path, location.lineno, 1) end end if path = trace.path @output.mark(path, trace.lineno, 1) end end rescue warn "Line coverage disabled: #{$!}" @trace = nil end end |
Instance Method Details
#disable ⇒ Object
55 56 57 58 59 |
# File 'lib/covered/capture.rb', line 55 def disable @trace&.disable super end |
#enable ⇒ Object
49 50 51 52 53 |
# File 'lib/covered/capture.rb', line 49 def enable super @trace&.enable end |