Class: Dry::Component::Injector

Inherits:
BasicObject
Defined in:
lib/dry/component/injector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container, options: {}, strategy: :default) ⇒ Injector

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Injector.



16
17
18
19
20
# File 'lib/dry/component/injector.rb', line 16

def initialize(container, options: {}, strategy: :default)
  @container = container
  @options = options
  @injector = ::Dry::AutoInject(container, options).__send__(strategy)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



28
29
30
# File 'lib/dry/component/injector.rb', line 28

def method_missing(name, *args, &block)
  ::Dry::Component::Injector.new(container, options: options, strategy: name)
end

Instance Attribute Details

#containerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



7
8
9
# File 'lib/dry/component/injector.rb', line 7

def container
  @container
end

#injectorObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/dry/component/injector.rb', line 13

def injector
  @injector
end

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/dry/component/injector.rb', line 10

def options
  @options
end

Instance Method Details

#[](*deps) ⇒ Object



23
24
25
26
# File 'lib/dry/component/injector.rb', line 23

def [](*deps)
  load_components(*deps)
  injector[*deps]
end

#respond_to?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/dry/component/injector.rb', line 32

def respond_to?(name, include_private = false)
  injector.respond_to?(name, include_private)
end