Module: Mongoid::Extensions::Binary::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#mongoize(object) ⇒ BSON::Binary | nil Also known as: demongoize

Mongoize an object of any type to how it's stored in the db.

Examples:

Mongoize the object.

BigDecimal.mongoize(123)

Parameters:

  • object (Object)

    The object to Mongoize

Returns:

  • (BSON::Binary | nil)

    A Binary representing the object or nil.



28
29
30
31
32
33
34
# File 'build/mongoid-master/lib/mongoid/extensions/binary.rb', line 28

def mongoize(object)
  return if object.nil?
  case object
  when BSON::Binary then object
  when String, Symbol then BSON::Binary.new(object.to_s)
  end
end