Methods

Class/Module Index [+]

Quicksearch

Mongoid::Matchers::Strategies

This module is responsible for returning the correct matcher given a MongoDB query expression.

Constants

MATCHERS

Public Instance Methods

matcher(document, key, value) click to toggle source

Get the matcher for the supplied key and value. Will determine the class name from the key.

@example Get the matcher.

document.matcher(:title, { "$in" => [ "test" ] })

@param [ Document ] document The document to check. @param [ Symbol, String ] key The field name. @param [ Object, Hash ] The value or selector.

@return [ Matcher ] The matcher.

@since 2.0.0.rc.7

# File lib/mongoid/matchers/strategies.rb, line 51
def matcher(document, key, value)
  if value.is_a?(Hash)
    matcher = MATCHERS[value.keys.first]
    if matcher
      matcher.new(extract_attribute(document, key))
    else
      Default.new(extract_attribute(document, key))
    end
  else
    case key.to_s
      when "$or" then Matchers::Or.new(value, document)
      when "$and" then Matchers::And.new(value, document)
      else Default.new(extract_attribute(document, key))
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.