Class: DependencyManager::Resolver
- Inherits:
-
Object
- Object
- DependencyManager::Resolver
- Defined in:
- lib/dependency_manager/resolver.rb
Overview
Resolves a factories dependencies against the currently loaded dependency list. Checks for potential missing dependencies and reconciles against optional and required dependencies.
Defined Under Namespace
Classes: MissingDependencies
Instance Method Summary collapse
-
#initialize(factory:, loaded_dependencies:) ⇒ Resolver
constructor
Creates a new Resolver.
-
#resolve ⇒ Hash[Symbol, Any]
Resolves dependencies from the currently loaded dependencies.
Constructor Details
#initialize(factory:, loaded_dependencies:) ⇒ Resolver
Creates a new Resolver
18 19 20 21 |
# File 'lib/dependency_manager/resolver.rb', line 18 def initialize(factory:, loaded_dependencies:) @factory = factory @loaded_dependencies = loaded_dependencies end |
Instance Method Details
#resolve ⇒ Hash[Symbol, Any]
Resolves dependencies from the currently loaded dependencies
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dependency_manager/resolver.rb', line 31 def resolve # Resolve required dependencies from our current list resolved_dependencies = @loaded_dependencies.slice(*@factory.dependencies) required_dependencies = @factory.required_dependencies # But check if there are a few missing. Optional dependencies not included in this missing_dependencies = required_dependencies.reject do |dependency_name| !!resolved_dependencies[dependency_name] end if missing_dependencies.any? error = missing_dependencies.join(', ') raise MissingDependencies, "Dependencies for `#{@factory.const_name}` are not present: #{error}" end resolved_dependencies end |