Module: Mongoid::Extensions::Hash

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary (collapse)

Instance Method Details

- (Hash) __evolve_object_id__

Evolves each value in the hash to an object id if it is convertable.

Examples:

Convert the hash values.

{ field: id }.__evolve_object_id__

Returns:

  • (Hash)

    The converted hash.

Since:

  • 3.0.0



14
15
16
# File 'lib/mongoid/extensions/hash.rb', line 14

def __evolve_object_id__
  update_values(&:__evolve_object_id__)
end

- (Object) extract_id

Get the id attribute from this hash, whether it's prefixed with an underscore or is a symbol.

Examples:

Extract the id.

{ :_id => 1 }.extract_id

Returns:

  • (Object)

    The value of the id.

Since:

  • 2.3.2



27
28
29
# File 'lib/mongoid/extensions/hash.rb', line 27

def extract_id
  self["id"] || self["_id"] || self[:id] || self[:_id]
end

- (Hash) mongoize

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

Examples:

Mongoize the object.

object.mongoize

Returns:

  • (Hash)

    The object.

Since:

  • 3.0.0



40
41
42
# File 'lib/mongoid/extensions/hash.rb', line 40

def mongoize
  ::Hash.mongoize(self)
end

- (true) resizable?

Can the size of this object change?

Examples:

Is the hash resizable?

{}.resizable?

Returns:

  • (true)

    true.

Since:

  • 3.0.0



52
53
54
# File 'lib/mongoid/extensions/hash.rb', line 52

def resizable?
  true
end