Class: Necropsy::Analyzers::Dynamic::CoverageCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/necropsy/analyzers/dynamic/coverage_collector.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, output:, merge: false, run_id: nil, clock: nil) ⇒ CoverageCollector

Returns a new instance of CoverageCollector.



23
24
25
26
27
28
29
# File 'lib/necropsy/analyzers/dynamic/coverage_collector.rb', line 23

def initialize(root:, output:, merge: false, run_id: nil, clock: nil)
  @root = File.expand_path(root)
  @output = output
  @merge = merge
  @run_id = run_id
  @clock = clock || -> { Clock.new.time }
end

Class Method Details

.install_at_exit(root:, output:, merge: false, run_id: nil, clock: nil) ⇒ Object



19
20
21
# File 'lib/necropsy/analyzers/dynamic/coverage_collector.rb', line 19

def self.install_at_exit(root:, output:, merge: false, run_id: nil, clock: nil)
  new(root: root, output: output, merge: merge, run_id: run_id, clock: clock).install_at_exit
end

.record(root:, output:, clock: nil) ⇒ Object



15
16
17
# File 'lib/necropsy/analyzers/dynamic/coverage_collector.rb', line 15

def self.record(root:, output:, clock: nil, &)
  new(root: root, output: output, clock: clock).record(&)
end

Instance Method Details

#install_at_exitObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/necropsy/analyzers/dynamic/coverage_collector.rb', line 40

def install_at_exit
  started_at = current_time
  started = start_coverage

  at_exit do
    finished_at = current_time
    result = coverage_result(started: started)
    write_payload(result: result, started_at: started_at, finished_at: finished_at)
  rescue StandardError => e
    warn "Necropsy coverage collector failed: #{e.message}"
  end
end

#recordObject



31
32
33
34
35
36
37
38
# File 'lib/necropsy/analyzers/dynamic/coverage_collector.rb', line 31

def record
  started_at = current_time
  Coverage.start(methods: true)
  yield
  write_payload(result: Coverage.result, started_at: started_at, finished_at: current_time)
ensure
  Coverage.result(stop: true, clear: true) if Coverage.running?
end