Module: SimpleCov::ResultMerger::ResultsetStore
- 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 collapse
- .resultset_path ⇒ Object
-
.synchronize ⇒ Object
Ensure only one process is reading or writing the resultset at any given time.
- .with_flock ⇒ Object
- .write(resultset) ⇒ Object
- .writelock_path ⇒ Object
Class Method Details
.resultset_path ⇒ Object
14 15 16 |
# File 'lib/simplecov/result_merger/resultset_store.rb', line 14 def resultset_path File.join(SimpleCov.coverage_path, ".resultset.json") end |
.synchronize ⇒ Object
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.
32 33 34 35 36 37 38 39 |
# 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 ⇒ Object
41 42 43 44 45 46 47 |
# 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) ⇒ Object
22 23 24 25 26 27 |
# 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 ⇒ Object
18 19 20 |
# File 'lib/simplecov/result_merger/resultset_store.rb', line 18 def writelock_path File.join(SimpleCov.coverage_path, ".resultset.json.lock") end |