Sha256: 17e3508ed12b034926cf7d63329744c19731bcc7efdc25b8c72aa48ebb24abcd

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require "dry/system/constants"

module Dry
  module System
    # Default manual registration implementation
    #
    # This is currently configured by default for every System::Container.
    # Manual registrar objects are responsible for loading files from configured
    # manual registration paths, which should hold code to explicitly register
    # certain objects with the container.
    #
    # @api private
    class ManualRegistrar
      attr_reader :container

      attr_reader :config

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

      # @api private
      def finalize!
        ::Dir[registrations_dir.join(RB_GLOB)].sort.each do |file|
          call(File.basename(file, RB_EXT))
        end
      end

      # @api private
      def call(component)
        require(root.join(config.registrations_dir, component.root_key.to_s))
      end

      def file_exists?(component)
        File.exist?(File.join(registrations_dir, "#{component.root_key}#{RB_EXT}"))
      end

      private

      # @api private
      def registrations_dir
        root.join(config.registrations_dir)
      end

      # @api private
      def root
        container.root
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-system-0.22.0 lib/dry/system/manual_registrar.rb
dry-system-0.21.0 lib/dry/system/manual_registrar.rb