Class: RPath::Registry
- Inherits:
-
Object
- Object
- RPath::Registry
- Defined in:
- lib/rpath/registry.rb
Class Method Summary collapse
-
.clear ⇒ Object
Unregisters all adapters.
-
.find(id) ⇒ Adapter?
Finds a registered adapter by id.
-
.infer(graph) ⇒ Adapter?
Infers the adapter for a given graph.
-
.register(adapter, id = nil) ⇒ void
(also: use)
Registers an adapter.
Class Method Details
.clear ⇒ Object
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.
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.
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.
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 |