pattern_query_helper 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pattern_query_helper/filtering.rb +12 -9
- data/lib/pattern_query_helper/version.rb +1 -1
- data/lib/pattern_query_helper.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05e0f634c8e36cce3943e085bf9a0bd461f9e8cded7fa8b28ba84e606bba50fe
|
4
|
+
data.tar.gz: 2bc96a37d492f6733a370d3c5f86696dae953056a261bcd2de9787589bd02e34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6e697f89bc109f2c120998d662106340fb78db4c319ca898ee9e86fe7aebdaaa2dd9e6881b8686128b34d377b58893ab3ce31e9e09b00d89bef05efea1b629f
|
7
|
+
data.tar.gz: c14a371a3224a4d80d00c5da3f78e821d37d2a0ed1625dff40e3727adea536f7bf8f585a837887a9be90ec8009b8bc831bb5796d8bf24f68d331c73060e2a9cd
|
@@ -1,13 +1,16 @@
|
|
1
1
|
module PatternQueryHelper
|
2
2
|
class Filtering
|
3
|
-
def self.create_filters(filters,
|
3
|
+
def self.create_filters(filters, valid_columns_map=nil, symbol_prefix="")
|
4
4
|
filters ||= {}
|
5
5
|
filter_string = "true = true"
|
6
6
|
filter_params = {}
|
7
7
|
filter_array = []
|
8
8
|
filters.each do |filter_attribute, criteria|
|
9
|
-
if
|
10
|
-
raise ArgumentError.new("Invalid filter '#{filter_attribute}'") unless
|
9
|
+
if valid_columns_map
|
10
|
+
raise ArgumentError.new("Invalid filter '#{filter_attribute}'") unless valid_columns_map[filter_attribute]
|
11
|
+
filter_column = valid_columns_map[filter_attribute]
|
12
|
+
else
|
13
|
+
filter_column = filter_attribute
|
11
14
|
end
|
12
15
|
criteria.each do |operator_code, criterion|
|
13
16
|
filter_symbol = "#{symbol_prefix}#{filter_attribute}_#{operator_code}"
|
@@ -25,22 +28,22 @@ module PatternQueryHelper
|
|
25
28
|
when "noteql"
|
26
29
|
operator = "!="
|
27
30
|
when "like"
|
28
|
-
|
31
|
+
modified_filter_column = "lower(#{filter_column})"
|
29
32
|
operator = "like"
|
30
33
|
criterion.downcase!
|
31
34
|
when "in"
|
32
35
|
operator = "in (:#{filter_symbol})"
|
33
|
-
# if criterion are anything but numbers, downcase the
|
36
|
+
# if criterion are anything but numbers, downcase the filter_column
|
34
37
|
if criterion.scan(/[^\d|,|\s]/).any?
|
35
|
-
|
38
|
+
modified_filter_column = "lower(#{filter_column})"
|
36
39
|
end
|
37
40
|
criterion = criterion.downcase.split(",")
|
38
41
|
filter_symbol_already_embedded = true
|
39
42
|
when "notin"
|
40
43
|
operator = "not in (:#{filter_symbol})"
|
41
|
-
# if criterion are anything but numbers, downcase the
|
44
|
+
# if criterion are anything but numbers, downcase the filter_column
|
42
45
|
if criterion.scan(/[^\d|,|\s]/).any?
|
43
|
-
|
46
|
+
modified_filter_column = "lower(#{filter_column})"
|
44
47
|
end
|
45
48
|
criterion = criterion.downcase.split(",")
|
46
49
|
filter_symbol_already_embedded = true
|
@@ -50,7 +53,7 @@ module PatternQueryHelper
|
|
50
53
|
else
|
51
54
|
raise ArgumentError.new("Invalid operator code '#{operator_code}' on '#{filter_attribute}' filter")
|
52
55
|
end
|
53
|
-
filter_column =
|
56
|
+
filter_column = modified_filter_column || filter_column
|
54
57
|
filter_string = "#{filter_string} and #{filter_column} #{operator}"
|
55
58
|
filter_string << " :#{filter_symbol}" unless filter_symbol_already_embedded or filter_symbol.blank?
|
56
59
|
filter_params["#{filter_symbol}"] = criterion unless filter_symbol.blank?
|
data/lib/pattern_query_helper.rb
CHANGED
@@ -89,7 +89,11 @@ module PatternQueryHelper
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def self.parse_helpers(query_helpers, valid_columns)
|
92
|
-
|
92
|
+
valid_columns_map = {}
|
93
|
+
valid_columns.each do |c|
|
94
|
+
valid_columns_map["#{c}"] = c
|
95
|
+
end
|
96
|
+
filtering = PatternQueryHelper::Filtering.create_filters(query_helpers[:filter], valid_columns_map)
|
93
97
|
sorting = PatternQueryHelper::Sorting.parse_sorting_params(query_helpers[:sort], valid_columns)
|
94
98
|
associations = PatternQueryHelper::Associations.process_association_params(query_helpers[:include])
|
95
99
|
pagination = PatternQueryHelper::Pagination.parse_pagination_params(query_helpers[:page], query_helpers[:per_page])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pattern_query_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan McDaniel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|