Module: Axiom::Adapter

Included in:
DataObjects, Memory
Defined in:
lib/rom/support/axiom/adapter.rb,
lib/rom/support/axiom/adapter/memory.rb,
lib/rom/support/axiom/adapter/sqlite3.rb,
lib/rom/support/axiom/adapter/postgres.rb,
lib/rom/support/axiom/adapter/data_objects.rb

Overview

TODO:

think about making this a (base) class

Provides base functionality for every axiom adapter

Examples:


class MyAdapter
  extend Axiom::Adapter
  uri_scheme :foo
end

Defined Under Namespace

Classes: DataObjects, Memory, Postgres, Sqlite3

Constant Summary collapse

REGISTRY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The registry of adapters

Returns:

  • (Hash<String, Object>)

    a hash of adapters, keyed by uri scheme

{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(uri) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the adapter to use for the given uri

Parameters:

  • uri (Addressable::URI)

    the uri to initialize the adapter with

Returns:

  • (Object)

    a axiom adapter

Raises:



41
42
43
44
45
46
47
48
49
50
51
# 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) ⇒ Class

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the adapter class registered for uri

Parameters:

  • uri (Addressable::URI)

    the uri that identifies the adapter class

Returns:

  • (Class)

    a axiom adapter class

Raises:



65
66
67
68
69
70
71
72
73
74
# 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

Instance Method Details

#uri_scheme(name) ⇒ self

Set the uri scheme for an adapter class

Examples:

for a DataObjects adapter


class Postgres < Axiom::Adapter::DataObjects
  uri_scheme :postgres
end

for an arbitrary adapter


class InMemory
  extend Axiom::Adapter
  uri_scheme :in_memory
end

Parameters:

  • name (#to_s)

    the name of the uri scheme

Returns:

  • (self)


106
107
108
# File 'lib/rom/support/axiom/adapter.rb', line 106

def uri_scheme(name)
  REGISTRY[name.to_s] = self
end