aboutsummaryrefslogblamecommitdiffstats
path: root/lib/active_job/parameters.rb
blob: 955fd887d7b29e2078f024798b1f6f55b1018299 (plain) (tree)
1
2
3
4
5
6
7
8
9




                                            
                                                                                                    
 
                              
                               






                                                                 
         
       
 




                                                                                  
require 'active_model/global_locator'
require 'active_support/core_ext/object/try'

module ActiveJob
  class Parameters
    TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Hash, Array, Bignum ]

    def self.serialize(params)
      params.collect do |param|
        if param.respond_to?(:global_id)
          param.global_id
        elsif TYPE_WHITELIST.include?(param.class)
          param
        else
          raise "Unsupported parameter type: #{param.class.name}"
        end
      end
    end

    def self.deserialize(params)
      params.collect { |param| ActiveModel::GlobalLocator.locate(param) || param }
    end
  end
end