Sha256: 6d2295c6e9f0c60e7cf97f5a395b6379954a8df7716d887d201365f461e1d441

Contents?: true

Size: 1.04 KB

Versions: 41

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

41 entries across 41 versions & 1 rubygems

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