diff options
Diffstat (limited to 'activejob/lib/active_job/serializers.rb')
-rw-r--r-- | activejob/lib/active_job/serializers.rb | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/activejob/lib/active_job/serializers.rb b/activejob/lib/active_job/serializers.rb index 9930ae0823..df66e66659 100644 --- a/activejob/lib/active_job/serializers.rb +++ b/activejob/lib/active_job/serializers.rb @@ -4,17 +4,18 @@ require "set" module ActiveJob # The <tt>ActiveJob::Serializers</tt> module is used to store a list of known serializers - # and to add new ones. It also has helpers to serialize/deserialize objects - module Serializers + # and to add new ones. It also has helpers to serialize/deserialize objects. + module Serializers # :nodoc: extend ActiveSupport::Autoload extend ActiveSupport::Concern autoload :ObjectSerializer autoload :SymbolSerializer autoload :DurationSerializer + autoload :DateTimeSerializer autoload :DateSerializer + autoload :TimeWithZoneSerializer autoload :TimeSerializer - autoload :DateTimeSerializer mattr_accessor :_additional_serializers self._additional_serializers = Set.new @@ -22,7 +23,7 @@ module ActiveJob class << self # 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. + # Raises <tt>ActiveJob::SerializationError</tt> if it can't find a proper serializer. def serialize(argument) serializer = serializers.detect { |s| s.serialize?(argument) } raise SerializationError.new("Unsupported argument type: #{argument.class.name}") unless serializer @@ -31,23 +32,23 @@ module ActiveJob # Returns deserialized object. # Will look up through all known serializers. - # If no serializers found will raise `ArgumentError` + # If no serializer found will raise <tt>ArgumentError</tt>. 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 know" unless serializer + raise ArgumentError, "Serializer #{serializer_name} is not known" unless serializer serializer.deserialize(argument) end - # Returns list of known serializers + # Returns list of known serializers. def serializers self._additional_serializers end - # Adds a new serializer to a list of known serializers + # Adds new serializers to a list of known serializers. def add_serializers(*new_serializers) self._additional_serializers += new_serializers.flatten end @@ -57,6 +58,7 @@ module ActiveJob DurationSerializer, DateTimeSerializer, DateSerializer, + TimeWithZoneSerializer, TimeSerializer end end |