Class: Dry::System::AutoRegistrar Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/system/auto_registrar.rb,
lib/dry/system/auto_registrar/configuration.rb

Overview

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

Default auto-registration implementation

This is currently configured by default for every System::Container. Auto-registrar objects are responsible for loading files from configured auto-register paths and registering components automatically within the container.

Defined Under Namespace

Classes: Configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container) ⇒ AutoRegistrar

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 AutoRegistrar.



20
21
22
23
# File 'lib/dry/system/auto_registrar.rb', line 20

def initialize(container)
  @container = container
  @config = container.config
end

Instance Attribute Details

#configObject (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.



18
19
20
# File 'lib/dry/system/auto_registrar.rb', line 18

def config
  @config
end

#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.



16
17
18
# File 'lib/dry/system/auto_registrar.rb', line 16

def container
  @container
end

Instance Method Details

#call(dir) {|registration_config| ... } ⇒ Object

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.

Yields:

  • (registration_config)


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dry/system/auto_registrar.rb', line 31

def call(dir)
  registration_config = Configuration.new
  yield(registration_config) if block_given?
  components(dir).each do |component|
    next if !component.auto_register? || registration_config.exclude.(component)

    container.require_component(component) do
      register(component.identifier, memoize: registration_config.memoize) { registration_config.instance.(component) }
    end
  end
end

#finalize!Object

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.



26
27
28
# File 'lib/dry/system/auto_registrar.rb', line 26

def finalize!
  Array(config.auto_register).each { |dir| call(dir) }
end