module Dio::ModuleBase::ClassMethods
ClassMethods
defines class methods for classes using Dio
.
Public Instance Methods
__dio_injection_proc__()
click to toggle source
@api private
# File lib/dio/module_base.rb, line 119 def __dio_injection_proc__ @__dio_injection_proc__ end
inject(&injector)
click to toggle source
Defines a block to load dependencies from Dio
. A given block is evaluated in each instance context of the class.
@yield [Dio::LoaderFactory::Loader]
# File lib/dio/module_base.rb, line 114 def inject(&injector) @__dio_injection_proc__ = injector end
injectable(subkey = nil, &block)
click to toggle source
Declares the class is an injectable via Dio
. You can define a factory block.
@param subkey [Symbol, nil] @yield passed arguments when loading
# 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, &factory)
click to toggle source
Registers a factory of a dependency.
@param key [Symbol] @yield passed arguments when loading
# 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