Module: Mongoid::Extensions::Object::ClassMethods

Defined in:
build/mongoid-master/lib/mongoid/extensions/object.rb

Instance Method Summary collapse

Instance Method Details

#__mongoize_fk__(association, object) ⇒ Object

Convert the provided object to a foreign key, given the metadata key contstraint.

Examples:

Convert the object to a fk.

Object.__mongoize_fk__(association, object)

Parameters:

  • association (Association)

    The association metadata.

  • object (Object)

    The object to convert.

Returns:

  • (Object)

    The converted object.

Since:

  • 3.0.0



248
249
250
251
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 248

def __mongoize_fk__(association, object)
  return nil if !object || object == ""
  association.convert_to_foreign_key(object)
end

#demongoize(object) ⇒ Object

Convert the object from its mongo friendly ruby type to this type.

Examples:

Demongoize the object.

Object.demongoize(object)

Parameters:

  • object (Object)

    The object to demongoize.

Returns:

Since:

  • 3.0.0



263
264
265
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 263

def demongoize(object)
  object
end

#mongoize(object) ⇒ Object

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

Examples:

Mongoize the object.

Object.mongoize("123.11")

Parameters:

  • object (Object)

    The object to mongoize.

Returns:

  • (Object)

    The object mongoized.

Since:

  • 3.0.0



278
279
280
# File 'build/mongoid-master/lib/mongoid/extensions/object.rb', line 278

def mongoize(object)
  object.mongoize
end