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(klass, args: [], kwargs: {}, calls: [], tags: [], id: nil, anonymous: false) ⇒ Definition

Returns a new instance of Definition.



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

def initialize(klass, args: [], kwargs: {}, calls: [], tags: [], id: nil, anonymous: false)
  @klass = klass
  @args = args
  @kwargs = kwargs
  @calls = calls
  @tags = tags
  @id = id
  @anonymous = anonymous
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

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
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

#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

#anonymous?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/corindon/dependency_injection/definition.rb', line 38

def anonymous?
  @anonymous
end

#build(injector) ⇒ Object

# @return [Object]

Parameters:



27
28
29
30
31
32
33
34
35
# File 'lib/corindon/dependency_injection/definition.rb', line 27

def build(injector)
  object = do_call(klass, :new, injector.resolve(args), injector.resolve(kwargs))

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

  object
end