Class: Ace::TestRunner::Molecules::PackageResolver
- Inherits:
-
Object
- Object
- Ace::TestRunner::Molecules::PackageResolver
- 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
-
#project_root ⇒ String?
readonly
Get the project root.
Instance Method Summary collapse
-
#available_packages ⇒ Array<String>
List all available packages in the mono-repo.
-
#initialize(project_root: nil) ⇒ PackageResolver
constructor
Initialize resolver.
-
#resolve(name_or_path) ⇒ String?
Resolve a package name or path to an absolute directory path.
Constructor Details
#initialize(project_root: nil) ⇒ PackageResolver
Initialize resolver
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_root ⇒ String? (readonly)
Get the project root
54 55 56 |
# File 'lib/ace/test_runner/molecules/package_resolver.rb', line 54 def project_root @project_root end |
Instance Method Details
#available_packages ⇒ Array<String>
List all available packages in the mono-repo. Results are memoized since filesystem glob operations are relatively expensive.
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
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 |