Sha256: 24719f2f872e93ea705f1b8411d77f9e3d59954e40c46f23ee7484c26226a808

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

# @api private
# @since 0.1.0
class SmartCore::Container::Entities::Namespace < SmartCore::Container::Entities::Base
  # @return [String]
  #
  # @api private
  # @since 0.1.0
  alias_method :namespace_name, :external_name

  # @param namespace_name [String]
  # @return [void]
  #
  # @api private
  # @since 0.1.0
  def initialize(namespace_name)
    super(namespace_name)
    @container_klass = Class.new(SmartCore::Container)
    @container_instance = nil
    @lock = SmartCore::Container::ArbitaryLock.new
  end

  # @return [SmartCore::Container]
  #
  # @api private
  # @since 0.1.0
  def reveal
    thread_safe { container_instance }
  end

  # @param dependencies_definition [Proc]
  # @return [void]
  #
  # @api private
  # @since 0.1.0
  def append_definitions(dependencies_definition)
    thread_safe { container_klass.instance_eval(&dependencies_definition) }
  end

  # @return [void]
  #
  # @api private
  # @since 0.1.0
  def freeze!
    thread_safe { container_instance.freeze! }
  end

  private

  # @return [Class<SmartCore::Container>]
  #
  # @api private
  # @since 0.1.0
  attr_reader :container_klass

  # @return [SmartCore::Container]
  #
  # @api private
  # @since 0.1.0
  def container_instance
    @container_instance ||= container_klass.new
  end

  # @param block [Block]
  # @return [Any]
  #
  # @api private
  # @since 0.1.0
  def thread_safe(&block)
    @lock.thread_safe(&block)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
smart_container-0.7.0 lib/smart_core/container/entities/namespace.rb
smart_container-0.6.0 lib/smart_core/container/entities/namespace.rb
smart_container-0.5.0 lib/smart_core/container/entities/namespace.rb
smart_container-0.4.0 lib/smart_core/container/entities/namespace.rb
smart_container-0.3.0 lib/smart_core/container/entities/namespace.rb
smart_container-0.2.0 lib/smart_core/container/entities/namespace.rb
smart_container-0.1.0 lib/smart_core/container/entities/namespace.rb