Class: Ace::Search::Atoms::SearchPathResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/search/atoms/search_path_resolver.rb

Overview

Resolve search path using 4-step priority algorithm

Priority order:

  1. Explicit path argument (if provided)

  2. PROJECT_ROOT_PATH environment variable

  3. Project root detection via ProjectRootFinder

  4. Fallback to current directory

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.resolve(explicit_path = nil) ⇒ String

Resolve search path with 4-step priority

Parameters:

  • explicit_path (String, nil) (defaults to: nil)

    Optional explicit path argument

Returns:

  • (String)

    Resolved absolute or relative path



20
21
22
# File 'lib/ace/search/atoms/search_path_resolver.rb', line 20

def self.resolve(explicit_path = nil)
  new.resolve(explicit_path)
end

Instance Method Details

#resolve(explicit_path = nil) ⇒ String

Resolve search path with 4-step priority

Parameters:

  • explicit_path (String, nil) (defaults to: nil)

    Optional explicit path argument

Returns:

  • (String)

    Resolved absolute or relative path



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ace/search/atoms/search_path_resolver.rb', line 28

def resolve(explicit_path = nil)
  # Step 1: Use explicit path if provided (and not whitespace-only)
  return explicit_path if explicit_path && !explicit_path.strip.empty?

  # Step 2: Check PROJECT_ROOT_PATH environment variable
  project_root_env = env_project_root
  if project_root_env && !project_root_env.empty?
    # We validate the ENV var path to prevent a misconfigured environment
    # from causing silent failures. We then fall back gracefully.
    # (Explicit paths are trusted and not validated here)
    return project_root_env if valid_path?(project_root_env)
  end

  # Step 3: Detect project root using ProjectRootFinder
  project_root = find_project_root
  return project_root if project_root

  # Step 4: Fallback to current directory
  "."
end