Sha256: 5d51831c38db742a46e139be790f73999ffacbffdf1bbabbcf6520443b45c334

Contents?: true

Size: 1.93 KB

Versions: 11

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

# @api private
# @since 0.1.0
module SmartCore::Container::RegistryBuilder
  # rubocop:disable Layout/LineLength
  class << self
    # @parma container [SmartCore::Container]
    # @option ignored_definition_commands [Array<Class::SmartCore::Container::DefinitionDSL::Commands::Base>>]
    # @option ignored_instantiation_commands [Array<Class::SmartCore::Container::DefinitionDSL::Commands::Base>>]
    # @return [SmartCore::Container::Registry]
    #
    # @api private
    # @since 0.1.0
    def build(container, ignored_definition_commands: [], ignored_instantiation_commands: [])
      SmartCore::Container::Registry.new.tap do |registry|
        define(container.class, registry, ignored_commands: ignored_definition_commands)
        instantiate(container.class, registry, ignored_commands: ignored_instantiation_commands)
      end
    end

    # @param container_klass [Class<SmartCore::Container>]
    # @param registry [SmartCore::Container::Registry]
    # @option ignored_commands [Array<Class<SmartCore::Container::DefinitionDSL::Commands::Base>>]
    # @return [void]
    #
    # @api private
    # @since 0.1.0
    def define(container_klass, registry, ignored_commands: [])
      container_klass.__container_definition_commands__.each do |command|
        next if ignored_commands.include?(command.class)
        command.call(registry)
      end
    end

    # @param container_klass [Class<SmartCore::Container>]
    # @param registry [SmartCore::Container::Registry]
    # @option ignored_commands [Array<Class<SmartCore::Container::DefinitionDSL::Commands::Base>>]
    # @return [void]
    #
    # @api private
    # @since 0.1.0
    def instantiate(container_klass, registry, ignored_commands: [])
      container_klass.__container_instantiation_commands__.each do |command|
        next if ignored_commands.include?(command.class)
        command.call(registry)
      end
    end
  end
  # rubocop:enable Layout/LineLength
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
smart_container-0.11.0 lib/smart_core/container/registry_builder.rb
smart_container-0.10.0 lib/smart_core/container/registry_builder.rb
smart_container-0.9.0 lib/smart_core/container/registry_builder.rb
smart_container-0.8.1 lib/smart_core/container/registry_builder.rb
smart_container-0.8.0 lib/smart_core/container/registry_builder.rb
smart_container-0.7.0 lib/smart_core/container/registry_builder.rb
smart_container-0.6.0 lib/smart_core/container/registry_builder.rb
smart_container-0.5.0 lib/smart_core/container/registry_builder.rb
smart_container-0.4.0 lib/smart_core/container/registry_builder.rb
smart_container-0.3.0 lib/smart_core/container/registry_builder.rb
smart_container-0.2.0 lib/smart_core/container/registry_builder.rb