Module: Porous::Injection
- Included in:
- Component
- Defined in:
- lib/porous/injection.rb
Instance Attribute Summary collapse
-
#injections ⇒ Object
readonly
Returns the value of attribute injections.
Instance Method Summary collapse
Instance Attribute Details
#injections ⇒ Object (readonly)
Returns the value of attribute injections.
21 22 23 |
# File 'lib/porous/injection.rb', line 21 def injections @injections end |
Instance Method Details
#init ⇒ Object
5 |
# File 'lib/porous/injection.rb', line 5 def init; end |
#init_injections ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/porous/injection.rb', line 23 def init_injections @injections ||= {} self.class.injections.each do |name, klass| unless klass.included_modules.include?(Porous::Injection) raise Error, "Invalid #{klass} class, should mixin Porous::Injection" end @injections[name] = klass.new.with_root_component(@root_component) end @injections.each_value do |instance| instance.inject instance.init end end |
#inject ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/porous/injection.rb', line 12 def inject @root_component.injections.each do |name, instance| define_singleton_method(name) do instance end end self end |
#with_root_component(component) ⇒ Object
7 8 9 10 |
# File 'lib/porous/injection.rb', line 7 def with_root_component(component) @root_component = component self end |