123456789_123456789_123456789_123456789_123456789_

Class: ActiveJob::Serializers::DurationSerializer

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveJob::Serializers::ObjectSerializer
Defined in: activejob/lib/active_job/serializers/duration_serializer.rb

Instance Attribute Summary

ObjectSerializer - Inherited

#deserialize

Deserializes an argument from a JSON primitive type.

#serialize?

Determines if an argument should be serialized by a serializer.

::Singleton - Included

#duplicable?

::Singleton instances are not duplicable:

Instance Method Summary

ObjectSerializer - Inherited

#serialize

Serializes an argument to a JSON primitive type.

#klass

The class of the object that will be serialized.

Instance Method Details

#deserialize(hash)

[ GitHub ]

  
# File 'activejob/lib/active_job/serializers/duration_serializer.rb', line 12

def deserialize(hash)
  value = hash["value"]
  parts = Arguments.deserialize(hash["parts"])
  # `parts` is originally a hash, but will have been flattened to an array by Arguments.serialize
  klass.new(value, parts.to_h)
end

#klass (private)

[ GitHub ]

  
# File 'activejob/lib/active_job/serializers/duration_serializer.rb', line 20

def klass
  ActiveSupport::Duration
end

#serialize(duration)

[ GitHub ]

  
# File 'activejob/lib/active_job/serializers/duration_serializer.rb', line 6

def serialize(duration)
  # Ideally duration.parts would be wrapped in an array before passing to Arguments.serialize,
  # but we continue passing the bare hash for backwards compatibility:
  super("value" => duration.value, "parts" => Arguments.serialize(duration.parts))
end