Class: Dio::LoadContext

Inherits:
Object
  • Object
show all
Defined in:
lib/dio/load_context.rb

Overview

LoadContext provides some information about current loading.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argsObject (readonly)

Returns the value of attribute args.



12
# File 'lib/dio/load_context.rb', line 12

attr_reader :key, :target, :args

#keyObject (readonly)

A key of a loaded dependency.



12
13
14
# File 'lib/dio/load_context.rb', line 12

def key
  @key
end

#targetObject (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.

Parameters:

  • args (Array)

Returns:

  • (Object)

    The dependency object.



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