Class: CovLoupe::Resolvers::CoverageLineResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/cov_loupe/resolvers/coverage_line_resolver.rb

Overview

Finds a SimpleCov line coverage array for a given file path.

Resolution strategy (in order):

  1. Exact match on the normalized input path
  2. Match after stripping the project root prefix (handles relative keys in resultsets)

On case-insensitive volumes, all comparisons are case-normalized to avoid false negatives. If multiple coverage entries normalize to the same path, an ambiguity error is raised to prevent silent data corruption.

This resolver is string-based only — it does not touch the filesystem.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cov_data, root:, volume_case_sensitive:) ⇒ CoverageLineResolver

Returns a new instance of CoverageLineResolver.

Parameters:

  • cov_data (Hash)

    coverage data map keyed by file path

  • root (String, nil)

    project root used for path stripping

  • volume_case_sensitive (Boolean)

    whether the volume is case-sensitive



22
23
24
25
26
# File 'lib/cov_loupe/resolvers/coverage_line_resolver.rb', line 22

def initialize(cov_data, root:, volume_case_sensitive:)
  @cov_data = cov_data
  @root = root
  @normalize_case = !volume_case_sensitive
end

Instance Attribute Details

#cov_dataObject (readonly)

Returns the value of attribute cov_data.



46
47
48
# File 'lib/cov_loupe/resolvers/coverage_line_resolver.rb', line 46

def cov_data
  @cov_data
end

Instance Method Details

#lookup_lines(file_abs) ⇒ Array<Integer, nil>

Resolve coverage lines for a file path, trying fallbacks before raising.

Parameters:

  • file_abs (String)

    absolute file path to resolve

Returns:

  • (Array<Integer, nil>)

    SimpleCov-style line coverage array



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cov_loupe/resolvers/coverage_line_resolver.rb', line 31

def lookup_lines(file_abs)
  # Normalize the input path first to handle platform-specific differences
  normalized_path = normalize_path(file_abs)

  # First try exact match
  direct_match = find_direct_match(normalized_path)
  return direct_match if direct_match

  # Then try without current working directory prefix
  stripped_match = find_stripped_match(normalized_path)
  return stripped_match if stripped_match

  raise_not_found_error(file_abs)
end