-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update schema to use a thread safe Hash. * Add #[] and #[]= methods to the adapter api to allow getting and setting the named relations. * Add initial #update method to the relation/gateway api. Will need to add Axiom::Relation::Operation::Update as well as base #update method to Axiom relations matching this api.
- Loading branch information
Showing
17 changed files
with
497 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
--- | ||
threshold: 14 | ||
total_score: 18 | ||
threshold: 11 | ||
total_score: 38 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# encoding: utf-8 | ||
|
||
module Axiom | ||
module Adapter | ||
class Memory | ||
|
||
# A gateway relation to the memory adapter | ||
class Gateway < Relation | ||
include Adamantium::Flat, Relation::Proxy | ||
include Equalizer.new(:adapter, :name, :relation) | ||
|
||
# The adapter the gateway will use to fetch results | ||
# | ||
# @return [Axiom:Adapter::Memory] | ||
# | ||
# @api private | ||
attr_reader :adapter | ||
protected :adapter | ||
|
||
# The gateway name | ||
# | ||
# @example | ||
# gateway.name # => "users" | ||
# | ||
# @return [String] | ||
# | ||
# @api public | ||
attr_reader :name | ||
|
||
# The gateway relation | ||
# | ||
# @example | ||
# gateway.relation # => a set of tuples | ||
# | ||
# @return [Axiom::Relation] | ||
# | ||
# @api public | ||
attr_reader :relation | ||
|
||
# Initialize a memory gateway | ||
# | ||
# @param [Axiom::Adapter::Memory] adapter | ||
# @param [#to_str] name | ||
# @param [Axiom::Relation] relation | ||
# | ||
# @return [undefined] | ||
# | ||
# @api private | ||
def initialize(adapter, name, relation) | ||
@adapter = adapter | ||
@name = name.to_str | ||
@relation = relation.materialize | ||
end | ||
|
||
# Return a relation that represents an insertion into a relation | ||
# | ||
# @example | ||
# insertion = relation.insert(other) | ||
# | ||
# @param [Enumerable] other | ||
# | ||
# @return [Axiom::Adapter::Memory::Gateway] | ||
# | ||
# @api public | ||
def insert(other) | ||
adapter.insert(self, other) | ||
new | ||
end | ||
|
||
# Return a relation that represents a deletion from a relation | ||
# | ||
# @example | ||
# deletion = relation.delete(other) | ||
# | ||
# @param [Enumerable] other | ||
# | ||
# @return [Axiom::Adapter::Memory::Gateway] | ||
# | ||
# @api public | ||
def delete(other) | ||
adapter.delete(self, other) | ||
new | ||
end | ||
|
||
# Return a relation that represents an update of a relation | ||
# | ||
# @example with a hash | ||
# update = relation.update(a: 1, b: 2) | ||
# | ||
# @example with a block | ||
# update = relation.update do |r| | ||
# r[:name] = r.concat(r[:first], r[:last]) | ||
# end | ||
# | ||
# @param [Enumerable] other | ||
# | ||
# @return [Axiom::Adapter::Memory::Gateway] | ||
# | ||
# @api public | ||
def update(&block) | ||
# TODO: implement logic to handle restriction-like input | ||
adapter.update(self, &block) | ||
new | ||
end | ||
|
||
private | ||
|
||
# Return a new gateway for the relation | ||
# | ||
# @return [Axiom::Adapter::Memory::Gateway] | ||
# | ||
# @api private | ||
def new | ||
adapter[name] | ||
end | ||
|
||
end # Gateway | ||
|
||
end # Memory | ||
end # Adapter | ||
end # Axiom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe Axiom::Adapter::Memory::Gateway do | ||
subject { described_class.new(adapter, name, relation) } | ||
|
||
include_context 'relation' | ||
|
||
let(:adapter) { Axiom::Adapter::Memory.new(schema) } | ||
|
||
describe '#insert' do | ||
it 'inserts a new tuple' do | ||
new_gateway = subject.insert([[3], [4]]) | ||
expect(new_gateway.to_a).to eq([[1], [2], [3], [4]]) | ||
end | ||
end | ||
|
||
describe '#replace' do | ||
it 'replaces with new tuples' do | ||
new_gateway = subject.replace([[2]]) | ||
expect(new_gateway.to_a).to eq([[2]]) | ||
end | ||
end | ||
|
||
describe '#delete' do | ||
it 'deletes matching tuples' do | ||
new_gateway = subject.delete([[3], [4]]) | ||
expect(new_gateway.to_a).to eq([[1], [2]]) | ||
end | ||
end | ||
|
||
describe '#update' do | ||
pending 'Design interface' do | ||
context 'with a Hash argument' do | ||
it 'updates matching tuples' do | ||
new_gateway = subject.update(id: 2) | ||
expect(new_gateway.to_a).to eq([[2]]) | ||
end | ||
end | ||
end | ||
|
||
context 'with a block' do | ||
it 'updates matching tuples' do | ||
new_gateway = subject.update { |tuple| [2] } | ||
expect(new_gateway.to_a).to eq([[2]]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
shared_context 'relation' do | ||
let(:relation) { Relation.new(header, body) } | ||
let(:body) { [[1], [2], [3]] } | ||
let(:header) { [id_attribute] } | ||
let(:id_attribute) { Attribute::Integer.new(:id) } | ||
let(:schema) { {} } | ||
let(:name) { 'users'.freeze } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe Adapter::Memory, '.new' do | ||
context 'with a schema' do | ||
subject { described_class.new(schema) } | ||
|
||
let(:schema) { {} } | ||
|
||
it { should be_instance_of(described_class) } | ||
end | ||
|
||
context 'without a schema' do | ||
subject { described_class.new } | ||
|
||
it { should be_instance_of(described_class) } | ||
end | ||
end |
Oops, something went wrong.