Class: Mongoid::Matchable::Nor

Inherits:
Default
  • Object
show all
Defined in:
build/mongoid-7.0/lib/mongoid/matchable/nor.rb

Overview

Defines behavior for handling $nor expressions in embedded documents.

Since:

  • 4.0.0

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::Matchable::Default

Instance Method Details

#_matches?(conditions) ⇒ true, false

Does the supplied query match the attribute?

Note: an empty array as an argument to $nor is prohibited by MongoDB server. Mongoid does allow this and returns false in this case.

Examples:

Does this match?

matcher._matches?("$nor" => [ { field => value } ])

Parameters:

  • conditions (Array)

    The or expression.

Returns:

  • (true, false)

    True if matches, false if not.

Since:

  • 6.4.2/7.0.2/7.1.0



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'build/mongoid-7.0/lib/mongoid/matchable/nor.rb', line 22

def _matches?(conditions)
  if conditions.length == 0
    # MongoDB does not allow $nor array to be empty, but
    # Mongoid accepts an empty array for $or which MongoDB also
    # prohibits
    return false
  end
  conditions.none? do |condition|
    condition.all? do |key, value|
      document._matches?(key => value)
    end
  end
end