Class: Paquito::Types::ActiveRecordPacker

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

Constant Summary collapse

FACTORY =
factory
VALID_CLASSES =
core_types + ext_types

Class Method Summary collapse

Class Method Details

.dump(value) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/paquito/types/active_record_packer.rb', line 25

def self.dump(value)
  coded = ActiveRecordCoder.dump(value)
  FACTORY.dump(coded)
rescue NoMethodError, PackError => e
  raise unless PackError === e || e.name == :to_msgpack

  class_name = value.class.name
  receiver_name = e.receiver.class.name
  error_attrs = coded[1][1].select { |_, attr_value| VALID_CLASSES.exclude?(attr_value.class) }

  Rails.logger.warn(<<~LOG.squish)
    [MessagePackCodecTypes]
    Failed to encode record with ActiveRecordCoder
    class=#{class_name}
    error_class=#{receiver_name}
    error_attrs=#{error_attrs.keys.join(", ")}
  LOG

  raise PackError.new("failed to pack ActiveRecord object", e.receiver)
end

.load(value) ⇒ Object



46
47
48
# File 'lib/paquito/types/active_record_packer.rb', line 46

def self.load(value)
  ActiveRecordCoder.load(FACTORY.load(value))
end