grape-pagy 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +3 -3
- data/grape-pagy.gemspec +1 -1
- data/lib/grape/pagy.rb +8 -7
- data/spec/grape/pagy_spec.rb +19 -0
- data/spec/spec_helper.rb +17 -0
- 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: 5956682171c97b589bba13991d1f810f73bcdbc95ef24ca169d16a4f19085713
|
4
|
+
data.tar.gz: 590ec8ca32ad36c166875b095e874036b46f45f0c32a53999ee8f7f083cfb0b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77257d503b9a5ab54e33d722f971ff2b095e0317010820f6388f1a1a19eaff47fc5fb1baae3a83b856eb26e2561f140df3d084b1055dfd297ffd5aadbb92a30a
|
7
|
+
data.tar.gz: a8491d340672664083ebebfb4b66df017a8272eade89966a8a38bf92be001ee526ce8d1b9efe105a09caf0e580a533687b2dd913d0a2077bc3071e3e45a1c302
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grape-pagy (0.
|
4
|
+
grape-pagy (0.3.0)
|
5
5
|
grape (>= 1.5)
|
6
6
|
pagy
|
7
7
|
|
@@ -94,10 +94,10 @@ GEM
|
|
94
94
|
ruby-progressbar (1.10.1)
|
95
95
|
ruby2_keywords (0.0.2)
|
96
96
|
thread_safe (0.3.6)
|
97
|
-
tzinfo (1.2.
|
97
|
+
tzinfo (1.2.8)
|
98
98
|
thread_safe (~> 0.1)
|
99
99
|
unicode-display_width (1.7.0)
|
100
|
-
zeitwerk (2.4.
|
100
|
+
zeitwerk (2.4.1)
|
101
101
|
|
102
102
|
PLATFORMS
|
103
103
|
ruby
|
data/grape-pagy.gemspec
CHANGED
data/lib/grape/pagy.rb
CHANGED
@@ -2,6 +2,7 @@ require 'grape'
|
|
2
2
|
require 'pagy'
|
3
3
|
require 'pagy/extras/arel'
|
4
4
|
require 'pagy/extras/array'
|
5
|
+
require 'pagy/extras/countless'
|
5
6
|
require 'pagy/extras/headers'
|
6
7
|
require 'pagy/extras/items'
|
7
8
|
require 'pagy/extras/overflow'
|
@@ -11,15 +12,15 @@ module Grape
|
|
11
12
|
Wrapper = Struct.new :request, :params do
|
12
13
|
include ::Pagy::Backend
|
13
14
|
|
14
|
-
def paginate(collection,
|
15
|
+
def paginate(collection, using: nil, **opts, &block)
|
15
16
|
pagy_with_items(opts)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
using ||= if collection.respond_to?(:arel_table)
|
18
|
+
:arel
|
19
|
+
elsif collection.is_a?(Array)
|
20
|
+
:array
|
21
|
+
end
|
21
22
|
|
22
|
-
method = [:pagy,
|
23
|
+
method = [:pagy, using].compact.join('_')
|
23
24
|
page, scope = send(method, collection, **opts)
|
24
25
|
|
25
26
|
pagy_headers(page).each(&block)
|
data/spec/grape/pagy_spec.rb
CHANGED
@@ -50,6 +50,25 @@ describe Grape::Pagy do
|
|
50
50
|
expect(last_response.body).to eq(%([]))
|
51
51
|
end
|
52
52
|
|
53
|
+
it 'should allow countless mode' do
|
54
|
+
get '/countless?page=2'
|
55
|
+
expect(last_response.status).to eq(200)
|
56
|
+
expect(last_response.headers).to include(
|
57
|
+
'Current-Page' => '2',
|
58
|
+
'Page-Items' => '3',
|
59
|
+
'Link' => [
|
60
|
+
%(<http://example.org/countless?page=1>; rel="first"),
|
61
|
+
%(<http://example.org/countless?page=1>; rel="prev"),
|
62
|
+
%(<http://example.org/countless?page=3>; rel="next"),
|
63
|
+
].join(', '),
|
64
|
+
)
|
65
|
+
expect(last_response.headers).not_to include(
|
66
|
+
'Total-Count',
|
67
|
+
'Total-Pages',
|
68
|
+
)
|
69
|
+
expect(last_response.body).to eq(%([4, 5, 6]))
|
70
|
+
end
|
71
|
+
|
53
72
|
it 'should inherit helper' do
|
54
73
|
get '/sub'
|
55
74
|
expect(last_response.status).to eq(200)
|
data/spec/spec_helper.rb
CHANGED
@@ -7,6 +7,16 @@ require 'rack/test'
|
|
7
7
|
Pagy::VARS[:items] = 10
|
8
8
|
Pagy::VARS[:max_items] = 20
|
9
9
|
|
10
|
+
class TestArray < Array
|
11
|
+
def limit(num)
|
12
|
+
slice!(0, num)
|
13
|
+
end
|
14
|
+
|
15
|
+
def offset(num)
|
16
|
+
slice!(num..-1)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
10
20
|
class TestAPI < Grape::API
|
11
21
|
helpers Grape::Pagy::Helpers
|
12
22
|
|
@@ -17,6 +27,13 @@ class TestAPI < Grape::API
|
|
17
27
|
pagy (1..12).to_a
|
18
28
|
end
|
19
29
|
|
30
|
+
params do
|
31
|
+
use :pagy, items: 3
|
32
|
+
end
|
33
|
+
get '/countless' do
|
34
|
+
pagy TestArray.new((1..12).to_a), using: :countless
|
35
|
+
end
|
36
|
+
|
20
37
|
resource :sub do
|
21
38
|
params do
|
22
39
|
use :pagy, items_param: :per_page
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-pagy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Black Square Media
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|