Module: SimpleCov::LastRun
- Defined in:
- lib/simplecov/last_run.rb,
sig/simplecov.rbs
Overview
Reads and writes coverage/.last_run.json — the previous run's coverage percentages used by MaximumCoverageDropCheck.
Class Method Summary collapse
- .last_run_path ⇒ String
-
.read ⇒ Hash[Symbol, untyped]?
nil when the file does not exist or is blank.
-
.write(json) ⇒ void
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 ⇒ String
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 ⇒ Hash[Symbol, untyped]?
nil when the file does not exist or is blank. Keys are symbolized.
1145 1146 1147 1148 1149 1150 1151 1152 |
# File 'sig/simplecov.rbs', line 1145 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) ⇒ void
This method returns an undefined value.
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 |