Class: Poniard::Injector
- Inherits:
-
Object
- Object
- Poniard::Injector
- Defined in:
- lib/poniard/injector.rb
Instance Attribute Summary collapse
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Instance Method Summary collapse
- #dispatch(method, overrides = {}) ⇒ Object
-
#initialize(sources) ⇒ Injector
constructor
A new instance of Injector.
- #injector ⇒ Object
Constructor Details
#initialize(sources) ⇒ Injector
Returns a new instance of Injector.
7 8 9 |
# File 'lib/poniard/injector.rb', line 7 def initialize(sources) @sources = sources + [self] end |
Instance Attribute Details
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
5 6 7 |
# File 'lib/poniard/injector.rb', line 5 def sources @sources end |
Instance Method Details
#dispatch(method, overrides = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/poniard/injector.rb', line 11 def dispatch(method, overrides = {}) args = method.parameters.map {|_, name| source = ( [OpenStruct.new(overrides)] + sources ).detect {|source| source.respond_to?(name) } if source dispatch(source.method(name), overrides) else UnknownInjectable.new(name) end } method.call(*args) end |
#injector ⇒ Object
26 27 28 |
# File 'lib/poniard/injector.rb', line 26 def injector self end |