command_search 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/command_search/mongoer.rb +12 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f2b041b01322aa1a4075fe249d11be0c2f09162e69004904c1c8f73bc55ef8e
4
- data.tar.gz: 86b41dffb65a45e51301c3f83d8956c8788b53f62af0e070572154d07fe12785
3
+ metadata.gz: 06faff1f0e62e2367a2a30bd36f28b0659e4d385c2e5d50ddbf2a3f73c8d7b88
4
+ data.tar.gz: 4a644540546ca3f4f1357640c2c5cde78e20bb2769e119a52552dd94ab8e9f35
5
5
  SHA512:
6
- metadata.gz: 6cc6ad695a6655df003d5d0741c51e588e4ec11b875bfea45a9baf2695b33cee4e9fc8591f9cd2233f6112a5ff0765fc23370e73f0ad8871e4aee5c23c120f4d
7
- data.tar.gz: 6a040c19da93e76992bbadb4a7e8d1adfdf786fd83a8fd0fd0818691ff5349f70531ac3eaf2374c48502b979652b6adafd9acd4f422c4c543bc3f1ac20082c73
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 [Numeric, Integer].include?(command_types[field.to_sym])
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 [Numeric, Integer].include?(command_types[field.to_sym])
40
+ if numeric_field?(field, command_types)
32
41
  { field => str }
33
42
  else
34
43
  { field => regex }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zumbalogy