Sha256: dc30a2cf08690a19bb31111881cd6fadd6be26a50498a8217cf0e587ae546f60

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require "dry/system/constants"
require_relative "component"

module Dry
  module System
    # 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
    class AutoRegistrar
      attr_reader :container

      def initialize(container)
        @container = container
      end

      # @api private
      def finalize!
        container.component_dirs.each do |component_dir|
          call(component_dir) if component_dir.auto_register?
        end
      end

      # @api private
      def call(component_dir)
        component_dir.each_component do |component|
          next unless register_component?(component)

          container.register(component.key, memoize: component.memoize?) { component.instance }
        end
      end

      private

      def register_component?(component)
        !container.registered?(component.key) && component.auto_register?
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dry-system-0.26.0 lib/dry/system/auto_registrar.rb
dry-system-0.25.0 lib/dry/system/auto_registrar.rb
dry-system-0.24.0 lib/dry/system/auto_registrar.rb
dry-system-0.23.0 lib/dry/system/auto_registrar.rb
dry-system-0.22.0 lib/dry/system/auto_registrar.rb
dry-system-0.21.0 lib/dry/system/auto_registrar.rb