Class: Injectable::DependenciesProxy

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

Overview

Memoizes the Dependencies generated by Dependency based on DependencyGraph

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph:, namespace: nil) ⇒ DependenciesProxy

Returns a new instance of DependenciesProxy.



6
7
8
9
10
# File 'lib/injectable/dependencies_proxy.rb', line 6

def initialize(graph:, namespace: nil)
  @graph = graph
  @namespace = namespace
  @instances = {}
end

Instance Attribute Details

#graphObject (readonly)

Returns the value of attribute graph.



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

def graph
  @graph
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

Instance Method Details

#get(name) ⇒ Object

Get the instance of the dependency name



13
14
15
# File 'lib/injectable/dependencies_proxy.rb', line 13

def get(name)
  @instances[name] ||= graph[name].instance(args: memoized_dependencies_of(name), namespace: namespace)
end