query_helper 0.2.12 → 0.2.17

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: d785c033c2c9b9f1eaa01641b8e92b8690a1a54eceb1507e58efb4a4437655ab
4
- data.tar.gz: de0529d9069f0c612b39873c69160eff8eeb52b35bcc05401026cc161b9914c9
3
+ metadata.gz: 761535bdbebea924ac3d4ab1ed900f50a047f2e79ed5c2121b5f0eecf0327388
4
+ data.tar.gz: bb55e4554e416e2729d35c2fc1091d65726bde73fc1db93e192baf1275237bb0
5
5
  SHA512:
6
- metadata.gz: 39e7d8268cde0434747bfb2cc52e0f85c6d294ba18af86b5a415f5c92da2f1dfbe7822dbdc685c55f99520b15e205e2a75867db6e628b5d594730a1b472990ca
7
- data.tar.gz: efcb54e2da3b21a3c454ff490b2c892336913dde41602aa07b31edf658f4644ebcc4f1a234bff8b72706ebd8fcfc7366de24c1a88891d1a3176d72686cdceb7e
6
+ metadata.gz: 0ba6ddb3222dba240810b0df6e1bc1025a2510d4b00c06430fc91c8786dbacc3d06df83f7986766a1d0755988550fdc44396fa1357c7c1cd2accc54edc904345
7
+ data.tar.gz: 33c4194f5bd8da5abdf8e7f2e78f0fcd9d84e5184c89ac3e926b8435e2a125f8b0f4428532fbfe24f6288e20f4c8520731c88720f2261788738f16048d8f0a49
@@ -1,56 +1,56 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- query_helper (0.2.12)
4
+ query_helper (0.2.17)
5
5
  activerecord (> 5)
6
6
  activesupport (> 5)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionpack (6.0.2.2)
12
- actionview (= 6.0.2.2)
13
- activesupport (= 6.0.2.2)
11
+ actionpack (6.0.3.2)
12
+ actionview (= 6.0.3.2)
13
+ activesupport (= 6.0.3.2)
14
14
  rack (~> 2.0, >= 2.0.8)
15
15
  rack-test (>= 0.6.3)
16
16
  rails-dom-testing (~> 2.0)
17
17
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
18
- actionview (6.0.2.2)
19
- activesupport (= 6.0.2.2)
18
+ actionview (6.0.3.2)
19
+ activesupport (= 6.0.3.2)
20
20
  builder (~> 3.1)
21
21
  erubi (~> 1.4)
22
22
  rails-dom-testing (~> 2.0)
23
23
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
24
- activemodel (6.0.2.2)
25
- activesupport (= 6.0.2.2)
26
- activerecord (6.0.2.2)
27
- activemodel (= 6.0.2.2)
28
- activesupport (= 6.0.2.2)
29
- activesupport (6.0.2.2)
24
+ activemodel (6.0.3.2)
25
+ activesupport (= 6.0.3.2)
26
+ activerecord (6.0.3.2)
27
+ activemodel (= 6.0.3.2)
28
+ activesupport (= 6.0.3.2)
29
+ activesupport (6.0.3.2)
30
30
  concurrent-ruby (~> 1.0, >= 1.0.2)
31
31
  i18n (>= 0.7, < 2)
32
32
  minitest (~> 5.1)
33
33
  tzinfo (~> 1.1)
34
- zeitwerk (~> 2.2)
34
+ zeitwerk (~> 2.2, >= 2.2.2)
35
35
  builder (3.2.4)
36
- byebug (11.1.1)
36
+ byebug (11.1.3)
37
37
  concurrent-ruby (1.1.6)
38
38
  crass (1.0.6)
39
- diff-lcs (1.3)
39
+ diff-lcs (1.4.4)
40
40
  erubi (1.9.0)
41
41
  faker (1.9.6)
42
42
  i18n (>= 0.7)
43
- i18n (1.8.2)
43
+ i18n (1.8.5)
44
44
  concurrent-ruby (~> 1.0)
45
- loofah (2.4.0)
45
+ loofah (2.6.0)
46
46
  crass (~> 1.0.2)
47
47
  nokogiri (>= 1.5.9)
48
48
  method_source (1.0.0)
49
49
  mini_portile2 (2.4.0)
50
- minitest (5.14.0)
51
- nokogiri (1.10.9)
50
+ minitest (5.14.1)
51
+ nokogiri (1.10.10)
52
52
  mini_portile2 (~> 2.4.0)
53
- rack (2.2.2)
53
+ rack (2.2.3)
54
54
  rack-test (1.1.0)
55
55
  rack (>= 1.0, < 3)
56
56
  rails-dom-testing (2.0.3)
@@ -58,9 +58,9 @@ GEM
58
58
  nokogiri (>= 1.6)
59
59
  rails-html-sanitizer (1.3.0)
60
60
  loofah (~> 2.3)
61
- railties (6.0.2.2)
62
- actionpack (= 6.0.2.2)
63
- activesupport (= 6.0.2.2)
61
+ railties (6.0.3.2)
62
+ actionpack (= 6.0.3.2)
63
+ activesupport (= 6.0.3.2)
64
64
  method_source
65
65
  rake (>= 0.8.7)
66
66
  thor (>= 0.20.3, < 2.0)
@@ -69,15 +69,15 @@ GEM
69
69
  rspec-core (~> 3.9.0)
70
70
  rspec-expectations (~> 3.9.0)
71
71
  rspec-mocks (~> 3.9.0)
72
- rspec-core (3.9.1)
73
- rspec-support (~> 3.9.1)
74
- rspec-expectations (3.9.1)
72
+ rspec-core (3.9.2)
73
+ rspec-support (~> 3.9.3)
74
+ rspec-expectations (3.9.2)
75
75
  diff-lcs (>= 1.2.0, < 2.0)
76
76
  rspec-support (~> 3.9.0)
77
77
  rspec-mocks (3.9.1)
78
78
  diff-lcs (>= 1.2.0, < 2.0)
79
79
  rspec-support (~> 3.9.0)
80
- rspec-rails (4.0.0)
80
+ rspec-rails (4.0.1)
81
81
  actionpack (>= 4.2)
82
82
  activesupport (>= 4.2)
83
83
  railties (>= 4.2)
@@ -85,13 +85,13 @@ GEM
85
85
  rspec-expectations (~> 3.9)
86
86
  rspec-mocks (~> 3.9)
87
87
  rspec-support (~> 3.9)
88
- rspec-support (3.9.2)
88
+ rspec-support (3.9.3)
89
89
  sqlite3 (1.3.13)
90
90
  thor (1.0.1)
91
91
  thread_safe (0.3.6)
92
- tzinfo (1.2.6)
92
+ tzinfo (1.2.7)
93
93
  thread_safe (~> 0.1)
94
- zeitwerk (2.3.0)
94
+ zeitwerk (2.4.0)
95
95
 
96
96
  PLATFORMS
97
97
  ruby
@@ -144,7 +144,7 @@ class QueryHelper
144
144
  end
145
145
 
146
146
  def to_json(args)
147
- JSON.generate(results)
147
+ results.to_json
148
148
  end
149
149
 
150
150
  def to_sql
@@ -179,6 +179,29 @@ class QueryHelper
179
179
  return @results
180
180
  end
181
181
 
182
+ def pagination_results(count=@count)
183
+ # Set pagination params if they aren't provided
184
+ results_per_page = @per_page || count
185
+ results_page = @page || 1
186
+
187
+ total_pages = (count/(results_per_page.nonzero? || 1).to_f).ceil
188
+ next_page = results_page + 1 if results_page.between?(1, total_pages - 1)
189
+ previous_page = results_page - 1 if results_page.between?(2, total_pages)
190
+ first_page = results_page == 1
191
+ last_page = results_page >= total_pages
192
+ out_of_range = !results_page.between?(1,total_pages)
193
+
194
+ { count: count,
195
+ current_page: results_page,
196
+ next_page: next_page,
197
+ previous_page: previous_page,
198
+ total_pages: total_pages,
199
+ per_page: results_per_page,
200
+ first_page: first_page,
201
+ last_page: last_page,
202
+ out_of_range: out_of_range }
203
+ end
204
+
182
205
  private
183
206
 
184
207
  def determine_page(page:, per_page:)
@@ -239,29 +262,6 @@ class QueryHelper
239
262
  @results.map!{ |r| r.except("_query_full_count") } if @page && @per_page && !@single_record
240
263
  end
241
264
 
242
- def pagination_results
243
- # Set pagination params if they aren't provided
244
- results_per_page = @per_page || @count
245
- results_page = @page || 1
246
-
247
- total_pages = (@count/(results_per_page.nonzero? || 1).to_f).ceil
248
- next_page = results_page + 1 if results_page.between?(1, total_pages - 1)
249
- previous_page = results_page - 1 if results_page.between?(2, total_pages)
250
- first_page = results_page == 1
251
- last_page = results_page == total_pages
252
- out_of_range = !results_page.between?(1,total_pages)
253
-
254
- { count: @count,
255
- current_page: results_page,
256
- next_page: next_page,
257
- previous_page: previous_page,
258
- total_pages: total_pages,
259
- per_page: results_per_page,
260
- first_page: first_page,
261
- last_page: last_page,
262
- out_of_range: out_of_range }
263
- end
264
-
265
265
  def create_column_maps
266
266
  ColumnMap.create_column_mappings(
267
267
  query: @query,
@@ -55,7 +55,7 @@ class QueryHelper
55
55
 
56
56
  def insert_order_by_and_limit_clause
57
57
  @sql.slice!(@parser.limit_clause) if @parser.limit_included? # remove existing limit clause
58
- @sql.slice!(@parser.order_by_clause) if @parser.order_by_included? # remove existing order by clause
58
+ @sql.slice!(@parser.order_by_clause) if @parser.order_by_included? && @order_by_clauses.length > 0 # remove existing order by clause
59
59
  @sql += " order by #{@order_by_clauses.join(", ")} " if @order_by_clauses.length > 0
60
60
  @sql += " limit :limit offset :offset " if @include_limit_clause
61
61
  end
@@ -1,3 +1,3 @@
1
1
  class QueryHelper
2
- VERSION = "0.2.12"
2
+ VERSION = "0.2.17"
3
3
  end
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.2.12
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan McDaniel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-16 00:00:00.000000000 Z
11
+ date: 2020-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler