Module: Mongoid::Matcher::EqImplWithRegexp Private

Defined in:
lib/mongoid/matcher/eq_impl_with_regexp.rb

Overview

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.

This is an internal equality implementation that performs exact comparisons and regular expression matches.

Class Method Summary collapse

Class Method Details

.matches?(original_operator, value, condition) ⇒ true | false, 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 whether a value satisfies an $eq (or similar) expression, performing a regular expression match if the condition is a regular expression.

Parameters:

  • original_operator (String)

    Not used.

  • value (Object)

    The value to check.

  • condition (Object)

    The equality condition predicate.

Returns:

  • (true | false)

    Whether the value matches.

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mongoid/matcher/eq_impl_with_regexp.rb', line 22

module_function def matches?(original_operator, value, condition)
  case condition
  when Regexp
    value =~ condition
  when ::BSON::Regexp::Raw
    value =~ condition.compile
  else
    if value.kind_of?(Time) && condition.kind_of?(Time)
      EqImpl.time_eq?(value, condition)
    else
      value == condition
    end
  end
end