Class: Paquito::ActiveRecordCoder

Inherits:
Object
  • Object
show all
Defined in:
lib/paquito/active_record_coder.rb

Defined Under Namespace

Classes: AssociationMissingError, ClassMissingError, Error, InstanceTracker

Constant Summary collapse

EMPTY_HASH =
{}.freeze

Class Method Summary collapse

Class Method Details

.dump(record) ⇒ Object



11
12
13
14
15
16
# File 'lib/paquito/active_record_coder.rb', line 11

def dump(record)
  instances = InstanceTracker.new
  serialized_associations = serialize_associations(record, instances)
  serialized_records = instances.map { |r| serialize_record(r) }
  [serialized_associations, *serialized_records]
end

.load(payload) ⇒ Object



18
19
20
21
22
23
# File 'lib/paquito/active_record_coder.rb', line 18

def load(payload)
  instances = InstanceTracker.new
  serialized_associations, *serialized_records = payload
  serialized_records.each { |attrs| instances.push(deserialize_record(*attrs)) }
  deserialize_associations(serialized_associations, instances)
end