Module: Mongoid::Extensions::Hash
- Defined in:
- lib/mongoid/extensions/hash.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#__consolidate__ ⇒ Hash
Consolidate the key/values in the hash under an atomic $set.
-
#__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.
-
#extract_id ⇒ Object
Get the id attribute from this hash, whether it’s prefixed with an underscore or is a symbol.
-
#mongoize ⇒ Hash
Turn the object from the ruby type we deal with to a Mongo friendly type.
-
#resizable? ⇒ true
Can the size of this object change?.
Instance Method Details
#__consolidate__ ⇒ Hash
Consolidate the key/values in the hash under an atomic $set.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mongoid/extensions/hash.rb', line 38 def __consolidate__ consolidated = {} each_pair do |key, value| if key =~ /\$/ (consolidated[key] ||= {}).merge!(value) else (consolidated["$set"] ||= {}).merge!(key => value) end end consolidated end |
#__evolve_object_id__ ⇒ Hash
Evolves each value in the hash to an object id if it is convertable.
14 15 16 |
# File 'lib/mongoid/extensions/hash.rb', line 14 def __evolve_object_id__ update_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 |
# File 'lib/mongoid/extensions/hash.rb', line 26 def __mongoize_object_id__ update_values(&:__mongoize_object_id__) end |
#extract_id ⇒ Object
Get the id attribute from this hash, whether it’s prefixed with an underscore or is a symbol.
59 60 61 |
# File 'lib/mongoid/extensions/hash.rb', line 59 def extract_id self["_id"] || self["id"] || self[:id] || self[:_id] end |
#mongoize ⇒ Hash
Turn the object from the ruby type we deal with to a Mongo friendly type.
72 73 74 |
# File 'lib/mongoid/extensions/hash.rb', line 72 def mongoize ::Hash.mongoize(self) end |
#resizable? ⇒ true
Can the size of this object change?
84 85 86 |
# File 'lib/mongoid/extensions/hash.rb', line 84 def resizable? true end |