Module: Mongoid::Extensions::Hash
- Defined in:
- lib/mongoid/extensions/hash.rb
Overview
Adds type-casting behavior to Hash class.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #__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.
-
#resizable? ⇒ true
Can the size of this object change?.
- #to_criteria ⇒ Criteria deprecated Deprecated.
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.
45 46 47 |
# 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.
16 17 18 |
# 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.
26 27 28 29 30 31 32 |
# File 'lib/mongoid/extensions/hash.rb', line 26 def __mongoize_object_id__ if id = self['$oid'] BSON::ObjectId.from_string(id) else transform_values!(&:__mongoize_object_id__) end end |
#delete_id ⇒ Object
Deletes an id value from the hash.
57 58 59 |
# 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.
70 71 72 |
# 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.
82 83 84 |
# File 'lib/mongoid/extensions/hash.rb', line 82 def mongoize ::Hash.mongoize(self) end |
#resizable? ⇒ true
Can the size of this object change?
92 93 94 |
# File 'lib/mongoid/extensions/hash.rb', line 92 def resizable? true end |
#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.
105 106 107 |
# File 'lib/mongoid/extensions/hash.rb', line 105 def to_criteria Criteria.from_hash(self) end |