module Persisto::Store

Attributes

adaptor[R]
mapper[R]

Public Class Methods

included(base) click to toggle source
# File lib/persisto/store.rb, line 5
def self.included(base)
        base.extend ClassMethods
end
new(adaptor, mapper) click to toggle source
# File lib/persisto/store.rb, line 21
def initialize adaptor, mapper
        @adaptor = adaptor
        @mapper = mapper
end

Public Instance Methods

all(query_object) click to toggle source
# File lib/persisto/store.rb, line 26
def all query_object
        assign_to_query_object(query_object)
        parse(adaptor.select(query_object))
end
delete(query_object) click to toggle source
# File lib/persisto/store.rb, line 51
def delete query_object
        assign_to_query_object(query_object)
        adaptor.delete(query_object)
end
dump(entity) click to toggle source
# File lib/persisto/store.rb, line 60
def dump entity
        mapper.dump_store(self.class.table_name, entity)
end
first(query_object) click to toggle source
# File lib/persisto/store.rb, line 31
def first query_object
        assign_to_query_object(query_object)
        parse(adaptor.select(query_object)).first
end
first!(query_object) click to toggle source
# File lib/persisto/store.rb, line 36
def first! query_object
        assign_to_query_object(query_object)
        parse(adaptor.select(query_object)).first || raise(EntityNotFound, "#{query_object.class.name}: entity not found")
end
insert(query_object) click to toggle source
# File lib/persisto/store.rb, line 41
def insert query_object
        assign_to_query_object(query_object)
        adaptor.insert(query_object)
end
parse(data) click to toggle source
# File lib/persisto/store.rb, line 64
def parse data
        [*data].map{|d| mapper.parse(d)}
end
transaction(&block) click to toggle source
# File lib/persisto/store.rb, line 56
def transaction &block
        adaptor.transaction &block
end
update(query_object) click to toggle source
# File lib/persisto/store.rb, line 46
def update query_object
        assign_to_query_object(query_object)
        adaptor.update(query_object)
end

Private Instance Methods

assign_to_query_object(query_object) click to toggle source
# File lib/persisto/store.rb, line 70
def assign_to_query_object query_object
        query_object.store = self
end