Class: RPath::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/rpath/registry.rb

Class Method Summary collapse

Class Method Details

.clearObject

Unregisters all adapters



36
37
38
# File 'lib/rpath/registry.rb', line 36

def clear
  id_to_adapter.clear
end

.find(id) ⇒ Adapter?

Finds a registered adapter by id.

Parameters:

  • id (Symbol)

Returns:



31
32
33
# File 'lib/rpath/registry.rb', line 31

def find(id)
  id_to_adapter[id]
end

.infer(graph) ⇒ Adapter?

Infers the adapter for a given graph. The first adapter whose #adapts? returns true is chosen.

Parameters:

  • graph (Object)

Returns:



24
25
26
# 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) ⇒ void Also known as: use

This method returns an undefined value.

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.

Parameters:

  • adapter (Adapter)
  • id (Symbol, nil) (defaults to: nil)

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



14
15
16
17
# File 'lib/rpath/registry.rb', line 14

def register(adapter, id = nil)
  id ||= default_id(adapter)
  id_to_adapter[id] = adapter
end