Module: RUUID::Mongoid::Extensions::UUID::ClassMethods

Defined in:
lib/ruuid/mongoid/extensions/uuid.rb

Instance Method Summary collapse

Instance Method Details

#demongoize(object) ⇒ RUUID::UUID

Convert the object from its Mongo-friendly Ruby type to this type.

Parameters:

  • object (BSON::Binary)

    The object to demongoize.

Returns:

  • (RUUID::UUID)

    The demongoized UUID.



24
25
26
27
28
29
30
31
32
33
# File 'lib/ruuid/mongoid/extensions/uuid.rb', line 24

def demongoize(object)
  case object
  when BSON::Binary
    new(object.data)
  when ::String
    parse(object)
  else
    object
  end
end

#mongoize(object) ⇒ BSON::Binary Also known as: evolve

Turn the object from the Ruby type we deal with to a Mongo-friendly type.

Parameters:

  • object (RUUID::UUID)

    The object to mongoize.

Returns:

  • (BSON::Binary)

    The mongoized object.



43
44
45
46
# File 'lib/ruuid/mongoid/extensions/uuid.rb', line 43

def mongoize(object)
  return object if object.nil?
  parse(object).mongoize rescue object.mongoize
end