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

Defined in:
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.



31
32
33
34
35
36
37
# File 'lib/mongoid/extensions/binary.rb', line 31

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