Class: Injectable::DependenciesGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/injectable/dependencies_graph.rb

Overview

Holds the dependency signatures of the service object

Instance Attribute Summary collapse

Instance Method Summary collapse

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_classObject (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

#graphObject (readonly)

Returns the value of attribute graph.



4
5
6
# File 'lib/injectable/dependencies_graph.rb', line 4

def graph
  @graph
end

#namespaceObject

Returns the value of attribute namespace.



5
6
7
# File 'lib/injectable/dependencies_graph.rb', line 5

def namespace
  @namespace
end

#proxy_classObject (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

#namesObject



16
17
18
# File 'lib/injectable/dependencies_graph.rb', line 16

def names
  graph.keys
end

#proxyObject



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