module SmartCore::Injection::Injector::Modulizer

@api private @since 0.1.0

Public Class Methods

inject_to(base_klass) click to toggle source

@param base_klass [Class, Module] @return [void]

@api private @since 0.1.0

# File lib/smart_core/injection/injector/modulizer.rb, line 22
def inject_to(base_klass)
  base_klass.include(::SmartCore::Injection::DSL)
end
with_containers(containers) click to toggle source

@param containers [Array<SmartCore::Container>] @return [Module]

@api private @since 0.1.0

# File lib/smart_core/injection/injector/modulizer.rb, line 12
def with_containers(containers)
  prevent_inconsistency!(containers)
  build_container_injectable_module(containers)
end

Private Class Methods

build_container_injectable_module(containers) click to toggle source

@param containers [Array<SmartCore::Container>] @return [Module]

@api private @since 0.1.0

# File lib/smart_core/injection/injector/modulizer.rb, line 46
def build_container_injectable_module(containers)
  Module.new do
    define_singleton_method :included do |base_klass|
      base_klass.include(::SmartCore::Injection::DSL)
      base_klass.register_container(*containers)
    end
  end
end
prevent_inconsistency!(containers) click to toggle source

@param containers [Array<SmartCore::Container>] @return [void]

@api private @since 0.1.0

# File lib/smart_core/injection/injector/modulizer.rb, line 33
    def prevent_inconsistency!(containers)
      unless containers.is_a?(Array) && containers.all? { |cont| cont.is_a?(SmartCore::Container) }
        raise(SmartCore::Injection::ArgumentError, <<~ERROR_MESSAGE)
          Injectable containers should be a type of SmartCore::Container
        ERROR_MESSAGE
      end
    end