Module: SimpleCov::LastRun

Defined in:
lib/simplecov/last_run.rb,
sig/simplecov.rbs

Class Method Summary collapse

Class Method Details

.last_run_pathString

Returns:

  • (String)


9
10
11
# File 'lib/simplecov/last_run.rb', line 9

def last_run_path
  File.join(SimpleCov.coverage_path, ".last_run.json")
end

.readHash[Symbol, untyped]?

The maximum_coverage_drop check digs into a Hash, so anything else in a corrupt or hand-edited file counts as "no previous run" rather than crashing the at_exit hook.

Returns:

  • (Hash[Symbol, untyped], nil)


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/simplecov/last_run.rb', line 16

def read
  return nil unless File.exist?(last_run_path)

  json = File.read(last_run_path)
  return nil if json.match?(/\A\s*\z/)

  parsed = JSON.parse(json, symbolize_names: true)
  parsed.instance_of?(Hash) ? parsed : invalid_last_run
rescue JSON::ParserError
  invalid_last_run
end

.write(json) ⇒ void

This method returns an undefined value.

Parameters:

  • json (Hash[Symbol, untyped])


28
29
30
# File 'lib/simplecov/last_run.rb', line 28

def write(json)
  AtomicFile.write(last_run_path, "#{JSON.pretty_generate(json)}\n")
end