Module: Persisto::Store

Defined in:
lib/persisto/store.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#adaptorObject (readonly)

Returns the value of attribute adaptor.



19
20
21
# File 'lib/persisto/store.rb', line 19

def adaptor
  @adaptor
end

#mapperObject (readonly)

Returns the value of attribute mapper.



19
20
21
# File 'lib/persisto/store.rb', line 19

def mapper
  @mapper
end

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/persisto/store.rb', line 5

def self.included(base)
	base.extend ClassMethods
end

Instance Method Details

#all(query_object) ⇒ Object



26
27
28
29
# 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) ⇒ Object



51
52
53
54
# File 'lib/persisto/store.rb', line 51

def delete query_object
	assign_to_query_object(query_object)
	adaptor.delete(query_object)
end

#dump(entity) ⇒ Object



60
61
62
# File 'lib/persisto/store.rb', line 60

def dump entity
	mapper.dump_store(self.class.table_name, entity)
end

#first(query_object) ⇒ Object



31
32
33
34
# 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) ⇒ Object



36
37
38
39
# 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

#initialize(adaptor, mapper) ⇒ Object



21
22
23
24
# File 'lib/persisto/store.rb', line 21

def initialize adaptor, mapper
	@adaptor = adaptor
	@mapper = mapper
end

#insert(query_object) ⇒ Object



41
42
43
44
# File 'lib/persisto/store.rb', line 41

def insert query_object
	assign_to_query_object(query_object)
	adaptor.insert(query_object)
end

#parse(data) ⇒ Object



64
65
66
# File 'lib/persisto/store.rb', line 64

def parse data
	[*data].map{|d| mapper.parse(d)}
end

#transaction(&block) ⇒ Object



56
57
58
# File 'lib/persisto/store.rb', line 56

def transaction &block
	adaptor.transaction &block
end

#update(query_object) ⇒ Object



46
47
48
49
# File 'lib/persisto/store.rb', line 46

def update query_object
	assign_to_query_object(query_object)
	adaptor.update(query_object)
end