Module: SimpleCov::ResultMerger::ResultsetFile

Defined in:
lib/simplecov/result_merger/resultset_file.rb

Overview

Read + parse a ‘.resultset.json` file with the same tolerance the historical `ResultMerger` had: missing file returns `{}`, an empty or unparseable file warns and returns `{}`, parse success returns the decoded Hash.

Class Method Summary collapse

Class Method Details

.decode(content) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/simplecov/result_merger/resultset_file.rb', line 28

def decode(content)
  return {} unless content

  JSON.parse(content) || {}
rescue StandardError
  warn "[SimpleCov]: Warning! Parsing JSON content of resultset file failed"
  {}
end

.parse(path) ⇒ Object



14
15
16
17
# File 'lib/simplecov/result_merger/resultset_file.rb', line 14

def parse(path)
  data = read(path)
  decode(data)
end

.read(path) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/simplecov/result_merger/resultset_file.rb', line 19

def read(path)
  return unless File.exist?(path)

  data = File.read(path)
  return if data.nil? || data.length < 2

  data
end