Class: Injectable::DependenciesGraph
- Inherits:
-
Object
- Object
- Injectable::DependenciesGraph
- Extended by:
- Forwardable
- Defined in:
- lib/injectable/dependencies_graph.rb
Overview
Holds the dependency signatures of the service object
Instance Attribute Summary collapse
-
#dependency_class ⇒ Object
readonly
Returns the value of attribute dependency_class.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
Instance Method Summary collapse
-
#add(name:, depends_on:, **kwargs) ⇒ Object
Adds the signature of a dependency to the graph.
-
#initialize(namespace:, dependency_class: ::Injectable::Dependency) ⇒ DependenciesGraph
constructor
A new instance of DependenciesGraph.
- #names ⇒ Object
- #with_namespace(namespace) ⇒ Object
Constructor Details
#initialize(namespace:, dependency_class: ::Injectable::Dependency) ⇒ DependenciesGraph
Returns a new instance of DependenciesGraph.
11 12 13 14 15 |
# File 'lib/injectable/dependencies_graph.rb', line 11 def initialize(namespace:, dependency_class: ::Injectable::Dependency) @namespace = namespace @graph = {} @dependency_class = dependency_class end |
Instance Attribute Details
#dependency_class ⇒ Object (readonly)
Returns the value of attribute dependency_class.
6 7 8 |
# File 'lib/injectable/dependencies_graph.rb', line 6 def dependency_class @dependency_class end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
6 7 8 |
# File 'lib/injectable/dependencies_graph.rb', line 6 def graph @graph end |
#namespace ⇒ Object
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/injectable/dependencies_graph.rb', line 7 def namespace @namespace end |
Instance Method Details
#add(name:, depends_on:, **kwargs) ⇒ Object
Adds the signature of a dependency to the graph
26 27 28 29 |
# File 'lib/injectable/dependencies_graph.rb', line 26 def add(name:, depends_on:, **kwargs) check_for_missing_dependencies!(depends_on) graph[name] = dependency_class.new(kwargs.merge(name: name, depends_on: depends_on)) end |
#names ⇒ Object
17 18 19 |
# File 'lib/injectable/dependencies_graph.rb', line 17 def names graph.keys end |
#with_namespace(namespace) ⇒ Object
21 22 23 |
# File 'lib/injectable/dependencies_graph.rb', line 21 def with_namespace(namespace) dup.tap { |dupe| dupe.namespace = namespace } end |