Module: ActiveJob::Serializers
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- activejob/lib/active_job/serializers.rb,
activejob/lib/active_job/serializers/date_serializer.rb,
activejob/lib/active_job/serializers/time_serializer.rb,
activejob/lib/active_job/serializers/range_serializer.rb,
activejob/lib/active_job/serializers/module_serializer.rb,
activejob/lib/active_job/serializers/object_serializer.rb,
activejob/lib/active_job/serializers/symbol_serializer.rb,
activejob/lib/active_job/serializers/duration_serializer.rb,
activejob/lib/active_job/serializers/date_time_serializer.rb,
activejob/lib/active_job/serializers/big_decimal_serializer.rb,
activejob/lib/active_job/serializers/time_object_serializer.rb,
activejob/lib/active_job/serializers/time_with_zone_serializer.rb
Overview
Active Job Serializers
The ActiveJob::Serializers
module is used to store a list of known serializers and to add new ones. It also has helpers to serialize/deserialize objects.
Defined Under Namespace
Classes: BigDecimalSerializer, DateSerializer, DateTimeSerializer, DurationSerializer, ModuleSerializer, ObjectSerializer, RangeSerializer, SymbolSerializer, TimeObjectSerializer, TimeSerializer, TimeWithZoneSerializer
Class Method Summary collapse
-
.add_serializers(*new_serializers) ⇒ Object
Adds new serializers to a list of known serializers.
-
.deserialize(argument) ⇒ Object
Returns deserialized object.
-
.serialize(argument) ⇒ Object
Returns serialized representative of the passed object.
-
.serializers ⇒ Object
Returns list of known serializers.
Methods included from ActiveSupport::Autoload
autoload, autoload_at, autoload_under, eager_autoload, eager_load!, extended
Class Method Details
.add_serializers(*new_serializers) ⇒ Object
Adds new serializers to a list of known serializers.
57 58 59 |
# File 'activejob/lib/active_job/serializers.rb', line 57 def add_serializers(*new_serializers) self._additional_serializers += new_serializers.flatten end |
.deserialize(argument) ⇒ Object
Returns deserialized object. Will look up through all known serializers. If no serializer found will raise ArgumentError
.
41 42 43 44 45 46 47 48 49 |
# File 'activejob/lib/active_job/serializers.rb', line 41 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) ⇒ Object
Returns serialized representative of the passed object. Will look up through all known serializers. Raises ActiveJob::SerializationError
if it can’t find a proper serializer.
32 33 34 35 36 |
# File 'activejob/lib/active_job/serializers.rb', line 32 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 ⇒ Object
Returns list of known serializers.
52 53 54 |
# File 'activejob/lib/active_job/serializers.rb', line 52 def serializers self._additional_serializers end |