Module: ActiveSupport::Messages::SerializerWithFallback
Do not use. This module is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | activesupport/lib/active_support/messages/serializer_with_fallback.rb |
Constant Summary
-
SERIALIZERS =
# File 'activesupport/lib/active_support/messages/serializer_with_fallback.rb', line 149{ marshal: MarshalWithFallback, json: JsonWithFallback, json_allow_marshal: JsonWithFallbackAllowMarshal, message_pack: MessagePackWithFallback, message_pack_allow_marshal: MessagePackWithFallbackAllowMarshal, }
Class Method Summary
Instance Method Summary
- #load(dumped)
- #detect_format(dumped) private
- #fallback?(format) ⇒ Boolean private
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) : when MarshalWithFallback.dumped?(dumped) :marshal when JsonWithFallback.dumped?(dumped) :json end end
#fallback?(format) ⇒ Boolean
(private)
# 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