Sha256: 952ec7668ff70a6efbb201cb3267a703f4cd5975881750546e6f7a6ae823d0d0

Contents?: true

Size: 1.35 KB

Versions: 35

Compression:

Stored size: 1.35 KB

Contents

module Mongoid
  module Matcher

    # @api private
    module FieldOperator
      MAP = {
        '$all' => All,
        '$bitsAllClear' => BitsAllClear,
        '$bitsAllSet' => BitsAllSet,
        '$bitsAnyClear' => BitsAnyClear,
        '$bitsAnySet' => BitsAnySet,
        '$elemMatch' => ElemMatch,
        '$eq' => Eq,
        '$exists' => Exists,
        '$gt' => Gt,
        '$gte' => Gte,
        '$in' => In,
        '$lt' => Lt,
        '$lte' => Lte,
        '$mod' => Mod,
        '$nin' => Nin,
        '$ne' => Ne,
        '$not' => Not,
        '$regex' => Regex,
        '$size' => Size,
        '$type' => Type,
      }.freeze

      module_function def get(op)
        MAP.fetch(op)
      rescue KeyError
        raise Errors::InvalidFieldOperator.new(op)
      end

      module_function def apply_array_field_operator(exists, value, condition)
        if Array === value
          value.any? { |v| yield v }
        else
          yield value
        end
      end

      module_function def apply_comparison_operator(operator, left, right)
        left.send(operator, right)
      rescue ArgumentError, NoMethodError, TypeError
        # We silence bogus comparison attempts, e.g. number to string
        # comparisons.
        # Several different exceptions may be produced depending on the types
        # involved.
        false
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
mongoid-8.0.10 lib/mongoid/matcher/field_operator.rb
mongoid-8.1.10 lib/mongoid/matcher/field_operator.rb
mongoid-8.1.9 lib/mongoid/matcher/field_operator.rb
mongoid-8.0.9 lib/mongoid/matcher/field_operator.rb
mongoid-8.1.8 lib/mongoid/matcher/field_operator.rb
mongoid-8.1.7 lib/mongoid/matcher/field_operator.rb
mongoid-8.1.6 lib/mongoid/matcher/field_operator.rb
mongoid-8.0.8 lib/mongoid/matcher/field_operator.rb
mongoid-8.1.5 lib/mongoid/matcher/field_operator.rb
mongoid-8.1.4 lib/mongoid/matcher/field_operator.rb
mongoid-8.0.7 lib/mongoid/matcher/field_operator.rb
mongoid-8.1.3 lib/mongoid/matcher/field_operator.rb
mongoid-8.1.2 lib/mongoid/matcher/field_operator.rb
mongoid-8.0.6 lib/mongoid/matcher/field_operator.rb
mongoid-7.5.4 lib/mongoid/matcher/field_operator.rb
mongoid-8.1.1 lib/mongoid/matcher/field_operator.rb
mongoid-8.0.5 lib/mongoid/matcher/field_operator.rb
mongoid-8.1.0 lib/mongoid/matcher/field_operator.rb
mongoid-7.5.3 lib/mongoid/matcher/field_operator.rb
mongoid-8.0.4 lib/mongoid/matcher/field_operator.rb