class Dry::System::AutoRegistrar
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.
@api private
Attributes
container[R]
Public Class Methods
new(container)
click to toggle source
# File lib/dry/system/auto_registrar.rb, line 19 def initialize(container) @container = container end
Public Instance Methods
call(component_dir)
click to toggle source
@api private
# File lib/dry/system/auto_registrar.rb, line 31 def call(component_dir) components(component_dir).each do |component| next unless register_component?(component) container.register(component.key, memoize: component.memoize?) { component.instance } end end
finalize!()
click to toggle source
@api private
# File lib/dry/system/auto_registrar.rb, line 24 def finalize! container.component_dirs.each do |component_dir| call(component_dir) if component_dir.auto_register? end end
Private Instance Methods
components(component_dir)
click to toggle source
# File lib/dry/system/auto_registrar.rb, line 41 def components(component_dir) files(component_dir.full_path).map { |file_path| component_dir.component_for_path(file_path) } end
files(dir)
click to toggle source
# File lib/dry/system/auto_registrar.rb, line 47 def files(dir) raise ComponentDirNotFoundError, dir unless Dir.exist?(dir) Dir["#{dir}/**/#{RB_GLOB}"].sort end
register_component?(component)
click to toggle source
# File lib/dry/system/auto_registrar.rb, line 53 def register_component?(component) !container.registered?(component.key) && component.auto_register? end