class Axiom::Adapter::Memory

A reference adapter for in-memory information

Constants

UnknownRelationError

Raised when the relation name is unknown

VERSION

Gem version

Attributes

schema[R]

The schema

@return [Hash{Symbol => Axiom::Relation}]

@api private

Public Class Methods

new(schema = {}) click to toggle source

Initialize a Memory adapter

@example with a schema

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

@example without a schema

adapter = Axiom::Adapter::Memory.new

@param [Hash{Symbol => Axiom::Relation}] schema

@return [undefined]

@api public

# File lib/axiom/adapter/memory.rb, line 42
def initialize(schema = {})
  @schema = ThreadSafe::Hash.new
  schema.each { |name, relation| self[name] = relation }
end

Public Instance Methods

[](name) click to toggle source

Get relation variable in the schema

@example

adapter[:users]  # => users relation

@param [Symbol] name

@return [Axiom::Relation]

@api public

# 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) click to toggle source

Set the relation variable in the schema

@example

adapter[:users] = users_relation

@param [Symbol] name @param [Axiom::Relation] relation

@return [undefined]

@api public

# File lib/axiom/adapter/memory.rb, line 74
def []=(name, relation)
  schema[name] = Relation::Variable::Materialized.new(relation)
end