Class: CovLoupe::ResultsetLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/cov_loupe/loaders/resultset_loader.rb

Overview

Reads and parses a SimpleCov .resultset.json file.

Handles both single-suite and multi-suite resultsets. For multi-suite files, it delegates to SimpleCov's ResultsCombiner (requiring the simplecov gem). Legacy resultsets that store raw line arrays (instead of { "lines" => [...] } hashes) are normalized to the newer format.

Timestamps are extracted from the "timestamp" or "created_at" fields and normalized to integer epoch seconds. Missing or unparseable timestamps default to 0, which disables time-based staleness checks.

Defined Under Namespace

Classes: Result, SuiteEntry

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resultset_path:, logger:) ⇒ ResultsetLoader

Returns a new instance of ResultsetLoader.



28
29
30
31
# File 'lib/cov_loupe/loaders/resultset_loader.rb', line 28

def initialize(resultset_path:, logger:)
  @resultset_path = resultset_path
  @logger = logger
end

Class Method Details

.load(resultset_path:, logger: nil) ⇒ Object



23
24
25
26
# File 'lib/cov_loupe/loaders/resultset_loader.rb', line 23

def self.load(resultset_path:, logger: nil)
  logger ||= CovLoupe.logger
  new(resultset_path: resultset_path, logger: logger).load
end

Instance Method Details

#loadObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cov_loupe/loaders/resultset_loader.rb', line 33

def load
  raw = JSON.parse(File.read(@resultset_path))

  suites = extract_suite_entries(raw)
  if suites.empty?
    raise CoverageDataError,
      "No test suite with coverage data found in resultset file: #{@resultset_path}"
  end

  coverage_map = build_coverage_map(suites)
  Result.new(
    coverage_map: coverage_map,
    timestamp:    compute_combined_timestamp(suites),
    suite_names:  suites.map(&:name)
  )
end