Module: ActiveSupport::Messages::SerializerWithFallback

Included in:
JsonWithFallback, MarshalWithFallback, MessagePackWithFallback
Defined in:
lib/active_support/messages/serializer_with_fallback.rb

Overview

:nodoc:

Defined Under Namespace

Modules: AllowMarshal, JsonWithFallback, JsonWithFallbackAllowMarshal, MarshalWithFallback, MessagePackWithFallback, MessagePackWithFallbackAllowMarshal

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](format) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/active_support/messages/serializer_with_fallback.rb', line 9

def self.[](format)
  if format.to_s.include?("message_pack") && !defined?(ActiveSupport::MessagePack)
    require "active_support/message_pack"
  end

  SERIALIZERS.fetch(format)
end

Instance Method Details

#load(dumped) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_support/messages/serializer_with_fallback.rb', line 17

def load(dumped)
  format = detect_format(dumped)

  if format == self.format
    _load(dumped)
  elsif format && fallback?(format)
    payload = { serializer: SERIALIZERS.key(self), fallback: format, serialized: dumped }
    ActiveSupport::Notifications.instrument("message_serializer_fallback.active_support", payload) do
      payload[:deserialized] = SERIALIZERS[format]._load(dumped)
    end
  else
    raise "Unsupported serialization format"
  end
end