2018-02-09 16:50:57 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-09 15:45:11 -05:00
|
|
|
module ActiveJob
|
|
|
|
module Serializers
|
2018-02-09 16:32:35 -05:00
|
|
|
class DurationSerializer < ObjectSerializer # :nodoc:
|
|
|
|
def serialize(duration)
|
2018-02-12 14:16:41 -05:00
|
|
|
super("value" => duration.value, "parts" => Arguments.serialize(duration.parts))
|
2018-02-09 16:32:35 -05:00
|
|
|
end
|
2018-02-09 15:45:11 -05:00
|
|
|
|
2018-02-09 16:32:35 -05:00
|
|
|
def deserialize(hash)
|
|
|
|
value = hash["value"]
|
2018-02-12 14:16:41 -05:00
|
|
|
parts = Arguments.deserialize(hash["parts"])
|
2018-02-09 15:45:11 -05:00
|
|
|
|
2018-02-09 16:32:35 -05:00
|
|
|
klass.new(value, parts)
|
|
|
|
end
|
2018-02-09 15:45:11 -05:00
|
|
|
|
2018-02-09 16:32:35 -05:00
|
|
|
private
|
2018-02-09 15:45:11 -05:00
|
|
|
def klass
|
|
|
|
ActiveSupport::Duration
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|