Class: Mongoid::Railties::ActiveJobSerializers::BsonObjectIdSerializer

Inherits:
ActiveJob::Serializers::ObjectSerializer
  • Object
show all
Defined in:
lib/mongoid/railties/bson_object_id_serializer.rb

Overview

This class provides serialization and deserialization of BSON::ObjectId for ActiveJob.

It is important that this class is loaded only when Rails is available since it depends on Rails’ ActiveJob::Serializers::ObjectSerializer.

Instance Method Summary collapse

Instance Method Details

#deserialize(string) ⇒ BSON::ObjectId

Deserializes the argument back into a BSON::ObjectId.

Parameters:

  • string (String)

    The string to deserialize.

Returns:

  • (BSON::ObjectId)

    The deserialized object.



33
34
35
# File 'lib/mongoid/railties/bson_object_id_serializer.rb', line 33

def deserialize(string)
  BSON::ObjectId.from_string(string)
end

#serialize(object) ⇒ Object

Serializes the argument to be passed to the job.

Parameters:

  • object (BSON::ObjectId)

    The object to serialize.



24
25
26
# File 'lib/mongoid/railties/bson_object_id_serializer.rb', line 24

def serialize(object)
  object.to_s
end

#serialize?(argument) ⇒ Boolean

Returns whether the argument can be serialized by this serializer.

@param [ Object ] argument The argument to check.

@return [ true | false ] Whether the argument can be serialized.

Returns:



17
18
19
# File 'lib/mongoid/railties/bson_object_id_serializer.rb', line 17

def serialize?(argument)
  argument.is_a?(BSON::ObjectId)
end