123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Extensions::Vector::ClassMethods

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

Instance Method Summary

Instance Method Details

#demongoize(object) ⇒ BSON::Vector | nil

Convert the object from its mongo friendly ruby type back to a ::BSON::Vector.

Examples:

Demongoize the object.

BSON::Vector.demongoize(binary)

Parameters:

  • object (Object)

    The object to demongoize.

Returns:

[ GitHub ]

  
# File 'lib/mongoid/extensions/vector.rb', line 50

def demongoize(object)
  case object
  when BSON::Binary then (object.type == :vector) ? object.as_vector : nil
  when BSON::Vector then object
  end
end

#mongoize(object) ⇒ BSON::Binary | nil

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

Examples:

Mongoize the object.

BSON::Vector.mongoize(vector)

Parameters:

  • object (Object)

    The object to Mongoize.

Returns:

[ GitHub ]

  
# File 'lib/mongoid/extensions/vector.rb', line 34

def mongoize(object)
  case object
  when BSON::Vector then BSON::Binary.from_vector(object)
  when BSON::Binary then object
  end
end