Sha256: babe378064e4c127ff06dcaa9be24552e0326c26badc43318f0e2f52e02e041b

Contents?: true

Size: 989 Bytes

Versions: 7

Compression:

Stored size: 989 Bytes

Contents

# frozen_string_literal: true

# @api private
# @since 0.5.0
class SmartCore::Initializer::TypeSet
  # @return [void]
  #
  # @api private
  # @since 0.5.0
  def initialize
    @types = {}
  end

  # @param name [String, Symbol]
  # @return [Boolean]
  #
  # @api private
  # @since 0.5.0
  def has_type?(name)
    types.key?(name)
  end

  # @param name [String, Symbol]
  # @param checker [Proc]
  # @return [void]
  #
  # @api private
  # @since 0.5.0
  def register(name, checker)
    type = SmartCore::Initializer::Type.new(name, checker)
    types[type.name] = type
  end

  # @param name [String, Symbol]
  # @return [SmartCore::Initializer::Type]
  #
  # @api private
  # @since 0.5.0
  def resolve(name)
    types.fetch(name.to_sym)
  rescue KeyError
    raise SmartCore::Initializer::UnregisteredTypeError, "type :#{name} is not registered!"
  end

  private

  # @return [Hash<Symbol,SmartCore::Initializer::Type>]
  #
  # @api private
  # @since 0.5.0
  attr_reader :types
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
smart_core-0.8.1 lib/smart_core/initializer/type_set.rb
smart_core-0.8.0 lib/smart_core/initializer/type_set.rb
smart_core-0.7.0 lib/smart_core/initializer/type_set.rb
smart_core-0.6.0 lib/smart_core/initializer/type_set.rb
smart_core-0.5.2 lib/smart_core/initializer/type_set.rb
smart_core-0.5.1 lib/smart_core/initializer/type_set.rb
smart_core-0.5.0 lib/smart_core/initializer/type_set.rb