Class: Mongoid::Railties::ActiveJobSerializers::BsonObjectIdSerializer
- Inherits:
-
ActiveJob::Serializers::ObjectSerializer
- Object
- ActiveJob::Serializers::ObjectSerializer
- Mongoid::Railties::ActiveJobSerializers::BsonObjectIdSerializer
- 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
-
#deserialize(string) ⇒ BSON::ObjectId
Deserializes the argument back into a BSON::ObjectId.
-
#serialize(object) ⇒ Object
Serializes the argument to be passed to the job.
-
#serialize?(argument) ⇒ Boolean
Returns whether the argument can be serialized by this serializer.
Instance Method Details
#deserialize(string) ⇒ BSON::ObjectId
Deserializes the argument back into a BSON::ObjectId.
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.
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.
17 18 19 |
# File 'lib/mongoid/railties/bson_object_id_serializer.rb', line 17 def serialize?(argument) argument.is_a?(BSON::ObjectId) end |