Class: Dio::LoadContext
- Inherits:
-
Object
- Object
- Dio::LoadContext
- Defined in:
- lib/dio/load_context.rb
Overview
LoadContext provides some information about current loading.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#key ⇒ Object
readonly
A key of a loaded dependency.
-
#target ⇒ Object
readonly
An instance which is injected to.
Instance Method Summary collapse
-
#initialize(key, target, args, loader) ⇒ LoadContext
constructor
A new instance of LoadContext.
-
#load(*args) ⇒ Object
Loads a dependency.
Constructor Details
#initialize(key, target, args, loader) ⇒ LoadContext
Returns a new instance of LoadContext.
14 15 16 17 18 19 |
# File 'lib/dio/load_context.rb', line 14 def initialize(key, target, args, loader) @key = key @target = target @args = args @loader = loader end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
12 |
# File 'lib/dio/load_context.rb', line 12 attr_reader :key, :target, :args |
#key ⇒ Object (readonly)
A key of a loaded dependency.
12 13 14 |
# File 'lib/dio/load_context.rb', line 12 def key @key end |
#target ⇒ Object (readonly)
An instance which is injected to.
12 |
# File 'lib/dio/load_context.rb', line 12 attr_reader :key, :target, :args |
Instance Method Details
#load(*args) ⇒ Object
Loads a dependency. You can omit arguments because the LoadContext instance already has arguments for loading.
26 27 28 29 |
# File 'lib/dio/load_context.rb', line 26 def load(*args) next_args = args.any? ? args : @args @loader.call(@key, *next_args) end |