Class: Carb::Container::RegistryContainer
- Inherits:
-
Object
- Object
- Carb::Container::RegistryContainer
- Includes:
- Base
- Defined in:
- lib/carb/container/registry_container.rb
Overview
Simple Hash based container for dependency resolution based on name, with further registration capabilities
Defined Under Namespace
Classes: Record
Instance Method Summary collapse
-
#[](name) ⇒ nil, Object
Gets a dependency.
-
#has_key?(name) ⇒ Boolean
Checks if the dependency exists within the container.
-
#initialize(dependencies = {}) ⇒ RegistryContainer
constructor
A new instance of RegistryContainer.
-
#register(name, dependency) ⇒ RegistryContainer
Self (for chaining purposes).
Constructor Details
#initialize(dependencies = {}) ⇒ RegistryContainer
Returns a new instance of RegistryContainer.
24 25 26 27 28 29 |
# File 'lib/carb/container/registry_container.rb', line 24 def initialize(dependencies = {}) @dependencies = {} dependencies.each do |name, dep| register_with_caller(name, dep, caller_locations[0]) end end |
Instance Method Details
#[](name) ⇒ nil, Object
Gets a dependency
47 48 49 50 51 |
# File 'lib/carb/container/registry_container.rb', line 47 def [](name) ensure_dependency_present!(name) dependencies[name].dependency.() end |
#has_key?(name) ⇒ Boolean
Checks if the dependency exists within the container
57 58 59 |
# File 'lib/carb/container/registry_container.rb', line 57 def has_key?(name) dependencies.has_key?(name) end |
#register(name, dependency) ⇒ RegistryContainer
Returns self (for chaining purposes).
38 39 40 41 |
# File 'lib/carb/container/registry_container.rb', line 38 def register(name, dependency) register_with_caller(name, dependency, caller_locations[0]) self end |