123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Extensions::Array::ClassMethods

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

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#resizable?true (readonly)

Returns whether the object’s size can be changed.

Examples:

Is the object resizable?

Array.resizable?

Returns:

  • (true)

    true.

[ GitHub ]

  
# File 'lib/mongoid/extensions/array.rb', line 150

def resizable?
  true
end

Instance Method Details

#__mongoize_fk__(association, object) ⇒ Array

Deprecated.

Convert the provided object to a proper array of foreign keys.

Examples:

Mongoize the object.

Array.__mongoize_fk__(constraint, object)

Parameters:

Returns:

  • (Array)

    The array of ids.

[ GitHub ]

  
# File 'lib/mongoid/extensions/array.rb', line 118

def __mongoize_fk__(association, object)
  if object.resizable?
    object.blank? ? object : association.convert_to_foreign_key(object)
  else
    object.blank? ? [] : association.convert_to_foreign_key(Array(object))
  end
end

#mongoize(object) ⇒ Array | nil

Turn the object from the ruby type we deal with to a Mongo friendly type.

Examples:

Mongoize the object.

Array.mongoize([ 1, 2, 3 ])

Parameters:

  • object (Object)

    The object to mongoize.

Returns:

  • (Array | nil)

    The object mongoized or nil.

[ GitHub ]

  
# File 'lib/mongoid/extensions/array.rb', line 136

def mongoize(object)
  return if object.nil?
  case object
  when ::Array, ::Set
    object.map(&:mongoize)
  end
end