Class: CovLoupe::Resolvers::ResultsetPathResolver

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

Overview

Locates the .resultset.json file for a project.

Resolution order:

  1. If the user provides an explicit path, resolve it (supports files and directories)
  2. If not found, search a list of default candidate locations relative to the project root

When a relative path is given, it is expanded against both the current working directory and the project root. If both expansions point to valid locations, an ambiguity error is raised to prevent silently using the wrong file.

Constant Summary collapse

DEFAULT_CANDIDATES =
[
  '.resultset.json',
  'coverage/.resultset.json',
  'tmp/.resultset.json',
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(root: Dir.pwd, candidates: DEFAULT_CANDIDATES) ⇒ ResultsetPathResolver

Returns a new instance of ResultsetPathResolver.



26
27
28
29
# File 'lib/cov_loupe/resolvers/resultset_path_resolver.rb', line 26

def initialize(root: Dir.pwd, candidates: DEFAULT_CANDIDATES)
  @root = root
  @candidates = candidates
end

Instance Method Details

#find_resultset(resultset: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/cov_loupe/resolvers/resultset_path_resolver.rb', line 31

def find_resultset(resultset: nil)
  if resultset && !resultset.empty?
    path = normalize_resultset_path(resultset)
    if (resolved = resolve_candidate(path, strict: true))
      return resolved
    end
  end

  resolve_fallback or raise_not_found_error
end