Module: SimpleCov::LastRun
- 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 collapse
- .last_run_path ⇒ Object
- .read ⇒ Object
-
.write(json) ⇒ Object
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.
Class Method Details
.last_run_path ⇒ Object
11 12 13 |
# File 'lib/simplecov/last_run.rb', line 11 def last_run_path File.join(SimpleCov.coverage_path, ".last_run.json") end |
.read ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/simplecov/last_run.rb', line 15 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) ⇒ Object
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.
27 28 29 30 31 32 |
# File 'lib/simplecov/last_run.rb', line 27 def write(json) FileUtils.mkdir_p(SimpleCov.coverage_path) 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 |