Module: ActiveJob::Serializers
Do not use. This module is for internal use only.
Overview
The Serializers
module is used to store a list of known serializers and to add new ones. It also has helpers to serialize/deserialize objects.
Class Attribute Summary
- ._additional_serializers (also: #_additional_serializers) rw
Class Method Summary
-
.add_serializers(*new_serializers)
Adds new serializers to a list of known serializers.
-
.deserialize(argument)
Returns deserialized object.
-
.serialize(argument)
Returns serialized representative of the passed object.
-
.serializers
Returns list of known serializers.
::ActiveSupport::Autoload
- Extended
Instance Attribute Summary
Class Attribute Details
._additional_serializers (rw) Also known as: #_additional_serializers
[ GitHub ]# File 'activejob/lib/active_job/serializers.rb', line 23
mattr_accessor :_additional_serializers
Class Method Details
.add_serializers(*new_serializers)
Adds new serializers to a list of known serializers.
# File 'activejob/lib/active_job/serializers.rb', line 55
def add_serializers(*new_serializers) self._additional_serializers += new_serializers.flatten end
.deserialize(argument)
Returns deserialized object. Will look up through all known serializers. If no serializer found will raise ArgumentError
.
# File 'activejob/lib/active_job/serializers.rb', line 39
def deserialize(argument) serializer_name = argument[Arguments::OBJECT_SERIALIZER_KEY] raise ArgumentError, "Serializer name is not present in the argument: #{argument.inspect}" unless serializer_name serializer = serializer_name.safe_constantize raise ArgumentError, "Serializer #{serializer_name} is not known" unless serializer serializer.deserialize(argument) end
.serialize(argument)
Returns serialized representative of the passed object. Will look up through all known serializers. Raises SerializationError
if it can’t find a proper serializer.
# File 'activejob/lib/active_job/serializers.rb', line 30
def serialize(argument) serializer = serializers.detect { |s| s.serialize?(argument) } raise SerializationError.new("Unsupported argument type: #{argument.class.name}") unless serializer serializer.serialize(argument) end
.serializers
Returns list of known serializers.
# File 'activejob/lib/active_job/serializers.rb', line 50
def serializers self._additional_serializers end
Instance Attribute Details
#_additional_serializers (rw)
[ GitHub ]# File 'activejob/lib/active_job/serializers.rb', line 23
mattr_accessor :_additional_serializers