Class: Ace::TestRunner::Molecules::PackageResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/test_runner/molecules/package_resolver.rb

Overview

Resolves package names or paths to absolute package directories Supports: package name (ace-bundle), relative path (./ace-bundle), absolute path

Note: This class depends on ace-support-fs which provides ProjectRootFinder.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_root: nil) ⇒ PackageResolver

Initialize resolver

Parameters:

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

    Override project root (for testing)



16
17
18
# File 'lib/ace/test_runner/molecules/package_resolver.rb', line 16

def initialize(project_root: nil)
  @project_root = project_root || Ace::Support::Fs::Molecules::ProjectRootFinder.find
end

Instance Attribute Details

#project_rootString? (readonly)

Get the project root

Returns:

  • (String, nil)

    Project root path



54
55
56
# File 'lib/ace/test_runner/molecules/package_resolver.rb', line 54

def project_root
  @project_root
end

Instance Method Details

#available_packagesArray<String>

List all available packages in the mono-repo. Results are memoized since filesystem glob operations are relatively expensive.

Returns:

  • (Array<String>)

    List of package names



43
44
45
46
47
48
49
50
# File 'lib/ace/test_runner/molecules/package_resolver.rb', line 43

def available_packages
  return [] unless @project_root

  @available_packages ||= Dir.glob(File.join(@project_root, "ace-*"))
    .select { |path| File.directory?(path) && has_test_directory?(path) }
    .map { |path| File.basename(path) }
    .sort
end

#resolve(name_or_path) ⇒ String?

Resolve a package name or path to an absolute directory path

Parameters:

  • name_or_path (String)

    Package name, relative path, or absolute path

Returns:

  • (String, nil)

    Absolute path to package directory, or nil if not found



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ace/test_runner/molecules/package_resolver.rb', line 23

def resolve(name_or_path)
  return nil if name_or_path.nil? || name_or_path.empty?

  path = if absolute_path?(name_or_path)
    resolve_absolute(name_or_path)
  elsif relative_path?(name_or_path)
    resolve_relative(name_or_path)
  else
    resolve_by_name(name_or_path)
  end

  # Validate the resolved path has a test directory
  return nil unless path && valid_package?(path)

  path
end