Class: Mongoid::Matchers::Or

Inherits:
Default show all
Defined in:
lib/mongoid/matchers/or.rb

Overview

Defines behavior for handling $or expressions in embedded documents.

Instance Attribute Summary

Attributes inherited from Default

#attribute, #document

Instance Method Summary collapse

Methods inherited from Default

#initialize

Constructor Details

This class inherits a constructor from Mongoid::Matchers::Default

Instance Method Details

#matches?(conditions) ⇒ true, false

Does the supplied query match the attribute?

Examples:

Does this match?

matcher.matches?("$or" => [ { field => value } ])

Parameters:

  • conditions (Array)

    The or expression.

Returns:

  • (true, false)

    True if matches, false if not.

Since:

  • 2.0.0.rc.7



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mongoid/matchers/or.rb', line 18

def matches?(conditions)
  conditions.each do |condition|
    res = true
    condition.keys.each do |k|
      key = k
      value = condition[k]
      res &&= Strategies.matcher(document, key, value).matches?(value)
      break unless res
    end
    return res if res
  end
  return false
end