Class: Corindon::DependencyInjection::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/corindon/dependency_injection/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_source, args: [], kwargs: {}, calls: [], tags: [], id: nil) ⇒ Definition

Returns a new instance of Definition.



16
17
18
19
20
21
22
23
# File 'lib/corindon/dependency_injection/definition.rb', line 16

def initialize(object_source, args: [], kwargs: {}, calls: [], tags: [], id: nil)
  @object_source = object_source
  @args = args
  @kwargs = kwargs
  @calls = calls
  @tags = tags
  @id = id
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/corindon/dependency_injection/definition.rb', line 9

def args
  @args
end

#callsObject (readonly)

Returns the value of attribute calls.



11
12
13
# File 'lib/corindon/dependency_injection/definition.rb', line 11

def calls
  @calls
end

#idString (readonly)

Returns:

  • (String)


14
15
16
# File 'lib/corindon/dependency_injection/definition.rb', line 14

def id
  @id
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



10
11
12
# File 'lib/corindon/dependency_injection/definition.rb', line 10

def kwargs
  @kwargs
end

#object_sourceObject (readonly)

Returns the value of attribute object_source.



8
9
10
# File 'lib/corindon/dependency_injection/definition.rb', line 8

def object_source
  @object_source
end

#tagsObject (readonly)

Returns the value of attribute tags.



12
13
14
# File 'lib/corindon/dependency_injection/definition.rb', line 12

def tags
  @tags
end

Instance Method Details

#build(injector) ⇒ Object

Parameters:

Returns:

  • (Object)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/corindon/dependency_injection/definition.rb', line 27

def build(injector)
  source = if object_source.is_a?(Class)
             [object_source, :new]
           else
             injector.resolve(object_source)
           end

  object = RubyCompat.do_call(*source, injector.resolve(args), injector.resolve(kwargs))

  calls.each do |(call, call_args, call_kwargs)|
    RubyCompat.do_call(object, call, injector.resolve(call_args), injector.resolve(call_kwargs))
  end

  object
end