Module: ActiveJob::Arguments

Defined in:
lib/rails_6_polyfills/activejob/serializers.rb

Constant Summary collapse

OBJECT_SERIALIZER_KEY =

:nodoc:

"_aj_serialized"

Instance Method Summary collapse

Instance Method Details

#custom_serialized?(hash) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/rails_6_polyfills/activejob/serializers.rb', line 53

def custom_serialized?(hash)
  hash.key?(OBJECT_SERIALIZER_KEY)
end

#deserialize_argument(argument) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rails_6_polyfills/activejob/serializers.rb', line 32

def deserialize_argument(argument)
  case argument
  when String
    argument
  when *TYPE_WHITELIST
    argument
  when Array
    argument.map { |arg| deserialize_argument(arg) }
  when Hash
    if serialized_global_id?(argument)
      deserialize_global_id argument
    elsif custom_serialized?(argument)
      Serializers.deserialize(argument)
    else
      deserialize_hash(argument)
    end
  else
    raise ArgumentError, "Can only deserialize primitive arguments: #{argument.inspect}"
  end
end

#serialize_argument(argument) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rails_6_polyfills/activejob/serializers.rb', line 10

def serialize_argument(argument)
  case argument
  when *TYPE_WHITELIST
    argument
  when GlobalID::Identification
    convert_to_global_id_hash(argument)
  when Array
    argument.map { |arg| serialize_argument(arg) }
  when ActiveSupport::HashWithIndifferentAccess
    serialize_indifferent_hash(argument)
  when Hash
    symbol_keys = argument.each_key.grep(Symbol).map(&:to_s)
    result = serialize_hash(argument)
    result[SYMBOL_KEYS_KEY] = symbol_keys
    result
  when ->(arg) { arg.respond_to?(:permitted?) }
    serialize_indifferent_hash(argument.to_h)
  else # Add Rails 6 support for Serializers
    Serializers.serialize(argument)
  end
end