Sha256: 4f7a5fd482757752572c7126e269ceb5b9748099a90564be0cfd41dfb0843936

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module SmartCore::Container::DefinitionDSL::Commands::Definition
  # @api private
  # @since 0.1.0
  class Register < SmartCore::Container::DefinitionDSL::Commands::Base
    # @since 0.1.0
    self.inheritable = true

    # @return [String]
    #
    # @api private
    # @since 0.1.0
    attr_reader :dependency_name

    # @param dependency_name [String, Symbol]
    # @param dependency_definition [Proc]
    # @return [void]
    #
    # @api private
    # @since 0.1.0
    def initialize(dependency_name, dependency_definition)
      SmartCore::Container::KeyGuard.indifferently_accessable_key(dependency_name).tap do |name|
        @dependency_name = name
        @dependency_definition = dependency_definition
      end
    end

    # @param registry [SmartCore::Container::Registry]
    # @return [void]
    #
    # @api private
    # @since 0.1.0
    def call(registry)
      registry.register_dependency(dependency_name, &dependency_definition)
    end

    # @return [SmartCore::Container::DefinitionDSL::Commands::Definition::Register]
    #
    # @api private
    # @since 0.1.0
    def dup
      self.class.new(dependency_name, dependency_definition)
    end

    private

    # @return [Proc]
    #
    # @api private
    # @since 0.1.0
    attr_reader :dependency_definition
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smart_container-0.1.0 lib/smart_core/container/definition_dsl/commands/definition/register.rb