Module: Medicine::DI
- Defined in:
- lib/medicine.rb
Instance Method Summary collapse
-
#initialize(injections = {}) ⇒ undefined
Injects dependencies.
-
#inject_dependency(name, dependency) ⇒ self
Injects a dependency.
-
#injections ⇒ Injections
private
Returns injections.
-
#injects(injections) ⇒ self
Injects dependencies.
Instance Method Details
#initialize(injections = {}) ⇒ undefined
Injects dependencies
33 34 35 36 37 |
# File 'lib/medicine.rb', line 33 def initialize(injections = {}) @injections = Injections.new injects(injections) super() end |
#inject_dependency(name, dependency) ⇒ self
Injects a dependency
50 51 52 53 54 |
# File 'lib/medicine.rb', line 50 def inject_dependency(name, dependency) raise DependencyUnknownError, "#{name} has not been declared as a dependency" unless self.class.dependencies.include?(name) @injections.set(name, dependency) self end |
#injections ⇒ Injections
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns injections
78 79 80 |
# File 'lib/medicine.rb', line 78 def injections @injections.dup.freeze end |
#injects(injections) ⇒ self
Injects dependencies
66 67 68 |
# File 'lib/medicine.rb', line 66 def injects(injections) injections.each { |name, dependency| inject_dependency(name, dependency) } end |