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

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

Instance Method Summary collapse

Instance Method Details

#__mongoize_fk__(association, object) ⇒ Array

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

Examples:

Mongoize the object.

Array.__mongoize_fk__(constraint, object)

Parameters:

  • association (Association)

    The association metadata.

  • object (Object)

    The object to convert.

Returns:

  • (Array)

    The array of ids.

Since:

  • 3.0.0



136
137
138
139
140
141
142
# File 'lib/mongoid/extensions/array.rb', line 136

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

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)

    The object mongoized.

Since:

  • 3.0.0



155
156
157
158
159
160
161
# File 'lib/mongoid/extensions/array.rb', line 155

def mongoize(object)
  if object.is_a?(::Array)
    evolve(object).collect{ |obj| obj.class.mongoize(obj) }
  else
    evolve(object)
  end
end

#resizable?true

Is the object's size changable?

Examples:

Is the object resizable?

Array.resizable?

Returns:

  • (true)

    true.

Since:

  • 3.0.0



171
172
173
# File 'lib/mongoid/extensions/array.rb', line 171

def resizable?
  true
end