class RPath::Registry

@private

Public Class Methods

clear() click to toggle source

Unregisters all adapters

# File lib/rpath/registry.rb, line 36
def clear
  id_to_adapter.clear
end
find(id) click to toggle source

Finds a registered adapter by id. @param [Symbol] id @return [Adapter, nil]

# File lib/rpath/registry.rb, line 31
def find(id)
  id_to_adapter[id]
end
infer(graph) click to toggle source

Infers the adapter for a given graph. The first adapter whose {#adapts?} returns true is chosen. @param [Object] graph @return [Adapter, nil]

# File lib/rpath/registry.rb, line 24
def infer(graph)
  id_to_adapter.each_value.find { |adapter| adapter.adapts?(graph) }
end
register(adapter, id = nil) click to toggle source

Registers an adapter. Once an adapter is registered, RPath calls its {#adapts?} when trying to infer the adapter for an evaluation, and its id, as opposed to an instance, may be given to {#RPath}. @param [Adapter] adapter @param [Symbol, nil] id

An id that can later be passed to {#RPath}. If omitted, the
symbolized, underscored name of the adapter class is assumed.

@return [void]

# File lib/rpath/registry.rb, line 14
def register(adapter, id = nil)
  id ||= default_id(adapter)
  id_to_adapter[id] = adapter
end
Also aliased as: use
use(adapter, id = nil)
Alias for: register

Private Class Methods

default_id(adapter) click to toggle source
# File lib/rpath/registry.rb, line 46
def default_id(adapter)
  Util.underscore(adapter.class.name.split('::').last).to_sym
end
id_to_adapter() click to toggle source
# File lib/rpath/registry.rb, line 42
def id_to_adapter
  @id_to_adapter ||= {}
end