Sha256: 3bb721d6f12ca3c27c9fe73584a185ea345d396b82f48158a093acab3a4258e7

Contents?: true

Size: 1.05 KB

Versions: 14

Compression:

Stored size: 1.05 KB

Contents

module Mongoid
  module Matcher

    # This module is used by $eq and other operators that need to perform
    # the matching that $eq performs (for example, $ne which negates the result
    # of $eq). Unlike $eq this module takes an original operator as an
    # additional argument to +matches?+ to provide the correct exception
    # messages reflecting the operator that was first invoked.
    #
    # @api private
    module EqImpl
      module_function def matches?(exists, value, condition, original_operator)
        case condition
        when Range
          # Since $ne invokes $eq, the exception message needs to handle
          # both operators.
          raise Errors::InvalidQuery, "Range is not supported as an argument to '#{original_operator}'"
=begin
          if value.is_a?(Array)
            value.any? { |elt| condition.include?(elt) }
          else
            condition.include?(value)
          end
=end
        else
          value == condition ||
          value.is_a?(Array) && value.include?(condition)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mongoid-7.3.5 lib/mongoid/matcher/eq_impl.rb
mongoid-7.3.4 lib/mongoid/matcher/eq_impl.rb
mongoid-7.2.6 lib/mongoid/matcher/eq_impl.rb
mongoid-7.3.3 lib/mongoid/matcher/eq_impl.rb
mongoid-7.3.2 lib/mongoid/matcher/eq_impl.rb
mongoid-7.2.5 lib/mongoid/matcher/eq_impl.rb
mongoid-7.2.4 lib/mongoid/matcher/eq_impl.rb
mongoid-7.3.1 lib/mongoid/matcher/eq_impl.rb
mongoid-7.3.0 lib/mongoid/matcher/eq_impl.rb
mongoid-7.2.3 lib/mongoid/matcher/eq_impl.rb
mongoid-7.2.2 lib/mongoid/matcher/eq_impl.rb
mongoid-7.2.1 lib/mongoid/matcher/eq_impl.rb
mongoid-7.2.0 lib/mongoid/matcher/eq_impl.rb
mongoid-7.2.0.rc1 lib/mongoid/matcher/eq_impl.rb