Methods

Instance Public methods

deserialize(arguments)

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.

📝 Source code
# File activejob/lib/active_job/arguments.rb, line 78
    def deserialize(arguments)
      arguments.map { |argument| deserialize_argument(argument) }
    rescue
      raise DeserializationError
    end
🔎 See on GitHub

serialize(argument)

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.

📝 Source code
# File activejob/lib/active_job/arguments.rb, line 34
    def serialize(argument)
      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(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
🔎 See on GitHub