Sha256: 09a7b649246e2295ef6264f4a36bf1c6d6fcc6a7f69e11c7de663b103b1ec9c6

Contents?: true

Size: 816 Bytes

Versions: 13

Compression:

Stored size: 816 Bytes

Contents

# frozen_string_literal: true
# encoding: utf-8

module Mongoid
  module Matchable

    # Checks that all values match.
    class All < Default

      # Return true if the attribute and first value in the hash are equal.
      #
      # @example Do the values match?
      #   matcher._matches?({ :key => 10 })
      #
      # @param [ Hash ] condition The condition to evaluate. This must be
      #   a one-element hash like {'$gt' => 1}.
      #
      # @return [ true, false ] If the values match.
      def _matches?(condition)
        first = condition_value(condition)
        return false if first.is_a?(Array) && first.empty?

        attribute_array = Array.wrap(@attribute)
        first.all? do |e|
          attribute_array.any? { |_attribute| e === _attribute }
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

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