Module: ActiveRecord::MessagePack::Extensions

Extended by:
Extensions
Included in:
Extensions
Defined in:
lib/active_record/message_pack.rb

Instance Method Summary collapse

Instance Method Details

#install(registry) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/active_record/message_pack.rb', line 25

def install(registry)
  registry.register_type 119, ActiveModel::Type::Binary::Data,
    packer: :to_s,
    unpacker: :new

  registry.register_type 120, ActiveRecord::Base,
    packer: method(:write_record),
    unpacker: method(:read_record),
    recursive: true
end

#read_record(unpacker) ⇒ Object



40
41
42
# File 'lib/active_record/message_pack.rb', line 40

def read_record(unpacker)
  ActiveRecord::MessagePack.load(unpacker.read)
end

#write_record(record, packer) ⇒ Object



36
37
38
# File 'lib/active_record/message_pack.rb', line 36

def write_record(record, packer)
  packer.write(ActiveRecord::MessagePack.dump(record))
end