Module: Mongoid::Matcher::Regex Private

Defined in:
build/mongoid-8.1/lib/mongoid/matcher/regex.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.matches?(exists, value, condition) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'build/mongoid-8.1/lib/mongoid/matcher/regex.rb', line 6

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

.matches_array_or_scalar?(value, condition) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



30
31
32
33
34
35
36
37
38
# File 'build/mongoid-8.1/lib/mongoid/matcher/regex.rb', line 30

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