class SmartCore::Initializer::TypeSystem::Registry

@api private @since 0.1.0

Attributes

systems[R]

@return [Hash<String,Class<SmartCore::Initializer::TypeSystem::Interop>]

@api private @since 0.1.0

Public Class Methods

new() click to toggle source

@return [void]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 13
def initialize
  @systems = {}
  @lock = SmartCore::Engine::Lock.new
end

Public Instance Methods

each(&block) click to toggle source

@param block [Block] @yield [system_name, system_interop]

@yieldparam system_name [String]
@yieldparam system_interop [Class<SmartCore::Initializer::TypeSystem::Interop>]

@return [Enumerable]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 61
def each(&block)
  thread_safe { iterate(&block) }
end
interops() click to toggle source

@return [Array<Class<SmartCore::Initializer::TypeSystem::Interop>>]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 49
def interops
  thread_safe { system_interops }
end
names() click to toggle source

@return [Array<String>]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 41
def names
  thread_safe { system_names }
end
register(system_identifier, interop_klass) click to toggle source

@param system_identifier [String, Symbol] @param interop_klass [Class<SmartCore::Initializer::TypeSystem::Interop>] @return [void]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 24
def register(system_identifier, interop_klass)
  thread_safe { apply(system_identifier, interop_klass) }
end
resolve(system_identifier) click to toggle source

@param system_identifier [String, Symbol] @return [Class<SmartCore::Initializer::TypeSystem::Interop>]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 33
def resolve(system_identifier)
  thread_safe { fetch(system_identifier) }
end
to_h() click to toggle source

@return [Hash<String,Class<SmartCore::Initializer::TypeSystem::Interop>]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 69
def to_h
  thread_safe { systems.dup }
end
Also aliased as: to_hash
to_hash()
Alias for: to_h

Private Instance Methods

apply(system_identifier, interop_klass) click to toggle source

@param system_identifier [String, Symbol] @param interop_klass [Class<SmartCore::Initializer::TypeSystem::Interop>] @return [void]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 116
def apply(system_identifier, interop_klass)
  prevent_incorrect_system_interop!(interop_klass)
  identifier = indifferently_accessible_identifier(system_identifier)
  systems[identifier] = interop_klass
end
fetch(system_identifier) click to toggle source

@param system_identifier [String, Symbol] @return [Class<SmartCore::Initializer::TypeSystem::Interop>]

@raise [SmartCore::Initializer::UnsupportedTypeSystemError]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 129
  def fetch(system_identifier)
    identifier = indifferently_accessible_identifier(system_identifier)

    begin
      systems.fetch(identifier)
    rescue ::KeyError
      raise(SmartCore::Initializer::UnsupportedTypeSystemError, <<~ERROR_MESSAGE)
        "#{identifier}" type system is not supported.
      ERROR_MESSAGE
    end
  end
indifferently_accessible_identifier(system_identifier) click to toggle source

@param system_identifier [String, Symbol] @return [String]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 162
def indifferently_accessible_identifier(system_identifier)
  system_identifier.to_s.clone.tap(&:freeze)
end
iterate(&block) click to toggle source

@param block [Block] @yield [system_name, system_interop]

@yieldparam system_name [String]
@yieldparam system_interop [Class<SmartCore::Initializer::TypeSystem::Interop>]

@return [Enumerable]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 106
def iterate(&block)
  block_given? ? systems.each_pair(&block) : systems.each_pair
end
prevent_incorrect_system_interop!(interop_klass) click to toggle source

@param interop_klass [Class<SMartCore::Initializer::TypeSystem::Interop>] @return [void]

@raise [SmartCore::Initializer::IncorrectTypeSystemInteropError]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 148
def prevent_incorrect_system_interop!(interop_klass)
  unless interop_klass.is_a?(Class) && interop_klass < SmartCore::Initializer::TypeSystem::Interop
    raise(
      SmartCore::Initializer::IncorrectTypeSystemInteropError,
      'Incorrect type system interop class.'
    )
  end
end
system_interops() click to toggle source

@return [Array<Class<SmartCore::Initializer::TypeSystem::Interop>>]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 94
def system_interops
  systems.values
end
system_names() click to toggle source

@return [Array<String>]

@pai private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 86
def system_names
  systems.keys
end
thread_safe(&block) click to toggle source

@param block [Block] @return [Any]

@api private @since 0.1.0

# File lib/smart_core/initializer/type_system/registry.rb, line 171
def thread_safe(&block)
  @lock.synchronize(&block)
end