aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_job/parameters.rb
blob: 5f814f846d64a93c3732e6a9eec636adb62d8f5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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|
        raise "Unsupported parameter type: #{param.class.name}" unless param.respond_to?(:global_id) || TYPE_WHITELIST.include?(param.class)
        param.try(:global_id) || param
      end
    end

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