123456789_123456789_123456789_123456789_123456789_

Module: SimpleCov::LastRun

Relationships & Source Files
Defined in: lib/simplecov/last_run.rb

Overview

Reads and writes coverage/.last_run.json — the previous run's coverage percentages used by MaximumCoverageDropCheck.

Class Method Summary

Class Method Details

.last_run_path

[ GitHub ]

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

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

.read

[ GitHub ]

  
# File 'lib/simplecov/last_run.rb', line 14

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

  json = File.read(last_run_path)
  return nil if json.strip.empty?

  JSON.parse(json, symbolize_names: true)
end

.write(json)

Write to a process-private temp file, then atomically rename, so a concurrent reader (e.g. another parallel-tests worker checking MaximumCoverageDrop) never sees a half-written file.

[ GitHub ]

  
# File 'lib/simplecov/last_run.rb', line 26

def write(json)
  temp_path = "#{last_run_path}.#{Process.pid}.tmp"
  File.open(temp_path, "w") { |f| f.puts JSON.pretty_generate(json) }
  File.rename(temp_path, last_run_path)
end