Class: Injectable::DependenciesGraph
- Inherits:
-
Object
- Object
- Injectable::DependenciesGraph
- 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.
-
#proxy_class ⇒ Object
readonly
Returns the value of attribute proxy_class.
Instance Method Summary collapse
-
#add(name:, depends_on:, **kwargs) ⇒ Object
Adds the signature of a dependency to the graph.
-
#initialize(namespace:, proxy_class: ::Injectable::DependenciesProxy, dependency_class: ::Injectable::Dependency) ⇒ DependenciesGraph
constructor
A new instance of DependenciesGraph.
- #names ⇒ Object
- #proxy ⇒ Object
- #with_namespace(namespace) ⇒ Object
Constructor Details
#initialize(namespace:, proxy_class: ::Injectable::DependenciesProxy, dependency_class: ::Injectable::Dependency) ⇒ DependenciesGraph
Returns a new instance of DependenciesGraph.
7 8 9 10 11 12 13 14 |
# File 'lib/injectable/dependencies_graph.rb', line 7 def initialize(namespace:, proxy_class: ::Injectable::DependenciesProxy, dependency_class: ::Injectable::Dependency) @namespace = namespace @graph = {} @proxy_class = proxy_class @dependency_class = dependency_class end |
Instance Attribute Details
#dependency_class ⇒ Object (readonly)
Returns the value of attribute dependency_class.
4 5 6 |
# File 'lib/injectable/dependencies_graph.rb', line 4 def dependency_class @dependency_class end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
4 5 6 |
# File 'lib/injectable/dependencies_graph.rb', line 4 def graph @graph end |
#namespace ⇒ Object
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/injectable/dependencies_graph.rb', line 5 def namespace @namespace end |
#proxy_class ⇒ Object (readonly)
Returns the value of attribute proxy_class.
4 5 6 |
# File 'lib/injectable/dependencies_graph.rb', line 4 def proxy_class @proxy_class end |
Instance Method Details
#add(name:, depends_on:, **kwargs) ⇒ Object
Adds the signature of a dependency to the graph
25 26 27 28 |
# File 'lib/injectable/dependencies_graph.rb', line 25 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
16 17 18 |
# File 'lib/injectable/dependencies_graph.rb', line 16 def names graph.keys end |
#proxy ⇒ Object
30 31 32 |
# File 'lib/injectable/dependencies_graph.rb', line 30 def proxy proxy_class.new(graph: graph, namespace: namespace) end |
#with_namespace(namespace) ⇒ Object
20 21 22 |
# File 'lib/injectable/dependencies_graph.rb', line 20 def with_namespace(namespace) dup.tap { |dupe| dupe.namespace = namespace } end |