aboutsummaryrefslogblamecommitdiffstats
path: root/activejob/lib/active_job/serializers/duration_serializer.rb
blob: b35eaf5f607e55a3a9135eb85f3755f28fe9e7ab (plain) (tree)
1
2
3
4
5
6
7
8
9

                             

                    

                                                         
                                                                                        
         
 

                             
                                                    
 

                               
 
             


                                 


       
# 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