Module: ActiveJob::Arguments
Instance Method Summary collapse
-
#deserialize(arguments) ⇒ Object
Deserializes a set of arguments.
-
#serialize(arguments) ⇒ Object
Serializes a set of arguments.
-
#serialize_argument(argument) ⇒ Object
:nodoc:.
Instance Method Details
#deserialize(arguments) ⇒ Object
Deserializes a set of arguments. Intrinsic types that can safely be deserialized without mutation are returned as-is. Arrays/Hashes are deserialized element by element. All other types are deserialized using GlobalID.
82 83 84 85 86 |
# File 'lib/active_job/arguments.rb', line 82 def deserialize(arguments) arguments.map { |argument| deserialize_argument(argument) } rescue raise DeserializationError end |
#serialize(arguments) ⇒ Object
Serializes a set of arguments. Intrinsic types that can safely be serialized without mutation are returned as-is. Arrays/Hashes are serialized element by element. All other types are serialized using GlobalID.
34 35 36 |
# File 'lib/active_job/arguments.rb', line 34 def serialize(arguments) arguments.map { |argument| serialize_argument(argument) } end |
#serialize_argument(argument) ⇒ Object
:nodoc:
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/active_job/arguments.rb', line 38 def serialize_argument(argument) # :nodoc: case argument when nil, true, false, Integer, Float # Types that can hardly be subclassed argument when String if argument.class == String argument else begin Serializers.serialize(argument) rescue SerializationError argument end end when Symbol { OBJECT_SERIALIZER_KEY => "ActiveJob::Serializers::SymbolSerializer", "value" => argument.name } 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.keys symbol_keys.select! { |k| k.is_a?(Symbol) } symbol_keys.map!(&:name) aj_hash_key = if Hash.ruby2_keywords_hash?(argument) RUBY2_KEYWORDS_KEY else SYMBOL_KEYS_KEY end result = serialize_hash(argument) result[aj_hash_key] = symbol_keys result else Serializers.serialize(argument) end end |