Class: Storing::Store

Inherits:
AbstractStore show all
Defined in:
lib/storing/store.rb

Defined Under Namespace

Classes: Entity

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adaptor) ⇒ Store

Returns a new instance of Store.



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

def initialize adaptor
	@adaptor = adaptor
end

Instance Attribute Details

#adaptorObject (readonly)

Returns the value of attribute adaptor.



50
51
52
# File 'lib/storing/store.rb', line 50

def adaptor
  @adaptor
end

Class Method Details

.primary_keyObject



38
39
40
# File 'lib/storing/store.rb', line 38

def self.primary_key
	@primary_key || raise(MissingPrimaryKey, 'primary key not assigned')
end

.set_primary_key(val) ⇒ Object



34
35
36
# File 'lib/storing/store.rb', line 34

def self.set_primary_key val
	@primary_key = val
end

.set_table_name(val) ⇒ Object



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

def self.set_table_name val
	@table_name = val
end

.table_nameObject



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

def self.table_name
	@table_name || raise(MissingTableName, 'table name not assigned')
end

Instance Method Details

#delete(entity_hash = {}) ⇒ Object



73
74
75
76
# File 'lib/storing/store.rb', line 73

def delete entity_hash={}
	entity = new_entity(entity_hash)
	adaptor.delete(table_name, entity.primary_key_hash)
end

#insert(entity_hash = {}) ⇒ Object



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

def insert entity_hash={}
	adaptor.insert(table_name, entity_hash)
end

#primary_keyObject



86
87
88
# File 'lib/storing/store.rb', line 86

def primary_key
	self.class.primary_key
end

#query(query_object) ⇒ Object



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

def query query_object
	adaptor.query(query_object)
end

#select(conditions = {}) ⇒ Object



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

def select conditions={}
	adaptor.select(table_name, conditions)
end

#table_nameObject



82
83
84
# File 'lib/storing/store.rb', line 82

def table_name
	self.class.table_name
end

#transactionObject



78
79
80
# File 'lib/storing/store.rb', line 78

def transaction
	adaptor.transaction
end

#update(entity_hash = {}) ⇒ Object



68
69
70
71
# File 'lib/storing/store.rb', line 68

def update entity_hash={}
	entity = new_entity(entity_hash)
	adaptor.update(table_name, entity.params, entity.primary_key_hash)
end