Class: Injectable::DependenciesGraph

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
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:, 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_classObject (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

#graphObject (readonly)

Returns the value of attribute graph.



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

def graph
  @graph
end

#namespaceObject

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

#namesObject



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