Class/Module Index [+]

Quicksearch

Mongoid::Extensions::Hash::CriteriaHelpers

Expands complex criterion into mongodb selectors.

Public Instance Methods

expand_complex_criteria() click to toggle source

Expand the complex criteria into a MongoDB compliant selector hash.

@example Convert the criterion.

{}.expand_complex_criteria

@return [ Hash ] The mongo selector.

@since 1.0.0

# File lib/mongoid/extensions/hash/criteria_helpers.rb, line 16
def expand_complex_criteria
  {}.tap do |hsh|
    each_pair do |k,v|
      if k.respond_to?(:key) && k.respond_to?(:to_mongo_query)
        hsh[k.key] ||= {}
        hsh[k.key].merge!(k.to_mongo_query(v))
      else
        hsh[k] = v
      end
    end
  end
end
extract_id() click to toggle source

Get the id attribute from this hash, whether it’s prefixed with an underscore or is a symbol.

@example Extract the id.

{ :_id => 1 }.extract_id

@return [ Object ] The value of the id.

@since 2.3.2

# File lib/mongoid/extensions/hash/criteria_helpers.rb, line 38
def extract_id
  self["id"] || self["_id"] || self[:id] || self[:_id]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.