aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib/active_job/serializers/duration_serializer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activejob/lib/active_job/serializers/duration_serializer.rb')
-rw-r--r--activejob/lib/active_job/serializers/duration_serializer.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/activejob/lib/active_job/serializers/duration_serializer.rb b/activejob/lib/active_job/serializers/duration_serializer.rb
new file mode 100644
index 0000000000..715fe27a5c
--- /dev/null
+++ b/activejob/lib/active_job/serializers/duration_serializer.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module ActiveJob
+ module Serializers
+ class DurationSerializer < ObjectSerializer # :nodoc:
+ def serialize(duration)
+ super("value" => duration.value, "parts" => Arguments.serialize(duration.parts))
+ end
+
+ def deserialize(hash)
+ value = hash["value"]
+ parts = Arguments.deserialize(hash["parts"])
+
+ klass.new(value, parts)
+ end
+
+ private
+
+ def klass
+ ActiveSupport::Duration
+ end
+ end
+ end
+end