Class: Axiom::Adapter::Memory

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/axiom/adapter/memory.rb,
lib/axiom/adapter/memory/version.rb

Overview

A reference adapter for in-memory information

Constant Summary collapse

UnknownRelationError =

Raised when the relation name is unknown

Class.new(IndexError)
VERSION =

Gem version

'0.2.0'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(schema = {}) ⇒ undefined

Initialize a Memory adapter

Examples:

with a schema

adapter = Axiom::Adapter::Memory.new(
  users: Axiom::Relation.new(
    [[:id, Integer], [:name, String]],
    [[1, 'Dan Kubb'], [2, 'John Doe']]
  )
)

without a schema

adapter = Axiom::Adapter::Memory.new

Parameters:



42
43
44
45
# File 'lib/axiom/adapter/memory.rb', line 42

def initialize(schema = {})
  @schema = ThreadSafe::Hash.new
  schema.each { |name, relation| self[name] = relation }
end

Instance Method Details

#[](name) ⇒ Axiom::Relation

Get relation variable in the schema

Examples:

adapter[:users]  # => users relation

Parameters:

  • name (Symbol)

Returns:



57
58
59
60
61
# File 'lib/axiom/adapter/memory.rb', line 57

def [](name)
  schema.fetch(name) do
    fail UnknownRelationError, "the relation named #{name} is unknown"
  end
end

#[]=(name, relation) ⇒ undefined

Set the relation variable in the schema

Examples:

adapter[:users] = users_relation

Parameters:

Returns:

  • (undefined)


74
75
76
# File 'lib/axiom/adapter/memory.rb', line 74

def []=(name, relation)
  schema[name] = Relation::Variable::Materialized.new(relation)
end