Sha256: fd30921e67d40e8259e84c975c79e4c6fa05c73dfcc42fc5d8348bb14d9602a7

Contents?: true

Size: 1.13 KB

Versions: 13

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require "dry/system/constants"

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

13 entries across 13 versions & 1 rubygems

Version Path
dry-system-1.2.2 lib/dry/system/auto_registrar.rb
dry-system-1.2.1 lib/dry/system/auto_registrar.rb
dry-system-1.2.0 lib/dry/system/auto_registrar.rb
dry-system-1.1.1 lib/dry/system/auto_registrar.rb
dry-system-1.1.0 lib/dry/system/auto_registrar.rb
dry-system-1.1.0.beta2 lib/dry/system/auto_registrar.rb
dry-system-1.1.0.beta1 lib/dry/system/auto_registrar.rb
dry-system-1.0.1 lib/dry/system/auto_registrar.rb
dry-system-1.0.0 lib/dry/system/auto_registrar.rb
dry-system-1.0.0.rc1 lib/dry/system/auto_registrar.rb
dry-system-0.27.2 lib/dry/system/auto_registrar.rb
dry-system-0.27.1 lib/dry/system/auto_registrar.rb
dry-system-0.27.0 lib/dry/system/auto_registrar.rb