query_helper 0.3.6 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/query_helper/invalid_sort_param_error.rb +18 -0
- data/lib/query_helper/sql_filter.rb +1 -1
- data/lib/query_helper/sql_sort.rb +3 -1
- data/lib/query_helper/version.rb +1 -1
- data/lib/query_helper.rb +2 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8de4575667fa298b34568c0635c91d7bc056e8f69b17e7c2053a29a974dff831
|
4
|
+
data.tar.gz: 12b8586b7bd0b14323ea85511dede752fd03d8b0ad12d3704e905fe2f0f8fe56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf2ec789f7bc275fffde36f677711423279cf4746e6cdcd8c14f18d47b5c53053ec7772652b9ea23885dde9b0f63397fcab115624ceac486e004ba12edbcf16e
|
7
|
+
data.tar.gz: 853857f9e9937833b3199064964a54a20e2a089d786d50e5bc3775543d394e040e45b6c1fdc6ebc589f3febef515ccb1da850ac10115fe97a70bd268447ee4d0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
query_helper (0.3.
|
4
|
+
query_helper (0.3.8)
|
5
5
|
activerecord (> 5)
|
6
6
|
activesupport (> 5)
|
7
7
|
sqlite3
|
@@ -89,7 +89,7 @@ GEM
|
|
89
89
|
rspec-mocks (~> 3.10)
|
90
90
|
rspec-support (~> 3.10)
|
91
91
|
rspec-support (3.10.2)
|
92
|
-
sqlite3 (1.
|
92
|
+
sqlite3 (2.1.0)
|
93
93
|
mini_portile2 (~> 2.8.0)
|
94
94
|
thor (1.1.0)
|
95
95
|
tzinfo (2.0.4)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class QueryHelper
|
2
|
+
class InvalidSortParamError < StandardError
|
3
|
+
|
4
|
+
attr_reader :sort_string
|
5
|
+
|
6
|
+
def initialize(msg='Invalid sort param', sort_string='')
|
7
|
+
@sort_string = sort_string
|
8
|
+
super(msg)
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_json
|
12
|
+
{
|
13
|
+
'error' => message,
|
14
|
+
'sort_param' => sort_string
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -17,7 +17,7 @@ class QueryHelper
|
|
17
17
|
|
18
18
|
@filter_values.each do |comparate_alias, criteria|
|
19
19
|
# Find the sql mapping if it exists
|
20
|
-
map = @column_maps.find { |m| m.alias_name == comparate_alias }
|
20
|
+
map = @column_maps.find { |m| m.alias_name.downcase == comparate_alias.downcase }
|
21
21
|
raise InvalidQueryError.new("cannot filter by #{comparate_alias}") unless map
|
22
22
|
|
23
23
|
# create the filter
|
@@ -34,7 +34,9 @@ class QueryHelper
|
|
34
34
|
direction = sort.split(":")[1]
|
35
35
|
modifier = sort.split(":")[2]
|
36
36
|
begin
|
37
|
-
|
37
|
+
sort_col = @column_maps.find{ |m| m.alias_name.casecmp?(sort_alias) }
|
38
|
+
raise InvalidSortParamError.new("Invalid sort param", sort_alias) if sort_col.nil?
|
39
|
+
sql_expression = sort_col.sql_expression
|
38
40
|
rescue NoMethodError => e
|
39
41
|
raise InvalidQueryError.new("Sorting not allowed on column '#{sort_alias}'")
|
40
42
|
end
|
data/lib/query_helper/version.rb
CHANGED
data/lib/query_helper.rb
CHANGED
@@ -10,6 +10,7 @@ require "query_helper/sql_manipulator"
|
|
10
10
|
require "query_helper/sql_filter"
|
11
11
|
require "query_helper/sql_sort"
|
12
12
|
require "query_helper/invalid_query_error"
|
13
|
+
require "query_helper/invalid_sort_param_error"
|
13
14
|
|
14
15
|
class QueryHelper
|
15
16
|
|
@@ -281,7 +282,7 @@ class QueryHelper
|
|
281
282
|
placement = :where
|
282
283
|
maps = column_maps.select do |cm|
|
283
284
|
placement = :having if cm.aggregate
|
284
|
-
@search_fields.include? cm.alias_name
|
285
|
+
@search_fields.map(&:downcase).include? cm.alias_name.downcase
|
285
286
|
end
|
286
287
|
bind_variable = ('a'..'z').to_a.shuffle[0,20].join.to_sym
|
287
288
|
@bind_variables[bind_variable] = "%#{@search_string}%"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patterninc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/query_helper/column_map.rb
|
191
191
|
- lib/query_helper/filter.rb
|
192
192
|
- lib/query_helper/invalid_query_error.rb
|
193
|
+
- lib/query_helper/invalid_sort_param_error.rb
|
193
194
|
- lib/query_helper/query_helper_concern.rb
|
194
195
|
- lib/query_helper/sql_filter.rb
|
195
196
|
- lib/query_helper/sql_manipulator.rb
|
@@ -216,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
217
|
- !ruby/object:Gem::Version
|
217
218
|
version: '0'
|
218
219
|
requirements: []
|
219
|
-
rubygems_version: 3.
|
220
|
+
rubygems_version: 3.5.16
|
220
221
|
signing_key:
|
221
222
|
specification_version: 4
|
222
223
|
summary: Ruby Gem to help with pagination and data formatting at Pattern, Inc.
|