Class: Untangle::Injector
- Inherits:
-
Object
- Object
- Untangle::Injector
- Defined in:
- lib/untangle/injector.rb
Instance Method Summary collapse
-
#initialize(parent_injector = nil) ⇒ Injector
constructor
A new instance of Injector.
- #inject(method) ⇒ Object
- #lookup(name) ⇒ Object
- #register(name, subject = nil) ⇒ Object
Constructor Details
#initialize(parent_injector = nil) ⇒ Injector
Returns a new instance of Injector.
6 7 8 9 |
# File 'lib/untangle/injector.rb', line 6 def initialize(parent_injector = nil) @parent_injector = parent_injector @subjects = {} end |
Instance Method Details
#inject(method) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/untangle/injector.rb', line 20 def inject(method) arguments = parameters(injection_method(method)).map { |type, name| lookup(name) } method.call(*arguments) end |
#lookup(name) ⇒ Object
16 17 18 |
# File 'lib/untangle/injector.rb', line 16 def lookup(name) @subjects[name] || handle_missing_subject(name) end |
#register(name, subject = nil) ⇒ Object
11 12 13 14 |
# File 'lib/untangle/injector.rb', line 11 def register(name, subject = nil) subject = yield if block_given? @subjects[name] = subject end |