Sha256: 9b6a83b9d895b9b2c123c278a57124bdcf07d363dec2bee6add80459ea75d5d4

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require "dry/system/constants"

module Dry
  module System
    # Default manifest registration implementation
    #
    # This is configured by default for every System::Container. The manifest registrar is
    # responsible for loading manifest files that contain code to manually register
    # certain objects with the container.
    #
    # @api private
    class ManifestRegistrar
      # @api private
      attr_reader :container

      # @api private
      attr_reader :config

      # @api private
      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

      # @api private
      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.24.0 lib/dry/system/manifest_registrar.rb
dry-system-0.23.0 lib/dry/system/manifest_registrar.rb