Module: Mongoid::Extensions::Hash::ClassMethods

Defined in:
build/mongoid-master/lib/mongoid/extensions/hash.rb

Instance Method Summary collapse

Instance Method Details

#mongoize(object) ⇒ Hash | nil

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

Examples:

Mongoize the object.

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

Parameters:

  • object (Object)

    The object to mongoize.

Returns:

  • (Hash | nil)

    The object mongoized or nil.



221
222
223
224
225
226
227
228
229
# File 'build/mongoid-master/lib/mongoid/extensions/hash.rb', line 221

def mongoize(object)
  return if object.nil?
  if object.is_a?(Hash)
    # Need to use transform_values! which maintains the BSON::Document
    # instead of transform_values which always returns a hash. To do this,
    # we first need to dup the hash.
    object.dup.transform_values!(&:mongoize)
  end
end

#resizable?true

Can the size of this object change?

Examples:

Is the hash resizable?

{}.resizable?

Returns:

  • (true)

    true.



237
238
239
# File 'build/mongoid-master/lib/mongoid/extensions/hash.rb', line 237

def resizable?
  true
end