Sha256: fc3879b9d6686bfa6112bcd69b319f08d2c28a473610b2d8c62f461ba0604e06

Contents?: true

Size: 1.09 KB

Versions: 40

Compression:

Stored size: 1.09 KB

Contents

module Mongoid
  module Matcher

    # @api private
    module ElemMatch
      module_function def matches?(exists, value, condition)
        unless Hash === condition
          raise Errors::InvalidQuery, "$elemMatch requires a Hash operand: #{Errors::InvalidQuery.truncate_expr(condition)}"
        end
        if Array === value && !value.empty?
          value.any? do |v|
            ElemMatchExpression.matches?(v, condition)
          end
        else
          # Validate the condition is valid, even though we will never attempt
          # matching it.
          condition.each do |k, v|
            k = k.to_s
            if k.start_with?('$')
              begin
                ExpressionOperator.get(k)
              rescue Mongoid::Errors::InvalidExpressionOperator
                begin
                  FieldOperator.get(k)
                rescue Mongoid::Errors::InvalidFieldOperator => exc
                  raise Mongoid::Errors::InvalidElemMatchOperator.new(exc.operator)
                end
              end
            end
          end
          false
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

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