grape-pagy 0.3.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -2
- data/.gitignore +1 -1
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +53 -62
- data/README.md +2 -2
- data/grape-pagy.gemspec +4 -4
- data/lib/grape/pagy.rb +9 -7
- metadata +9 -18
- data/spec/grape/pagy_spec.rb +0 -92
- data/spec/spec_helper.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca339ac7f54bf525cd93e7df3da9e4d881ab83825c28e500afcb1774ad6a7991
|
4
|
+
data.tar.gz: 5bd4e7028e53d7b6ed9770d08298fe21b6e2253edc006906c652f2227b645cf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31f94b19fbf94f33622333385075376149a694653da7297864945f6cb9afd11a38b355fc63dd426e0d887b5b8b295f4c4969826aad07b7ced9fdf32048f556db
|
7
|
+
data.tar.gz: 8126538a4b3592a3eb259ebdbe597add3749ab9297a08494414dc571231ea5ebc2370b4fc9ad4aeac8bbafbfee8566fd447b4f3a6b67baa10b961d3c73d998d6
|
data/.github/workflows/ruby.yml
CHANGED
@@ -11,9 +11,9 @@ jobs:
|
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
strategy:
|
13
13
|
matrix:
|
14
|
-
ruby-version: ["
|
14
|
+
ruby-version: ["3.0", "3.1"]
|
15
15
|
steps:
|
16
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v3
|
17
17
|
- uses: ruby/setup-ruby@v1
|
18
18
|
with:
|
19
19
|
ruby-version: ${{ matrix.ruby-version }}
|
data/.gitignore
CHANGED
@@ -46,7 +46,7 @@ build-iPhoneSimulator/
|
|
46
46
|
# for a library or gem, you might want to ignore these files since the code is
|
47
47
|
# intended to run in multiple environments; otherwise, check them in:
|
48
48
|
# Gemfile.lock
|
49
|
-
|
49
|
+
.ruby-version
|
50
50
|
# .ruby-gemset
|
51
51
|
|
52
52
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,33 +1,28 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grape-pagy (0.
|
4
|
+
grape-pagy (0.5.1)
|
5
5
|
grape (>= 1.5)
|
6
|
-
pagy (>=
|
6
|
+
pagy (>= 5.4)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (
|
11
|
+
activesupport (7.0.3.1)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 1.6, < 2)
|
14
14
|
minitest (>= 5.1)
|
15
15
|
tzinfo (~> 2.0)
|
16
|
-
zeitwerk (~> 2.3)
|
17
16
|
ast (2.4.2)
|
18
17
|
builder (3.2.4)
|
19
|
-
concurrent-ruby (1.1.
|
20
|
-
diff-lcs (1.
|
21
|
-
dry-
|
18
|
+
concurrent-ruby (1.1.10)
|
19
|
+
diff-lcs (1.5.0)
|
20
|
+
dry-container (0.10.0)
|
22
21
|
concurrent-ruby (~> 1.0)
|
23
|
-
|
24
|
-
dry-container (0.7.2)
|
22
|
+
dry-core (0.8.0)
|
25
23
|
concurrent-ruby (~> 1.0)
|
26
|
-
|
27
|
-
dry-
|
28
|
-
concurrent-ruby (~> 1.0)
|
29
|
-
dry-inflector (0.2.0)
|
30
|
-
dry-logic (1.1.1)
|
24
|
+
dry-inflector (0.3.0)
|
25
|
+
dry-logic (1.2.0)
|
31
26
|
concurrent-ruby (~> 1.0)
|
32
27
|
dry-core (~> 0.5, >= 0.5)
|
33
28
|
dry-types (1.5.1)
|
@@ -36,81 +31,77 @@ GEM
|
|
36
31
|
dry-core (~> 0.5, >= 0.5)
|
37
32
|
dry-inflector (~> 0.1, >= 0.1.2)
|
38
33
|
dry-logic (~> 1.0, >= 1.0.2)
|
39
|
-
grape (1.
|
34
|
+
grape (1.6.2)
|
40
35
|
activesupport
|
41
36
|
builder
|
42
37
|
dry-types (>= 1.1)
|
43
38
|
mustermann-grape (~> 1.0.0)
|
44
39
|
rack (>= 1.3.0)
|
45
40
|
rack-accept
|
46
|
-
i18n (1.
|
41
|
+
i18n (1.12.0)
|
47
42
|
concurrent-ruby (~> 1.0)
|
48
|
-
|
49
|
-
|
43
|
+
json (2.6.2)
|
44
|
+
minitest (5.16.2)
|
45
|
+
mustermann (2.0.1)
|
50
46
|
ruby2_keywords (~> 0.0.1)
|
51
|
-
mustermann-grape (1.0.
|
47
|
+
mustermann-grape (1.0.2)
|
52
48
|
mustermann (>= 1.0.0)
|
53
|
-
pagy (
|
54
|
-
|
55
|
-
|
49
|
+
pagy (5.10.1)
|
50
|
+
activesupport
|
51
|
+
parallel (1.22.1)
|
52
|
+
parser (3.1.2.0)
|
56
53
|
ast (~> 2.4.1)
|
57
|
-
rack (2.2.
|
54
|
+
rack (2.2.4)
|
58
55
|
rack-accept (0.4.5)
|
59
56
|
rack (>= 0.4)
|
60
|
-
rack-test (
|
61
|
-
rack (>= 1.
|
62
|
-
rainbow (3.
|
63
|
-
rake (13.0.
|
64
|
-
regexp_parser (2.
|
57
|
+
rack-test (2.0.2)
|
58
|
+
rack (>= 1.3)
|
59
|
+
rainbow (3.1.1)
|
60
|
+
rake (13.0.6)
|
61
|
+
regexp_parser (2.5.0)
|
65
62
|
rexml (3.2.5)
|
66
|
-
rspec (3.
|
67
|
-
rspec-core (~> 3.
|
68
|
-
rspec-expectations (~> 3.
|
69
|
-
rspec-mocks (~> 3.
|
70
|
-
rspec-core (3.
|
71
|
-
rspec-support (~> 3.
|
72
|
-
rspec-expectations (3.
|
63
|
+
rspec (3.11.0)
|
64
|
+
rspec-core (~> 3.11.0)
|
65
|
+
rspec-expectations (~> 3.11.0)
|
66
|
+
rspec-mocks (~> 3.11.0)
|
67
|
+
rspec-core (3.11.0)
|
68
|
+
rspec-support (~> 3.11.0)
|
69
|
+
rspec-expectations (3.11.0)
|
73
70
|
diff-lcs (>= 1.2.0, < 2.0)
|
74
|
-
rspec-support (~> 3.
|
75
|
-
rspec-mocks (3.
|
71
|
+
rspec-support (~> 3.11.0)
|
72
|
+
rspec-mocks (3.11.1)
|
76
73
|
diff-lcs (>= 1.2.0, < 2.0)
|
77
|
-
rspec-support (~> 3.
|
78
|
-
rspec-support (3.
|
79
|
-
rubocop (1.
|
74
|
+
rspec-support (~> 3.11.0)
|
75
|
+
rspec-support (3.11.0)
|
76
|
+
rubocop (1.31.2)
|
77
|
+
json (~> 2.3)
|
80
78
|
parallel (~> 1.10)
|
81
|
-
parser (>= 3.
|
79
|
+
parser (>= 3.1.0.0)
|
82
80
|
rainbow (>= 2.2.2, < 4.0)
|
83
81
|
regexp_parser (>= 1.8, < 3.0)
|
84
|
-
rexml
|
85
|
-
rubocop-ast (>= 1.
|
82
|
+
rexml (>= 3.2.5, < 4.0)
|
83
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
86
84
|
ruby-progressbar (~> 1.7)
|
87
85
|
unicode-display_width (>= 1.4.0, < 3.0)
|
88
|
-
rubocop-ast (1.
|
89
|
-
parser (>=
|
90
|
-
rubocop-bsm (0.
|
86
|
+
rubocop-ast (1.19.1)
|
87
|
+
parser (>= 3.1.1.0)
|
88
|
+
rubocop-bsm (0.6.0)
|
91
89
|
rubocop (~> 1.0)
|
92
90
|
rubocop-performance
|
93
|
-
rubocop-rails
|
94
91
|
rubocop-rake
|
95
92
|
rubocop-rspec
|
96
|
-
rubocop-performance (1.
|
97
|
-
rubocop (>=
|
93
|
+
rubocop-performance (1.14.3)
|
94
|
+
rubocop (>= 1.7.0, < 2.0)
|
98
95
|
rubocop-ast (>= 0.4.0)
|
99
|
-
rubocop-
|
100
|
-
activesupport (>= 4.2.0)
|
101
|
-
rack (>= 1.1)
|
102
|
-
rubocop (>= 0.90.0, < 2.0)
|
103
|
-
rubocop-rake (0.5.1)
|
104
|
-
rubocop
|
105
|
-
rubocop-rspec (2.2.0)
|
96
|
+
rubocop-rake (0.6.0)
|
106
97
|
rubocop (~> 1.0)
|
107
|
-
|
98
|
+
rubocop-rspec (2.12.1)
|
99
|
+
rubocop (~> 1.31)
|
108
100
|
ruby-progressbar (1.11.0)
|
109
|
-
ruby2_keywords (0.0.
|
110
|
-
tzinfo (2.0.
|
101
|
+
ruby2_keywords (0.0.5)
|
102
|
+
tzinfo (2.0.5)
|
111
103
|
concurrent-ruby (~> 1.0)
|
112
|
-
unicode-display_width (2.
|
113
|
-
zeitwerk (2.4.2)
|
104
|
+
unicode-display_width (2.2.0)
|
114
105
|
|
115
106
|
PLATFORMS
|
116
107
|
ruby
|
@@ -124,4 +115,4 @@ DEPENDENCIES
|
|
124
115
|
rubocop-bsm
|
125
116
|
|
126
117
|
BUNDLED WITH
|
127
|
-
2.
|
118
|
+
2.3.16
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Grape::Pagy
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Ruby](https://github.com/bsm/grape-pagy/actions/workflows/ruby.yml/badge.svg)](https://github.com/bsm/grape-pagy/actions/workflows/ruby.yml)
|
4
4
|
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
|
5
5
|
|
6
6
|
[Pagy](https://github.com/ddnexus/pagy) pagination for [grape](https://github.com/ruby-grape/grape) API framework.
|
@@ -47,7 +47,7 @@ class MyApi < Grape::API
|
|
47
47
|
resource :strings do
|
48
48
|
desc 'Supports arrays as well as relations.'
|
49
49
|
params do
|
50
|
-
# Override defaults by setting Pagy::
|
50
|
+
# Override defaults by setting Pagy::DEFAULT or by passing options.
|
51
51
|
use :pagy,
|
52
52
|
items_param: :per_page, # Accept per_page=N param to limit items.
|
53
53
|
items: 2, # If per_page param is blank, default to 2.
|
data/grape-pagy.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'grape-pagy'
|
3
|
-
spec.version = '0.
|
3
|
+
spec.version = '0.5.1'
|
4
4
|
spec.authors = ['Black Square Media']
|
5
5
|
spec.email = ['info@blacksquaremedia.com']
|
6
6
|
spec.description = 'Pagy paginator for grape API'
|
@@ -9,16 +9,16 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.license = 'Apache-2.0'
|
10
10
|
|
11
11
|
spec.files = `git ls-files -z`.split("\x0").reject {|f| f.start_with?('spec/') }
|
12
|
-
spec.test_files = `git ls-files -z -- spec/*`.split("\x0")
|
13
12
|
spec.require_paths = ['lib']
|
14
|
-
spec.required_ruby_version = '>=
|
13
|
+
spec.required_ruby_version = '>= 3.0'
|
15
14
|
|
16
15
|
spec.add_runtime_dependency 'grape', '>= 1.5'
|
17
|
-
spec.add_runtime_dependency 'pagy', '>=
|
16
|
+
spec.add_runtime_dependency 'pagy', '>= 5.4'
|
18
17
|
|
19
18
|
spec.add_development_dependency 'bundler'
|
20
19
|
spec.add_development_dependency 'rack-test'
|
21
20
|
spec.add_development_dependency 'rake'
|
22
21
|
spec.add_development_dependency 'rspec'
|
23
22
|
spec.add_development_dependency 'rubocop-bsm'
|
23
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
24
24
|
end
|
data/lib/grape/pagy.rb
CHANGED
@@ -13,7 +13,7 @@ module Grape
|
|
13
13
|
include ::Pagy::Backend
|
14
14
|
|
15
15
|
def paginate(collection, using: nil, **opts, &block)
|
16
|
-
|
16
|
+
opts = pagy_countless_get_vars(nil, opts)
|
17
17
|
using ||= if collection.respond_to?(:arel_table)
|
18
18
|
:arel
|
19
19
|
elsif collection.is_a?(Array)
|
@@ -31,20 +31,22 @@ module Grape
|
|
31
31
|
module Helpers
|
32
32
|
extend Grape::API::Helpers
|
33
33
|
|
34
|
-
params :pagy do |
|
35
|
-
items
|
36
|
-
page
|
37
|
-
page_param = opts[:page_param] || ::Pagy::
|
38
|
-
items_param = opts[:items_param] || ::Pagy::
|
34
|
+
params :pagy do |opts|
|
35
|
+
items = opts.delete(:items) || ::Pagy::DEFAULT[:items]
|
36
|
+
page = opts.delete(:page) || ::Pagy::DEFAULT[:page]
|
37
|
+
page_param = opts[:page_param] || ::Pagy::DEFAULT[:page_param]
|
38
|
+
items_param = opts[:items_param] || ::Pagy::DEFAULT[:items_param]
|
39
|
+
max_items = opts[:max_items] || ::Pagy::DEFAULT[:max_items]
|
39
40
|
|
40
41
|
@api.route_setting(:pagy_options, opts)
|
41
42
|
optional page_param, type: Integer, default: page, desc: 'Page offset to fetch.'
|
42
|
-
optional items_param, type: Integer, default: items, desc:
|
43
|
+
optional items_param, type: Integer, default: items, desc: "Number of items to return per page. Maximum value: #{max_items}"
|
43
44
|
end
|
44
45
|
|
45
46
|
# @param [Array|ActiveRecord::Relation] collection the collection or relation.
|
46
47
|
def pagy(collection, **opts)
|
47
48
|
defaults = route_setting(:pagy_options) || {}
|
49
|
+
|
48
50
|
Wrapper.new(request, params).paginate(collection, **defaults, **opts) do |key, value|
|
49
51
|
header key, value
|
50
52
|
end
|
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.5.1
|
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:
|
11
|
+
date: 2022-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -30,20 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
- - "<"
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: '4.0'
|
33
|
+
version: '5.4'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - ">="
|
42
39
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
44
|
-
- - "<"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '4.0'
|
40
|
+
version: '5.4'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: bundler
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,12 +127,11 @@ files:
|
|
133
127
|
- grape-pagy.gemspec
|
134
128
|
- lib/grape-pagy.rb
|
135
129
|
- lib/grape/pagy.rb
|
136
|
-
- spec/grape/pagy_spec.rb
|
137
|
-
- spec/spec_helper.rb
|
138
130
|
homepage: ''
|
139
131
|
licenses:
|
140
132
|
- Apache-2.0
|
141
|
-
metadata:
|
133
|
+
metadata:
|
134
|
+
rubygems_mfa_required: 'true'
|
142
135
|
post_install_message:
|
143
136
|
rdoc_options: []
|
144
137
|
require_paths:
|
@@ -147,17 +140,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
140
|
requirements:
|
148
141
|
- - ">="
|
149
142
|
- !ruby/object:Gem::Version
|
150
|
-
version: '
|
143
|
+
version: '3.0'
|
151
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
145
|
requirements:
|
153
146
|
- - ">="
|
154
147
|
- !ruby/object:Gem::Version
|
155
148
|
version: '0'
|
156
149
|
requirements: []
|
157
|
-
rubygems_version: 3.
|
150
|
+
rubygems_version: 3.3.3
|
158
151
|
signing_key:
|
159
152
|
specification_version: 4
|
160
153
|
summary: ''
|
161
|
-
test_files:
|
162
|
-
- spec/grape/pagy_spec.rb
|
163
|
-
- spec/spec_helper.rb
|
154
|
+
test_files: []
|
data/spec/grape/pagy_spec.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Grape::Pagy do
|
4
|
-
include Rack::Test::Methods
|
5
|
-
|
6
|
-
let(:app) { TestAPI }
|
7
|
-
|
8
|
-
it 'paginates' do
|
9
|
-
get '/'
|
10
|
-
expect(last_response.status).to eq(200)
|
11
|
-
expect(last_response.headers).to include(
|
12
|
-
'Current-Page' => '1',
|
13
|
-
'Link' => %(<http://example.org/?page=1>; rel="first", <http://example.org/?page=2>; rel="next", <http://example.org/?page=3>; rel="last"),
|
14
|
-
'Page-Items' => '5',
|
15
|
-
'Total-Count' => '12',
|
16
|
-
'Total-Pages' => '3',
|
17
|
-
)
|
18
|
-
expect(last_response.body).to eq(%([1, 2, 3, 4, 5]))
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'accepts page and items parameters' do
|
22
|
-
get '/?page=2&items=3'
|
23
|
-
expect(last_response.status).to eq(200)
|
24
|
-
expect(last_response.headers).to include(
|
25
|
-
'Current-Page' => '2',
|
26
|
-
'Page-Items' => '3',
|
27
|
-
'Total-Count' => '12',
|
28
|
-
'Total-Pages' => '4',
|
29
|
-
)
|
30
|
-
expect(last_response.body).to eq(%([4, 5, 6]))
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'caps items' do
|
34
|
-
get '/?items=10'
|
35
|
-
expect(last_response.headers).to include('Page-Items' => '6')
|
36
|
-
expect(last_response.body).to eq(%([1, 2, 3, 4, 5, 6]))
|
37
|
-
|
38
|
-
get '/?items=3'
|
39
|
-
expect(last_response.headers).to include('Page-Items' => '3')
|
40
|
-
expect(last_response.body).to eq(%([1, 2, 3]))
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'ignores overflow' do
|
44
|
-
get '/?page=99'
|
45
|
-
expect(last_response.status).to eq(200)
|
46
|
-
expect(last_response.headers).to include(
|
47
|
-
'Current-Page' => '99',
|
48
|
-
'Total-Pages' => '3',
|
49
|
-
)
|
50
|
-
expect(last_response.body).to eq(%([]))
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'allows 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
|
-
|
72
|
-
it 'inherits helper' do
|
73
|
-
get '/sub'
|
74
|
-
expect(last_response.status).to eq(200)
|
75
|
-
expect(last_response.headers).to include(
|
76
|
-
'Current-Page' => '1',
|
77
|
-
'Page-Items' => '10',
|
78
|
-
'Total-Count' => '13',
|
79
|
-
'Total-Pages' => '2',
|
80
|
-
)
|
81
|
-
expect(last_response.body).to eq(%([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
|
82
|
-
|
83
|
-
get '/sub?per_page=20'
|
84
|
-
expect(last_response.status).to eq(200)
|
85
|
-
expect(last_response.headers).to include(
|
86
|
-
'Current-Page' => '1',
|
87
|
-
'Page-Items' => '20',
|
88
|
-
'Total-Count' => '13',
|
89
|
-
'Total-Pages' => '1',
|
90
|
-
)
|
91
|
-
end
|
92
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
ENV['RACK_ENV'] ||= 'test'
|
2
|
-
|
3
|
-
require 'rspec'
|
4
|
-
require 'grape/pagy'
|
5
|
-
require 'rack/test'
|
6
|
-
|
7
|
-
Pagy::VARS[:items] = 10
|
8
|
-
Pagy::VARS[:max_items] = 20
|
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
|
-
|
20
|
-
class TestAPI < Grape::API
|
21
|
-
helpers Grape::Pagy::Helpers
|
22
|
-
|
23
|
-
params do
|
24
|
-
use :pagy, items: 5, max_items: 6
|
25
|
-
end
|
26
|
-
get '' do
|
27
|
-
pagy (1..12).to_a
|
28
|
-
end
|
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
|
-
|
37
|
-
resource :sub do
|
38
|
-
params do
|
39
|
-
use :pagy, items_param: :per_page
|
40
|
-
end
|
41
|
-
get '/' do
|
42
|
-
pagy (1..12).to_a, count: 13
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
RSpec.configure do |config|
|
48
|
-
config.include Rack::Test::Methods
|
49
|
-
config.raise_errors_for_deprecations!
|
50
|
-
end
|