module Axiom::Adapter
Provides base functionality for every axiom adapter
@todo think about making this a (base) class
@example
class MyAdapter extend Axiom::Adapter uri_scheme :foo end
Constants
- REGISTRY
The registry of adapters
@return [Hash<String, Object>]
a hash of adapters, keyed by uri scheme
@api private
Public Class Methods
build(uri)
click to toggle source
Return the adapter to use for the given uri
@param [Addressable::URI] uri
the uri to initialize the adapter with
@return [Object]
a axiom adapter
@raise [UnknownAdapterError]
when the given +uri+'s scheme is not registered
@api private
# File lib/rom/support/axiom/adapter.rb, line 41 def self.build(uri) require_adapter(uri) klass = get(uri) if klass.name == 'Axiom::Adapter::Memory' klass.new else klass.new(uri) end end
get(uri)
click to toggle source
Return the adapter class registered for uri
@param [Addressable::URI] uri
the uri that identifies the adapter class
@return [Class]
a axiom adapter class
@raise [UnknownAdapterError]
when the given +uri+'s scheme is not registered
@api private
# File lib/rom/support/axiom/adapter.rb, line 65 def self.get(uri) uri_scheme = uri.scheme REGISTRY.fetch(uri_scheme) { raise( UnknownAdapterError, "#{uri_scheme.inspect} is no registered uri scheme" ) } end
Private Class Methods
require_adapter(uri)
click to toggle source
Try to load an adapter using a standard path
@api private
# File lib/rom/support/axiom/adapter.rb, line 79 def self.require_adapter(uri) require "rom/support/axiom/adapter/#{uri.scheme}" rescue LoadError end
Public Instance Methods
uri_scheme(name)
click to toggle source
Set the uri scheme for an adapter class
@example for a DataObjects
adapter
class Postgres < Axiom::Adapter::DataObjects uri_scheme :postgres end
@example for an arbitrary adapter
class InMemory extend Axiom::Adapter uri_scheme :in_memory end
@param [#to_s] name
the name of the uri scheme
@return [self]
@api public
# File lib/rom/support/axiom/adapter.rb, line 106 def uri_scheme(name) REGISTRY[name.to_s] = self end