module SimpleCov::ResultMerger
def merged_result
for the result consisting of a join on all source result's names
SimpleCov::Result with merged coverage data and the command_name
Gets all SimpleCov::Results from cache, merges them and produces a new
def merged_result merged = {} results.each do |result| merged = result.original_result.merge_resultset(merged) end result = SimpleCov::Result.new(merged) # Specify the command name result.command_name = results.map(&:command_name).sort.join(", ") result end
def results
All results that are above the SimpleCov.merge_timeout will be
of SimpleCov::Result from that.
Gets the resultset hash and re-creates all included instances
def results results = [] resultset.each do |command_name, data| result = SimpleCov::Result.from_hash(command_name => data) # Only add result if the timeout is above the configured threshold if (Time.now - result.created_at) < SimpleCov.merge_timeout results << result end end results end
def resultset
def resultset if stored_data MultiJson.load(stored_data) else {} end end
def resultset_path
def resultset_path File.join(SimpleCov.coverage_path, '.resultset.json') end
def store_result(result)
def store_result(result) new_set = resultset command_name, data = result.to_hash.first new_set[command_name] = data File.open(resultset_path, "w+") do |f| if defined? ::JSON f.puts JSON.pretty_generate(new_set) else f.puts MultiJson.dump(new_set) end end true end
def stored_data
def stored_data if File.exist?(resultset_path) and stored_data = File.read(resultset_path) and stored_data.length >= 2 stored_data else nil end end