module Superstore::Persistence::ClassMethods
Public Instance Methods
_insert_record(attributes)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/superstore/persistence.rb, line 6 def find_by_id(id) find_by(id: id) end
instantiate(attributes, column_types = {}, &block)
click to toggle source
Calls superclass method
# File lib/superstore/persistence.rb, line 32 def instantiate(attributes, column_types = {}, &block) if attributes[superstore_column].is_a?(String) attributes = JSON.parse(attributes[superstore_column]).merge('id' => attributes['id']) end super(attributes, column_types, &block) end
instantiate_instance_of(klass, attributes, column_types = {}, &block)
click to toggle source
Calls superclass method
# File lib/superstore/persistence.rb, line 23 def instantiate_instance_of(klass, attributes, column_types = {}, &block) if attributes[superstore_column].is_a?(String) attributes = JSON.parse(attributes[superstore_column]).merge('id' => attributes['id']) end super(klass, attributes, column_types, &block) end
serialize_attributes(attributes)
click to toggle source
# File lib/superstore/persistence.rb, line 41 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
Private Instance Methods
adapter()
click to toggle source
# File lib/superstore/persistence.rb, line 52 def adapter @adapter ||= Superstore::Adapters::JsonbAdapter.new end