Class: Untangle::Injector

Inherits:
Object
  • Object
show all
Defined in:
lib/untangle/injector.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent_injector = nil) ⇒ Injector

Returns a new instance of Injector.


6
7
8
9
# File 'lib/untangle/injector.rb', line 6

def initialize(parent_injector = nil)
  @parent_injector = parent_injector
  @subjects = {}
end

Instance Method Details

#inject(method) ⇒ Object


20
21
22
23
24
25
# File 'lib/untangle/injector.rb', line 20

def inject(method)
  arguments = parameters(injection_method(method)).map { |type, name|
    lookup(name)
  }
  method.call(*arguments)
end

#lookup(name) ⇒ Object


16
17
18
# File 'lib/untangle/injector.rb', line 16

def lookup(name)
  @subjects[name] || handle_missing_subject(name)
end

#register(name, subject = nil) ⇒ Object


11
12
13
14
# File 'lib/untangle/injector.rb', line 11

def register(name, subject = nil)
  subject = yield if block_given?
  @subjects[name] = subject
end