Sha256: 09676f1faf98d57fecf79812f14cec7887d2b5859ef297e66e1647deed0fdbce
Contents?: true
Size: 1.29 KB
Versions: 8
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true module Coverband module Adapters class FileStore < Base attr_accessor :path def initialize(path, _opts = {}) @path = path config_dir = File.dirname(@path) Dir.mkdir config_dir unless File.exist?(config_dir) end 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) } end def coverage existing_data(path) end def covered_files report = existing_data(path) existing_data(path).merge(report).keys || [] end def covered_lines_for_file(file) report = existing_data(path) report[file] || [] end private def existing_data(path) if File.exist?(path) JSON.parse(File.read(path)) else {} end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems