Module: Mongoid::Extensions::Hash::CriteriaHelpers
- Included in:
- Hash
- Defined in:
- lib/mongoid/extensions/hash/criteria_helpers.rb
Overview
Expands complex criterion into mongodb selectors.
Instance Method Summary collapse
-
#expand_complex_criteria ⇒ Hash
Expand the complex criteria into a MongoDB compliant selector hash.
-
#extract_id ⇒ Object
Get the id attribute from this hash, whether it’s prefixed with an underscore or is a symbol.
Instance Method Details
#expand_complex_criteria ⇒ Hash
Expand the complex criteria into a MongoDB compliant selector hash.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mongoid/extensions/hash/criteria_helpers.rb', line 17 def {}.tap do |hsh| each_pair do |k, v| if k.respond_to?(:key) && k.respond_to?(:to_mongo_query) hsh[k.key] ||= {} v = v. if v.is_a?(::Hash) hsh[k.key].merge!(k.to_mongo_query(v)) else v.map!{|e| e.is_a?(::Hash) ? e. : e } if v.is_a?(::Array) hsh[k] = v end end end end |
#extract_id ⇒ Object
Get the id attribute from this hash, whether it’s prefixed with an underscore or is a symbol.
41 42 43 |
# File 'lib/mongoid/extensions/hash/criteria_helpers.rb', line 41 def extract_id self["id"] || self["_id"] || self[:id] || self[:_id] end |