Sha256: 6d2295c6e9f0c60e7cf97f5a395b6379954a8df7716d887d201365f461e1d441

Contents?: true

Size: 1.04 KB

Versions: 43

Compression:

Stored size: 1.04 KB

Contents

module Mongoid
  module Matcher

    # @api private
    module Regex
      module_function def matches?(exists, value, condition)
        condition = case condition
        when Regexp
          condition
        when BSON::Regexp::Raw
          condition.compile
        else
          # Note that strings must have been converted to a regular expression
          # instance already (with $options taken into account, if provided).
          raise Errors::InvalidQuery, "$regex requires a regular expression argument: #{Errors::InvalidQuery.truncate_expr(condition)}"
        end

        case value
        when Array
          value.any? do |v|
            v =~ condition
          end
        when String
          value =~ condition
        else
          false
        end
      end

      module_function def matches_array_or_scalar?(value, condition)
        if Array === value
          value.any? do |v|
            matches?(true, v, condition)
          end
        else
          matches?(true, value, condition)
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
mongoid-8.0.3 lib/mongoid/matcher/regex.rb
mongoid-7.5.2 lib/mongoid/matcher/regex.rb
mongoid-8.0.2 lib/mongoid/matcher/regex.rb
mongoid-7.5.1 lib/mongoid/matcher/regex.rb
mongoid-7.4.3 lib/mongoid/matcher/regex.rb
mongoid-8.0.1 lib/mongoid/matcher/regex.rb
mongoid-7.5.0 lib/mongoid/matcher/regex.rb
mongoid-7.4.1 lib/mongoid/matcher/regex.rb
mongoid-7.3.5 lib/mongoid/matcher/regex.rb
mongoid-7.4.0 lib/mongoid/matcher/regex.rb
mongoid-7.3.4 lib/mongoid/matcher/regex.rb
mongoid-7.2.6 lib/mongoid/matcher/regex.rb
mongoid-7.3.3 lib/mongoid/matcher/regex.rb
mongoid-7.3.2 lib/mongoid/matcher/regex.rb
mongoid-7.2.5 lib/mongoid/matcher/regex.rb
mongoid-7.2.4 lib/mongoid/matcher/regex.rb
mongoid-7.3.1 lib/mongoid/matcher/regex.rb
mongoid-7.3.0 lib/mongoid/matcher/regex.rb
mongoid-7.2.3 lib/mongoid/matcher/regex.rb
mongoid-7.2.2 lib/mongoid/matcher/regex.rb