Module: SimpleCov::ResultMerger::ResultsetStore
| Relationships & Source Files | |
| Defined in: | lib/simplecov/result_merger/resultset_store.rb |
Overview
Reads and writes the persistent .resultset.json cache, including
file-lock synchronization between processes and atomic temp-file
renames so concurrent readers don't observe a truncated file.
Class Method Summary
- .resultset_path mod_func
-
.synchronize
mod_func
Ensure only one process is reading or writing the resultset at any given time.
- .with_flock mod_func
- .write(resultset) mod_func
- .writelock_path mod_func
Class Method Details
.resultset_path (mod_func)
[ GitHub ]# File 'lib/simplecov/result_merger/resultset_store.rb', line 14
def resultset_path File.join(SimpleCov.coverage_path, ".resultset.json") end
.synchronize (mod_func)
Ensure only one process is reading or writing the resultset at any given time. Reentrant: the lock is acquired once per outer call no matter how deeply nested.
# File 'lib/simplecov/result_merger/resultset_store.rb', line 32
def synchronize(&) return yield if @locked @locked = true with_flock(&) ensure @locked = false end
.with_flock (mod_func)
[ GitHub ]# File 'lib/simplecov/result_merger/resultset_store.rb', line 41
def with_flock FileUtils.mkdir_p(SimpleCov.coverage_path) File.open(writelock_path, "w+") do |f| f.flock(File::LOCK_EX) yield end end
.write(resultset) (mod_func)
[ GitHub ]# File 'lib/simplecov/result_merger/resultset_store.rb', line 22
def write(resultset) FileUtils.mkdir_p(SimpleCov.coverage_path) temp_path = "#{resultset_path}.#{Process.pid}.tmp" File.open(temp_path, "w") { |f| f.puts JSON.pretty_generate(resultset) } File.rename(temp_path, resultset_path) end
.writelock_path (mod_func)
[ GitHub ]# File 'lib/simplecov/result_merger/resultset_store.rb', line 18
def writelock_path File.join(SimpleCov.coverage_path, ".resultset.json.lock") end