Module: Dio::ModuleBase

Extended by:
ActiveSupport::Concern
Defined in:
lib/dio/module_base.rb

Overview

Dio::ModuleBase provides core methods as a mixin. Dio module extends this module so you can use all of the methods from Dio like ‘Dio.injector`.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Instance Method Summary collapse

Instance Method Details

#clear_stubs(clazz = nil) ⇒ Object



61
62
63
# File 'lib/dio/module_base.rb', line 61

def clear_stubs(clazz = nil)
  injector.clear_stubs(clazz)
end

#create(clazz, *args) ⇒ Object

Create an instance of the given class with injection.

See Also:



35
36
37
# File 'lib/dio/module_base.rb', line 35

def create(clazz, *args)
  injector.create(clazz, *args)
end

#inject(target) ⇒ Object

Injects dependencies using the injector this module has.

See Also:



27
28
29
# File 'lib/dio/module_base.rb', line 27

def inject(target)
  injector.inject(target)
end

#injector(id = nil) ⇒ Dio::Injector

Returns a injector associated with this module. If you call ‘Dio.injector`, it returns a default injector. If an ID is given, returns an injector of the ID.

Parameters:

  • id (Symbol) (defaults to: nil)

Returns:



19
20
21
# File 'lib/dio/module_base.rb', line 19

def injector(id = nil)
  @state.injector(id || @injector_id)
end

#reset_loader(clazz = nil) ⇒ Object



56
57
58
# File 'lib/dio/module_base.rb', line 56

def reset_loader(clazz = nil)
  injector.reset_loader(clazz)
end

#reset_stateObject

Reset a whole state. This is used mainly for tests.



41
42
43
# File 'lib/dio/module_base.rb', line 41

def reset_state
  @state.reset(@injector_id => Dio::Injector.new)
end

#stub_deps(clazz, deps) ⇒ Object

See Also:



51
52
53
# File 'lib/dio/module_base.rb', line 51

def stub_deps(clazz, deps)
  injector.stub_deps(clazz, deps)
end

#wrap_load(clazz, &wrapper) ⇒ Object

See Also:



46
47
48
# File 'lib/dio/module_base.rb', line 46

def wrap_load(clazz, &wrapper)
  injector.wrap_load(clazz, &wrapper)
end