Class: Injectable::Container
- Inherits:
-
Object
- Object
- Injectable::Container
- Includes:
- Registerable
- Defined in:
- lib/injectable/container.rb
Overview
A simple container that can resolve dependencies.
Defined Under Namespace
Classes: Unresolvable
Instance Method Summary collapse
-
#get(name) ⇒ Object
Get an instance of an object from the container with the provided class.
-
#initialize(*objects) ⇒ Container
constructor
Create a new container with the objects needed to resolve dependencies and create new objects.
Methods included from Registerable
Constructor Details
#initialize(*objects) ⇒ Container
Create a new container with the objects needed to resolve dependencies and create new objects.
44 45 46 47 48 |
# File 'lib/injectable/container.rb', line 44 def initialize(*objects) objects.each do |object| instantiated_objects[object.class] = object end end |
Instance Method Details
#get(name) ⇒ Object
Get an instance of an object from the container with the provided class.
25 26 27 28 29 30 31 32 33 |
# File 'lib/injectable/container.rb', line 25 def get(name) classes = registered_implementations(name) if klass = instantiated_class(classes) instantiated_objects[klass] else object = instantiate(classes) instantiated_objects[object.class] = object end end |