Module: Superstore::Persistence::ClassMethods

Defined in:
lib/superstore/persistence.rb

Instance Method Summary collapse

Instance Method Details

#_insert_record(attributes) ⇒ Object


10
11
12
13
14
# File 'lib/superstore/persistence.rb', line 10

def _insert_record(attributes)
  id = attributes.fetch(primary_key)

  adapter.insert table_name, id, serialize_attributes(attributes)
end

#_update_record(attributes, constraints) ⇒ Object


16
17
18
19
20
# File 'lib/superstore/persistence.rb', line 16

def _update_record(attributes, constraints)
  id = constraints.fetch(primary_key)

  adapter.update table_name, id, serialize_attributes(attributes)
end

#find_by_id(id) ⇒ Object


6
7
8
# File 'lib/superstore/persistence.rb', line 6

def find_by_id(id)
  find_by(id: id)
end

#serialize_attributes(attributes) ⇒ Object


22
23
24
25
26
27
28
29
# File 'lib/superstore/persistence.rb', line 22

def serialize_attributes(attributes)
  serialized = {}
  attributes.each do |attr_name, value|
    next if attr_name == primary_key
    serialized[attr_name] = attribute_types[attr_name].serialize(value)
  end
  serialized
end