Class: Dry::AutoInject::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/auto_inject/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container, options = {}) ⇒ Builder

Returns a new instance of Builder.



15
16
17
18
# File 'lib/dry/auto_inject/builder.rb', line 15

def initialize(container, options = {})
  @container = container
  @strategies = options.fetch(:strategies) { Strategies }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



31
32
33
34
35
36
37
# File 'lib/dry/auto_inject/builder.rb', line 31

def method_missing(name, *args, &block)
  if strategies.key?(name)
    Injector.new(container, strategies[name], builder: self)
  else
    super
  end
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/auto_inject/builder.rb', line 7

def container
  @container
end

#strategiesObject (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/auto_inject/builder.rb', line 10

def strategies
  @strategies
end

Instance Method Details

#[](*dependency_names) ⇒ Object



21
22
23
# File 'lib/dry/auto_inject/builder.rb', line 21

def [](*dependency_names)
  default[*dependency_names]
end

#respond_to_missing?(name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/dry/auto_inject/builder.rb', line 25

def respond_to_missing?(name, _include_private = false)
  strategies.key?(name)
end