Class: DependencyInjection::Definition

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

Direct Known Subclasses

LazyDefinition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass_name, container) ⇒ Definition

Returns a new instance of Definition.



8
9
10
11
12
13
14
15
# File 'lib/dependency_injection/definition.rb', line 8

def initialize(klass_name, container)
  @container        = container
  self.arguments    = []
  self.file_path    = nil
  self.klass_name   = klass_name
  self.method_calls = {}
  self.scope        = :container
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



6
7
8
# File 'lib/dependency_injection/definition.rb', line 6

def arguments
  @arguments
end

#configuratorObject

Returns the value of attribute configurator.



6
7
8
# File 'lib/dependency_injection/definition.rb', line 6

def configurator
  @configurator
end

#file_pathObject

Returns the value of attribute file_path.



6
7
8
# File 'lib/dependency_injection/definition.rb', line 6

def file_path
  @file_path
end

#klass_nameObject

Returns the value of attribute klass_name.



6
7
8
# File 'lib/dependency_injection/definition.rb', line 6

def klass_name
  @klass_name
end

#method_callsObject

Returns the value of attribute method_calls.



6
7
8
# File 'lib/dependency_injection/definition.rb', line 6

def method_calls
  @method_calls
end

#scopeObject

Returns the value of attribute scope.



6
7
8
# File 'lib/dependency_injection/definition.rb', line 6

def scope
  @scope
end

Instance Method Details

#add_argument(argument) ⇒ Object



17
18
19
# File 'lib/dependency_injection/definition.rb', line 17

def add_argument(argument)
  self.add_arguments(argument)
end

#add_arguments(*arguments) ⇒ Object



21
22
23
24
25
# File 'lib/dependency_injection/definition.rb', line 21

def add_arguments(*arguments)
  self.arguments += arguments

  self
end

#add_configurator(name, method_name) ⇒ Object



27
28
29
30
31
# File 'lib/dependency_injection/definition.rb', line 27

def add_configurator(name, method_name)
  self.configurator = [name, method_name]

  self
end

#add_method_call(method_name, *arguments) ⇒ Object



33
34
35
36
37
# File 'lib/dependency_injection/definition.rb', line 33

def add_method_call(method_name, *arguments)
  self.method_calls[method_name] = arguments

  self
end

#klassObject



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

def klass
  self.klass_name.constantize
end

#objectObject



43
44
45
# File 'lib/dependency_injection/definition.rb', line 43

def object
  self.send("#{self.scope}_scoped_object")
end