Class: Skooma::CoverageStore
- Inherits:
-
Object
- Object
- Skooma::CoverageStore
- Defined in:
- lib/skooma/coverage_store.rb
Constant Summary collapse
- DEFAULT_FILE_PATH =
File.join(Dir.pwd, "tmp", "skooma_coverage.json")
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(file_path: DEFAULT_FILE_PATH) ⇒ CoverageStore
constructor
A new instance of CoverageStore.
- #load_data ⇒ Object
- #save_data(new_defined_paths, new_covered_paths) ⇒ Object
Constructor Details
#initialize(file_path: DEFAULT_FILE_PATH) ⇒ CoverageStore
Returns a new instance of CoverageStore.
9 10 11 12 |
# File 'lib/skooma/coverage_store.rb', line 9 def initialize(file_path: DEFAULT_FILE_PATH) @file_path = file_path ensure_file_exists end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
7 8 9 |
# File 'lib/skooma/coverage_store.rb', line 7 def file_path @file_path end |
Instance Method Details
#clear ⇒ Object
32 33 34 |
# File 'lib/skooma/coverage_store.rb', line 32 def clear File.delete(file_path) if File.exist?(file_path) end |
#load_data ⇒ Object
14 15 16 17 18 |
# File 'lib/skooma/coverage_store.rb', line 14 def load_data with_lock("r") do |file| parse_data(file.read) end end |
#save_data(new_defined_paths, new_covered_paths) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/skooma/coverage_store.rb', line 20 def save_data(new_defined_paths, new_covered_paths) with_lock("r+") do |file| existing_data = parse_data(file.read) merged_data = merge_data(existing_data, new_defined_paths, new_covered_paths) file.rewind file.write(JSON.generate(merged_data)) file.flush file.truncate(file.pos) end end |