Module: Mongoid::Extensions::Hash
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/mongoid/extensions/hash.rb |
Overview
Adds type-casting behavior to Hash
class.
Instance Attribute Summary
-
#resizable? ⇒ true
readonly
Can the size of this object change?
Instance Method Summary
- #__consolidate__(klass) ⇒ Hash deprecated Deprecated.
-
#__evolve_object_id__ ⇒ Hash
Evolves each value in the hash to an object id if it is convertable.
-
#__mongoize_object_id__ ⇒ Hash
Mongoizes each value in the hash to an object id if it is convertable.
- #delete_id ⇒ Object deprecated Deprecated.
- #extract_id ⇒ Object deprecated Deprecated.
-
#mongoize ⇒ Hash | nil
Turn the object from the ruby type we deal with to a Mongo friendly type.
- #to_criteria ⇒ Criteria deprecated Deprecated.
Instance Attribute Details
#resizable? ⇒ true
(readonly)
Can the size of this object change?
# File 'lib/mongoid/extensions/hash.rb', line 92
def resizable? true end
Instance Method Details
#__consolidate__(klass) ⇒ Hash
Consolidate the key/values in the hash under an atomic $set. DEPRECATED. This was never intended to be a public API and the functionality will no longer be exposed once this method is eventually removed.
# File 'lib/mongoid/extensions/hash.rb', line 45
def __consolidate__(klass) Mongoid::AtomicUpdatePreparer.prepare(self, klass) end
#__evolve_object_id__ ⇒ Hash
Evolves each value in the hash to an object id if it is convertable.
# File 'lib/mongoid/extensions/hash.rb', line 16
def __evolve_object_id__ transform_values!(&:__evolve_object_id__) end
#__mongoize_object_id__ ⇒ Hash
Mongoizes each value in the hash to an object id if it is convertable.
#delete_id ⇒ Object
Deletes an id value from the hash.
# File 'lib/mongoid/extensions/hash.rb', line 57
def delete_id delete("_id") || delete(:_id) || delete("id") || delete(:id) end
#extract_id ⇒ Object
Get the id attribute from this hash, whether it’s prefixed with an underscore or is a symbol.
# File 'lib/mongoid/extensions/hash.rb', line 70
def extract_id self["_id"] || self[:_id] || self["id"] || self[:id] end
#mongoize ⇒ Hash
| nil
Turn the object from the ruby type we deal with to a Mongo friendly type.
#to_criteria ⇒ Criteria
Convert this hash to a criteria. Will iterate over each keys in the hash which must correspond to method on a criteria object. The hash must also include a “klass” key.