command_search 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/command_search/mongoer.rb +12 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06faff1f0e62e2367a2a30bd36f28b0659e4d385c2e5d50ddbf2a3f73c8d7b88
|
4
|
+
data.tar.gz: 4a644540546ca3f4f1357640c2c5cde78e20bb2769e119a52552dd94ab8e9f35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57839d8fee294a20c5303a958b8b966aef308a0b3366f62e74803998265c41e03b43eb1dd4263f3f9065c14d0e6f761b55eb199ed971e5396b196e61758593d1
|
7
|
+
data.tar.gz: 8306e47f90008256cb30191329645d8fbb96083f7b68fb489b0b19241686eb9c0eaaccc5b111eddca26f82c75ed6e87e8d4304a0c20c1bd9061803a983484840
|
@@ -4,6 +4,16 @@ module CommandSearch
|
|
4
4
|
module Mongoer
|
5
5
|
module_function
|
6
6
|
|
7
|
+
def numeric_field?(field, command_types)
|
8
|
+
raw_type = command_types[field.to_sym]
|
9
|
+
if raw_type.is_a?(Array)
|
10
|
+
type = (raw_type - [:allow_existence_boolean]).first
|
11
|
+
else
|
12
|
+
type = raw_type
|
13
|
+
end
|
14
|
+
[Numeric, Integer].include?(type)
|
15
|
+
end
|
16
|
+
|
7
17
|
def build_search(ast_node, fields, command_types)
|
8
18
|
str = ast_node[:value] || ''
|
9
19
|
fields = [fields] unless fields.is_a?(Array)
|
@@ -19,16 +29,15 @@ module CommandSearch
|
|
19
29
|
end
|
20
30
|
if ast_node[:negate]
|
21
31
|
forms = fields.map do |field|
|
22
|
-
if
|
32
|
+
if numeric_field?(field, command_types)
|
23
33
|
{ field => { '$ne' => str } }
|
24
34
|
else
|
25
35
|
{ field => { '$not' => regex } }
|
26
36
|
end
|
27
37
|
end
|
28
38
|
else
|
29
|
-
forms = fields.map { |f| { f => regex } }
|
30
39
|
forms = fields.map do |field|
|
31
|
-
if
|
40
|
+
if numeric_field?(field, command_types)
|
32
41
|
{ field => str }
|
33
42
|
else
|
34
43
|
{ field => regex }
|