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

Defined in:
lib/mongoid/extensions/vector.rb

Instance Method Summary collapse

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:

  • (BSON::Vector | nil)

    The vector or nil.



50
51
52
53
54
55
# 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:

  • (BSON::Binary | nil)

    A vector binary or nil.



34
35
36
37
38
39
# 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