Sha256: cfaf430a55019b99175f7f9c12303398095e155722020d7eaae10e548512e4ec

Contents?: true

Size: 1.32 KB

Versions: 12

Compression:

Stored size: 1.32 KB

Contents

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)].each do |file|
          call(File.basename(file, RB_EXT))
        end
      end

      # @api private
      def call(name)
        name = name.respond_to?(:root_key) ? name.root_key.to_s : name

        require(root.join(config.registrations_dir, name))
      end

      def file_exists?(name)
        name = name.respond_to?(:root_key) ? name.root_key.to_s : name

        File.exist?(File.join(registrations_dir, "#{name}#{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

12 entries across 12 versions & 1 rubygems

Version Path
dry-system-0.12.0 lib/dry/system/manual_registrar.rb
dry-system-0.11.0 lib/dry/system/manual_registrar.rb
dry-system-0.10.1 lib/dry/system/manual_registrar.rb
dry-system-0.10.0 lib/dry/system/manual_registrar.rb
dry-system-0.9.2 lib/dry/system/manual_registrar.rb
dry-system-0.9.1 lib/dry/system/manual_registrar.rb
dry-system-0.9.0 lib/dry/system/manual_registrar.rb
dry-system-0.8.1 lib/dry/system/manual_registrar.rb
dry-system-0.8.0 lib/dry/system/manual_registrar.rb
dry-system-0.7.3 lib/dry/system/manual_registrar.rb
dry-system-0.7.2 lib/dry/system/manual_registrar.rb
dry-system-0.7.1 lib/dry/system/manual_registrar.rb