Module: Mongoid::Matchers::Strategies
Overview
This module is responsible for returning the correct matcher given a MongoDB query expression.
Constant Summary collapse
- MATCHERS =
{ "$all" => Matchers::All, "$and" => Matchers::And, "$exists" => Matchers::Exists, "$gt" => Matchers::Gt, "$gte" => Matchers::Gte, "$in" => Matchers::In, "$lt" => Matchers::Lt, "$lte" => Matchers::Lte, "$ne" => Matchers::Ne, "$nin" => Matchers::Nin, "$or" => Matchers::Or, "$size" => Matchers::Size }.with_indifferent_access
Instance Method Summary collapse
-
#matcher(document, key, value) ⇒ Matcher
Get the matcher for the supplied key and value.
Instance Method Details
#matcher(document, key, value) ⇒ Matcher
Get the matcher for the supplied key and value. Will determine the class name from the key.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mongoid/matchers/strategies.rb', line 52 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 |