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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c3503df41d4640984dac6772f15d439c23b8fd3904514d58fb98b2af7efbc45
4
- data.tar.gz: d40370dd2f2e9c2da4b0993a7ac21d08dbc512b76bd2da031ff1e3ce56605507
3
+ metadata.gz: 05e0f634c8e36cce3943e085bf9a0bd461f9e8cded7fa8b28ba84e606bba50fe
4
+ data.tar.gz: 2bc96a37d492f6733a370d3c5f86696dae953056a261bcd2de9787589bd02e34
5
5
  SHA512:
6
- metadata.gz: 30a723aca45d1ceb20f914826367ca92bfc6381ebe621d823163c0cc3eb6615b4398dc1e4147f4dad4b40b41c8c71bb52191ab8909d384b6ff345caf1982f224
7
- data.tar.gz: 8c8c2855b31e831ed3b22c6c1f2709e15f2ee332515becf48e8a31637a82cf1ded7712155444d89e740bde76a0f62f53a765e61b4686930870507c755e63e8a7
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, valid_columns=nil, symbol_prefix="")
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 valid_columns
10
- raise ArgumentError.new("Invalid filter '#{filter_attribute}'") unless valid_columns.include? filter_attribute
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
- modified_filter_attribute = "lower(#{filter_attribute})"
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 filter_attribute
36
+ # if criterion are anything but numbers, downcase the filter_column
34
37
  if criterion.scan(/[^\d|,|\s]/).any?
35
- modified_filter_attribute = "lower(#{filter_attribute})"
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 filter_attribute
44
+ # if criterion are anything but numbers, downcase the filter_column
42
45
  if criterion.scan(/[^\d|,|\s]/).any?
43
- modified_filter_attribute = "lower(#{filter_attribute})"
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 = modified_filter_attribute || filter_attribute
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?
@@ -1,3 +1,3 @@
1
1
  module PatternQueryHelper
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
@@ -89,7 +89,11 @@ module PatternQueryHelper
89
89
  end
90
90
 
91
91
  def self.parse_helpers(query_helpers, valid_columns)
92
- filtering = PatternQueryHelper::Filtering.create_filters(query_helpers[:filter], valid_columns)
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.7
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-17 00:00:00.000000000 Z
11
+ date: 2019-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler