grape-kaminari 0.4.0 → 0.4.1

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: 5be6c20ba0aef343949970af43c69d6781e945ed043b3baa3b6c258570f4300b
4
- data.tar.gz: f9f31a5f31560e5cd751b31109d5720410ea4f8c523a1d0b4b050c1eef039247
3
+ metadata.gz: d524d760fab53973250ae175e7e484a22c0e1d76ca3a427b42d51118660fd708
4
+ data.tar.gz: 2c1e66d494b6b2dafdd9e7831022a7f1a6b8b10652d19acc897da2f3b150d52b
5
5
  SHA512:
6
- metadata.gz: c1205ab3b90b586436aaeeb2f94ce4443acdbd372b72a6e1acda2cb250081f976e4b9743eb4f36bdc92d82dc0174d16289202c61128536a1ca440c64f5c3d923
7
- data.tar.gz: 3c8f039a3f9596fc78bb9fd79adf917e79a662b372f480da7aa0bf35a75a07d1b40cc20557c9038300b92e3f12f566ad512ad6a9aede7c4f18f11b3b778c8997
6
+ metadata.gz: '065287dc5984a1817a7d92142c806e15e23f3aca99d510fee6dfecb710c7d3eacfe2e755d37605f4055d4ec175f4cd0994367dd2b2cdf3de54f26c2cc89961b4'
7
+ data.tar.gz: a0ac7c9bdac412351c1581794942982213252e1b2d0907ed1727c3be384353c926d9865da30e2cbd694211f0ce4858c2032533b9ca8a215c33fcd76cec658cca
@@ -8,6 +8,12 @@
8
8
 
9
9
  * Your contribution here.
10
10
 
11
+ ### 0.4.1
12
+
13
+ #### Features
14
+
15
+ * [#58](https://github.com/bsm/grape-kaminari/pull/58): Allow to paginate without counting - [@dim](https://github.com/dim).
16
+
11
17
  ### 0.4.0
12
18
 
13
19
  #### Features
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape-kaminari (0.4.0)
4
+ grape-kaminari (0.4.1)
5
5
  grape (>= 1.0, != 1.4.0)
6
6
  kaminari-grape
7
7
 
@@ -58,7 +58,7 @@ GEM
58
58
  ruby2_keywords (~> 0.0.1)
59
59
  mustermann-grape (1.0.1)
60
60
  mustermann (>= 1.0.0)
61
- parallel (1.19.2)
61
+ parallel (1.20.0)
62
62
  parser (2.7.2.0)
63
63
  ast (~> 2.4.1)
64
64
  rack (2.2.3)
@@ -68,39 +68,39 @@ GEM
68
68
  rack (>= 1.0, < 3)
69
69
  rainbow (3.0.0)
70
70
  rake (13.0.1)
71
- regexp_parser (1.8.1)
71
+ regexp_parser (1.8.2)
72
72
  rexml (3.2.4)
73
- rspec (3.9.0)
74
- rspec-core (~> 3.9.0)
75
- rspec-expectations (~> 3.9.0)
76
- rspec-mocks (~> 3.9.0)
77
- rspec-core (3.9.3)
78
- rspec-support (~> 3.9.3)
79
- rspec-expectations (3.9.2)
73
+ rspec (3.10.0)
74
+ rspec-core (~> 3.10.0)
75
+ rspec-expectations (~> 3.10.0)
76
+ rspec-mocks (~> 3.10.0)
77
+ rspec-core (3.10.0)
78
+ rspec-support (~> 3.10.0)
79
+ rspec-expectations (3.10.0)
80
80
  diff-lcs (>= 1.2.0, < 2.0)
81
- rspec-support (~> 3.9.0)
82
- rspec-mocks (3.9.1)
81
+ rspec-support (~> 3.10.0)
82
+ rspec-mocks (3.10.0)
83
83
  diff-lcs (>= 1.2.0, < 2.0)
84
- rspec-support (~> 3.9.0)
85
- rspec-support (3.9.3)
86
- rubocop (0.92.0)
84
+ rspec-support (~> 3.10.0)
85
+ rspec-support (3.10.0)
86
+ rubocop (1.2.0)
87
87
  parallel (~> 1.10)
88
88
  parser (>= 2.7.1.5)
89
89
  rainbow (>= 2.2.2, < 4.0)
90
- regexp_parser (>= 1.7)
90
+ regexp_parser (>= 1.8)
91
91
  rexml
92
- rubocop-ast (>= 0.5.0)
92
+ rubocop-ast (>= 1.0.1)
93
93
  ruby-progressbar (~> 1.7)
94
94
  unicode-display_width (>= 1.4.0, < 2.0)
95
- rubocop-ast (0.7.1)
95
+ rubocop-ast (1.1.1)
96
96
  parser (>= 2.7.1.5)
97
97
  ruby-progressbar (1.10.1)
98
98
  ruby2_keywords (0.0.2)
99
99
  thread_safe (0.3.6)
100
- tzinfo (1.2.7)
100
+ tzinfo (1.2.8)
101
101
  thread_safe (~> 0.1)
102
102
  unicode-display_width (1.7.0)
103
- zeitwerk (2.4.0)
103
+ zeitwerk (2.4.1)
104
104
 
105
105
  PLATFORMS
106
106
  ruby
@@ -33,19 +33,23 @@ module Grape
33
33
  end
34
34
  end
35
35
 
36
- def paginate(collection)
37
- collection.page(params[:page].to_i)
38
- .per(params[:per_page].to_i)
39
- .padding(params[:offset].to_i)
40
- .tap do |data|
41
- header 'X-Total', data.total_count.to_s
42
- header 'X-Total-Pages', data.total_pages.to_s
43
- header 'X-Per-Page', data.limit_value.to_s
44
- header 'X-Page', data.current_page.to_s
45
- header 'X-Next-Page', data.next_page.to_s
46
- header 'X-Prev-Page', data.prev_page.to_s
47
- header 'X-Offset', params[:offset].to_s
36
+ def paginate(collection, without_count: false)
37
+ coll = collection.page(params[:page].to_i)
38
+ .per(params[:per_page].to_i)
39
+ .padding(params[:offset].to_i)
40
+ coll = coll.without_count if without_count && coll.respond_to?(:without_count)
41
+
42
+ unless without_count
43
+ header 'X-Total', coll.total_count.to_s
44
+ header 'X-Total-Pages', coll.total_pages.to_s
48
45
  end
46
+ header 'X-Per-Page', coll.limit_value.to_s
47
+ header 'X-Page', coll.current_page.to_s
48
+ header 'X-Next-Page', coll.next_page.to_s
49
+ header 'X-Prev-Page', coll.prev_page.to_s
50
+ header 'X-Offset', params[:offset].to_s
51
+
52
+ coll
49
53
  end
50
54
  end
51
55
 
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module Kaminari
3
- VERSION = '0.4.0'.freeze
3
+ VERSION = '0.4.1'.freeze
4
4
  end
5
5
  end
@@ -39,7 +39,7 @@ describe Grape::Kaminari do
39
39
 
40
40
  before do
41
41
  subject.params { use :pagination }
42
- subject.get('/') {}
42
+ subject.get('/') { 'OK' }
43
43
  end
44
44
 
45
45
  it 'does not require :page' do
@@ -101,7 +101,7 @@ describe 'custom paginated api' do
101
101
  subject.params do
102
102
  use :pagination, per_page: 99, max_per_page: 999, offset: 9
103
103
  end
104
- subject.get('/') {}
104
+ subject.get('/') { 'OK' }
105
105
  end
106
106
 
107
107
  it 'defaults :per_page to customized value' do
@@ -18,6 +18,13 @@ class PaginatedAPI < Grape::API
18
18
  paginate(Kaminari.paginate_array((1..10).to_a))
19
19
  end
20
20
 
21
+ params do
22
+ use :pagination, offset: false
23
+ end
24
+ get 'no-count' do
25
+ paginate(Kaminari.paginate_array((1..10).to_a), without_count: true)
26
+ end
27
+
21
28
  resource :sub do
22
29
  params do
23
30
  use :pagination, per_page: 2
@@ -52,15 +59,32 @@ describe Grape::Kaminari do
52
59
  expect(json).to eq [1, 2, 3]
53
60
  end
54
61
 
62
+ it 'works without count' do
63
+ get '/no-count', page: 2, per_page: 3
64
+ expect(json).to eq [4, 5, 6]
65
+ expect(header).to include(
66
+ 'X-Per-Page' => '3',
67
+ 'X-Page' => '2',
68
+ 'X-Next-Page' => '3',
69
+ 'X-Prev-Page' => '1',
70
+ )
71
+ expect(header).not_to include(
72
+ 'X-Total',
73
+ 'X-Total-Pages',
74
+ )
75
+ end
76
+
55
77
  it 'sets headers' do
56
78
  get '/', page: 3, per_page: 2, offset: 1
57
- expect(header['X-Total']).to eq '10'
58
- expect(header['X-Total-Pages']).to eq '5'
59
- expect(header['X-Per-Page']).to eq '2'
60
- expect(header['X-Page']).to eq '3'
61
- expect(header['X-Next-Page']).to eq '4'
62
- expect(header['X-Prev-Page']).to eq '2'
63
- expect(header['X-Offset']).to eq '1'
79
+ expect(header).to include(
80
+ 'X-Total' => '10',
81
+ 'X-Total-Pages' => '5',
82
+ 'X-Per-Page' => '2',
83
+ 'X-Page' => '3',
84
+ 'X-Next-Page' => '4',
85
+ 'X-Prev-Page' => '2',
86
+ 'X-Offset' => '1',
87
+ )
64
88
  end
65
89
 
66
90
  it 'can be inherited' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-kaminari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tymon Tobolski
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-10-08 00:00:00.000000000 Z
12
+ date: 2020-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grape