-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Mongoid | ||
module Matcher | ||
|
||
# @api private | ||
module Mod | ||
module_function def matches?(exists, value, condition) | ||
unless Array === condition | ||
raise Errors::InvalidQuery, "Unknown $mod argument #{condition}" | ||
end | ||
if condition.length != 2 | ||
raise Errors::InvalidQuery, "Malformed $mod argument #{condition}, should have 2 elements" | ||
end | ||
condition[1] == value%condition[0] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
- name: existing field - matches | ||
document: | ||
pi: 8 | ||
query: | ||
pi: | ||
$mod: [5, 3] | ||
matches: true | ||
|
||
- name: existing field - does not match | ||
document: | ||
pi: 9 | ||
query: | ||
pi: | ||
$mod: [5, 3] | ||
matches: false | ||
|
||
- name: invalid condition | ||
document: | ||
pi: 9 | ||
query: | ||
pi: | ||
$mod: 5 | ||
error: true | ||
|
||
- name: invalid field | ||
document: | ||
pi: [1, 2] | ||
query: | ||
pi: | ||
$mod: 5 | ||
error: true | ||
|
||
- name: array too short | ||
document: | ||
pi: 3 | ||
query: | ||
pi: | ||
$mod: [5] | ||
error: true | ||
|
||
- name: empty array | ||
document: | ||
pi: 3 | ||
query: | ||
pi: | ||
$mod: [] | ||
error: true | ||
|
||
- name: array too long | ||
document: | ||
pi: 3 | ||
query: | ||
pi: | ||
$mod: [1, 2, 3] | ||
error: true |