lib/coverband/adapters/file_store.rb in coverband-2.0.3 vs lib/coverband/adapters/file_store.rb in coverband-3.0.0.alpha

- old
+ new

@@ -1,9 +1,14 @@ # frozen_string_literal: true module Coverband module Adapters + ### + # FilesStore store a merged coverage file to local disk + # Generally this is for testing and development + # Not recommended for production deployment + ### class FileStore < Base attr_accessor :path def initialize(path, _opts = {}) @path = path @@ -15,21 +20,12 @@ def clear! File.delete(path) if File.exist?(path) end def save_report(report) - results = existing_data(path) - report.each_pair do |file, values| - if results.key?(file) - # convert the keys to "3" opposed to 3 - values = JSON.parse(values.to_json) - results[file].merge!(values) { |_k, old_v, new_v| old_v.to_i + new_v.to_i } - else - results[file] = values - end - end - File.open(path, 'w') { |f| f.write(results.to_json) } + merge_reports(report, coverage) + save_coverage(report) end def coverage existing_data(path) end @@ -43,9 +39,13 @@ report = existing_data(path) report[file] || [] end private + + def save_coverage(report) + File.open(path, 'w') { |f| f.write(report.to_json) } + end def existing_data(path) if File.exist?(path) JSON.parse(File.read(path)) else