grape-kaminari 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +20 -20
- data/lib/grape/kaminari.rb +16 -12
- data/lib/grape/kaminari/version.rb +1 -1
- data/spec/kaminari_spec.rb +2 -2
- data/spec/paginate_helper_spec.rb +31 -7
- 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: d524d760fab53973250ae175e7e484a22c0e1d76ca3a427b42d51118660fd708
|
4
|
+
data.tar.gz: 2c1e66d494b6b2dafdd9e7831022a7f1a6b8b10652d19acc897da2f3b150d52b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '065287dc5984a1817a7d92142c806e15e23f3aca99d510fee6dfecb710c7d3eacfe2e755d37605f4055d4ec175f4cd0994367dd2b2cdf3de54f26c2cc89961b4'
|
7
|
+
data.tar.gz: a0ac7c9bdac412351c1581794942982213252e1b2d0907ed1727c3be384353c926d9865da30e2cbd694211f0ce4858c2032533b9ca8a215c33fcd76cec658cca
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grape-kaminari (0.4.
|
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.
|
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.
|
71
|
+
regexp_parser (1.8.2)
|
72
72
|
rexml (3.2.4)
|
73
|
-
rspec (3.
|
74
|
-
rspec-core (~> 3.
|
75
|
-
rspec-expectations (~> 3.
|
76
|
-
rspec-mocks (~> 3.
|
77
|
-
rspec-core (3.
|
78
|
-
rspec-support (~> 3.
|
79
|
-
rspec-expectations (3.
|
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.
|
82
|
-
rspec-mocks (3.
|
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.
|
85
|
-
rspec-support (3.
|
86
|
-
rubocop (
|
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.
|
90
|
+
regexp_parser (>= 1.8)
|
91
91
|
rexml
|
92
|
-
rubocop-ast (>= 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 (
|
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.
|
100
|
+
tzinfo (1.2.8)
|
101
101
|
thread_safe (~> 0.1)
|
102
102
|
unicode-display_width (1.7.0)
|
103
|
-
zeitwerk (2.4.
|
103
|
+
zeitwerk (2.4.1)
|
104
104
|
|
105
105
|
PLATFORMS
|
106
106
|
ruby
|
data/lib/grape/kaminari.rb
CHANGED
@@ -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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
header 'X-
|
44
|
-
header 'X-
|
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
|
|
data/spec/kaminari_spec.rb
CHANGED
@@ -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
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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.
|
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-
|
12
|
+
date: 2020-11-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grape
|