Module: Mongoid::Matcher::Mod Private

Defined in:
lib/mongoid/matcher/mod.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.

In-memory matcher for $mod expression.

Class Method Summary collapse

Class Method Details

.matches?(_exists, 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 a $mod expression.

Parameters:

  • exists (true | false)

    Not used.

  • value (Numeric)

    The value to check.

  • condition (Array<Numeric>)

    The $mod condition predicate, which is a 2-tuple containing the divisor and remainder.

Returns:

  • (true | false)

    Whether the value matches.

  • (Boolean)

Raises:



19
20
21
22
23
24
25
26
# File 'lib/mongoid/matcher/mod.rb', line 19

module_function def matches?(_exists, value, condition)
  raise Errors::InvalidQuery, "Unknown $mod argument #{condition}" unless condition.is_a?(Array)
  if condition.length != 2
    raise Errors::InvalidQuery, "Malformed $mod argument #{condition}, should have 2 elements"
  end

  condition[1] == value % condition[0]
end