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.
42 43 44 |
# File 'lib/mongoid/extensions/hash.rb', line 42 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.
13 14 15 |
# File 'lib/mongoid/extensions/hash.rb', line 13 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.
23 24 25 26 27 28 29 |
# File 'lib/mongoid/extensions/hash.rb', line 23 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.
54 55 56 |
# File 'lib/mongoid/extensions/hash.rb', line 54 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.
67 68 69 |
# File 'lib/mongoid/extensions/hash.rb', line 67 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.
79 80 81 |
# File 'lib/mongoid/extensions/hash.rb', line 79 def mongoize ::Hash.mongoize(self) end |
#resizable? ⇒ true
Can the size of this object change?
89 90 91 |
# File 'lib/mongoid/extensions/hash.rb', line 89 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.
102 103 104 |
# File 'lib/mongoid/extensions/hash.rb', line 102 def to_criteria Criteria.from_hash(self) end |