123456789_123456789_123456789_123456789_123456789_

Module: ActiveSupport::Messages::SerializerWithFallback

Do not use. This module is for internal use only.

Constant Summary

Class Method Summary

Instance Method Summary

Class Method Details

.[](format)

[ GitHub ]

  
# File 'activesupport/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

#detect_format(dumped) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/serializer_with_fallback.rb', line 33

def detect_format(dumped)
  case
  when MessagePackWithFallback.dumped?(dumped)
    :message_pack
  when MarshalWithFallback.dumped?(dumped)
    :marshal
  when JsonWithFallback.dumped?(dumped)
    :json
  end
end

#fallback?(format) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/serializer_with_fallback.rb', line 44

def fallback?(format)
  format != :marshal
end

#load(dumped)

[ GitHub ]

  
# File 'activesupport/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