Class: Interdependence::DependencyResolver::Base
- Inherits:
-
Object
- Object
- Interdependence::DependencyResolver::Base
- Includes:
- Adamantium
- Defined in:
- lib/interdependence/dependency_resolver/base.rb
Overview
Base class that consolidates common functionality for dependency resolvers
Class Attribute Summary collapse
-
.dependency_class ⇒ Class
writeonly
private
Dependency class this resolver should use.
Instance Method Summary collapse
-
#dependencies ⇒ ObservableDependencySetGraph
private
ObservableDependencySetGraph resolved dependencies.
-
#dependency_graph_mapper ⇒ Enumerator
private
Iterator for resolving dependencies.
-
#field ⇒ Symbol
private
Field name.
-
#new_dependency ⇒ dependency_class
private
New dependency initialized with attributes of self.
-
#options ⇒ Hash
private
Options for validator.
-
#resolve_dependency(dependency) ⇒ dependency_class
private
Resolve a dependency if it is resolvable.
-
#resolve_pair(parent, children) ⇒ Object
private
Resolve a parent-children pair.
-
#validator_class ⇒ Class
private
Descendant of ActiveModel::Model.
Class Attribute Details
.dependency_class=(value) ⇒ Class (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Dependency class this resolver should use
41 |
# File 'lib/interdependence/dependency_resolver/base.rb', line 41 class_attribute :dependency_class, instance_writer: false |
Instance Method Details
#dependencies ⇒ ObservableDependencySetGraph
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
ObservableDependencySetGraph resolved dependencies
49 50 51 52 53 54 55 |
# File 'lib/interdependence/dependency_resolver/base.rb', line 49 def dependencies dependency_graph_mapper.each do |(parent, children), graph| new_parent, new_children = resolve_pair(parent, children) graph[new_parent].replace(new_children) end end |
#dependency_graph_mapper ⇒ Enumerator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Iterator for resolving dependencies
106 107 108 109 110 111 |
# File 'lib/interdependence/dependency_resolver/base.rb', line 106 def dependency_graph_mapper new_dependency .dependencies .each .with_object(ObservableDependencySetGraph.new) end |
#field ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Field name
15 |
# File 'lib/interdependence/dependency_resolver/base.rb', line 15 attribute :field, Symbol, strict: true |
#new_dependency ⇒ dependency_class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
New dependency initialized with attributes of self
63 64 65 |
# File 'lib/interdependence/dependency_resolver/base.rb', line 63 def new_dependency dependency_class.new(self) end |
#options ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Options for validator
31 |
# File 'lib/interdependence/dependency_resolver/base.rb', line 31 attribute :options, Hash, strict: true |
#resolve_dependency(dependency) ⇒ dependency_class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolve a dependency if it is resolvable
76 77 78 79 80 81 82 |
# File 'lib/interdependence/dependency_resolver/base.rb', line 76 def resolve_dependency(dependency) if resolvable?(dependency) resolve_with(dependency) else dependency end end |
#resolve_pair(parent, children) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolve a parent-children pair
93 94 95 96 97 98 |
# File 'lib/interdependence/dependency_resolver/base.rb', line 93 def resolve_pair(parent, children) parent = resolve_dependency(parent) children = children.map { |child| resolve_dependency(child) } [parent, children] end |
#validator_class ⇒ Class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Descendant of ActiveModel::Model
23 |
# File 'lib/interdependence/dependency_resolver/base.rb', line 23 attribute :validator_class, Class, coercer: Types::ValidatorClassCoercer, strict: true |