123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Defined in: lib/mongoid/extensions/binary.rb

Instance Method Summary

Instance Method Details

#demongoize(object)

Alias for #mongoize.

[ GitHub ]

  
# File 'lib/mongoid/extensions/binary.rb', line 38

alias :demongoize :mongoize

#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.

[ GitHub ]

  
# 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