Sha256: 2241dc90617b053b0338c73a3d0a068088f7624cff38f9f1aeeeb2d6cbd63c8c

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

module Mongoid
  module Matchable

    # Defines behavior for handling $nor expressions in embedded documents.
    class Nor < Default

      # 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.
      #
      # @example Does this match?
      #   matcher._matches?("$nor" => [ { field => value } ])
      #
      # @param [ Array ] conditions The or expression.
      #
      # @return [ true, false ] True if matches, false if not.
      #
      # @since 7.1.0
      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
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
mongoid-7.1.11 lib/mongoid/matchable/nor.rb
mongoid-7.1.10 lib/mongoid/matchable/nor.rb
mongoid-7.1.9 lib/mongoid/matchable/nor.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/lib/mongoid/matchable/nor.rb
mongoid-7.1.8 lib/mongoid/matchable/nor.rb
mongoid-7.1.7 lib/mongoid/matchable/nor.rb
mongoid-7.1.6 lib/mongoid/matchable/nor.rb
mongoid-7.1.5 lib/mongoid/matchable/nor.rb
mongoid-7.1.4 lib/mongoid/matchable/nor.rb
mongoid-7.1.2 lib/mongoid/matchable/nor.rb
mongoid-7.1.1 lib/mongoid/matchable/nor.rb
mongoid-7.1.0 lib/mongoid/matchable/nor.rb
mongoid-7.1.0.rc0 lib/mongoid/matchable/nor.rb