Module: Dio::ModuleBase::ClassMethods
- Defined in:
- lib/dio/module_base.rb
Overview
ClassMethods defines class methods for classes using Dio.
Instance Method Summary collapse
- #__dio_injection_proc__ ⇒ Object private
-
#inject {|Dio::LoaderFactory::Loader| ... } ⇒ Object
Defines a block to load dependencies from Dio.
-
#injectable(subkey = nil) { ... } ⇒ Object
Declares the class is an injectable via Dio.
-
#provide(key) { ... } ⇒ Object
Registers a factory of a dependency.
Instance Method Details
#__dio_injection_proc__ ⇒ Object
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.
119 120 121 |
# File 'lib/dio/module_base.rb', line 119 def __dio_injection_proc__ @__dio_injection_proc__ end |
#inject {|Dio::LoaderFactory::Loader| ... } ⇒ Object
Defines a block to load dependencies from Dio. A given block is evaluated in each instance context of the class.
114 115 116 |
# File 'lib/dio/module_base.rb', line 114 def inject(&injector) @__dio_injection_proc__ = injector end |
#injectable(subkey = nil) { ... } ⇒ Object
Declares the class is an injectable via Dio. You can define a factory block.
95 96 97 98 99 |
# File 'lib/dio/module_base.rb', line 95 def injectable(subkey = nil, &block) key = subkey ? [self, subkey] : self factory = block || ->(*args) { new(*args) } __dio_injector__.register(key, &factory) end |
#provide(key) { ... } ⇒ Object
Registers a factory of a dependency.
105 106 107 108 |
# File 'lib/dio/module_base.rb', line 105 def provide(key, &factory) raise "You must define a factory of #{key}" unless block_given? __dio_injector__.register(key, &factory) end |