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 10 11 12 13 14 15 |
# File 'lib/poniard/injector.rb', line 7 def initialize(sources = []) @sources = sources.map {|source| if source.is_a? Hash OpenStruct.new(source) else source end }+ [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
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/poniard/injector.rb', line 17 def dispatch(method, overrides = {}) args = method.parameters.map {|_, name| source = sources_for(overrides).detect {|source| source.respond_to?(name) } if source dispatch(source.method(name), overrides) else UnknownInjectable.new(name) end } method.(*args) end |
#injector ⇒ Object
32 33 34 |
# File 'lib/poniard/injector.rb', line 32 def injector self end |