grape-pagy 0.2.0 → 0.5.0

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: ae85f7bb6472d19bcbedad2d0e03e0960a75615960819251b1a35ed793a0cb65
4
- data.tar.gz: 3fa36e9bcd909ae16e54c44c0c9b65499fa8f4ad7dbf94c75b8d7192897932b5
3
+ metadata.gz: 5cf4286de9e78c7b5a4f4f9ea1fdf9ad8c5e688a64b44e4551c26e300509d42c
4
+ data.tar.gz: ca06ad206ff3fb7dadc9dcf9f37848afd58645d35f9b8af0dbe7819182694c1e
5
5
  SHA512:
6
- metadata.gz: 74772e142b4277e609bdca9ce59e5a3de4ed35e940fbbf3a8a0dd79122bdacf9327acf832177b9ce92cb074a81be34c1fae30ea9a2871e36800ba6d19fd68905
7
- data.tar.gz: 65407c449ede7a7cfa7a3e1d7428530bc761b5c776a30a0db90baeacd234596e7b5fc933e34d50aa8cbf2011359a65a68bd9e9f29819c637edb1986f2a66a36e
6
+ metadata.gz: 0b6094898f98b12b1bf636963d9e3254efa554469f6a179c0ea047022955c9f716c01c1961756d31b53a77f18947026d1929e4eaea80352de47771c2f92769c9
7
+ data.tar.gz: 8141124754f358828ae5c248fac72acd3dcd4788aac64b3db54e9afbcbbc7b7e366739227c0e081b5249d6e010e6596293f18f06e1dfe5286241bc46b0ed4ac7
@@ -0,0 +1,21 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ["3.0"]
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby-version }}
20
+ bundler-cache: true
21
+ - run: bundle exec rake
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
- # .ruby-version
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
@@ -1,8 +1,12 @@
1
- inherit_from:
2
- - https://gitlab.com/bsm/misc/raw/master/rubocop/default.yml
1
+ inherit_gem:
2
+ rubocop-bsm:
3
+ - default.yml
4
+ inherit_mode:
5
+ merge:
6
+ - Exclude
3
7
 
4
8
  AllCops:
5
- TargetRubyVersion: "2.5"
9
+ TargetRubyVersion: "3.0"
6
10
 
7
11
  Naming/FileName:
8
12
  Exclude: ["lib/grape-pagy.rb"]
data/CHANGELOG.md CHANGED
@@ -1,7 +1,23 @@
1
- ### 0.2.0
1
+ ### 0.5.0
2
2
 
3
- * Improved, simplified and stabilised API [#1](https://github.com/bsm/grape-pagy/pull/1).
3
+ - Pin to Pagy 5.x.
4
4
 
5
- ### 0.1.0
5
+ ### 0.4.0
6
6
 
7
- * Initial release.
7
+ - Pin to Pagy 4.x.
8
+
9
+ ### 0.3.1
10
+
11
+ - Pin to Pagy 3.x.
12
+
13
+ ## 0.3.0
14
+
15
+ - Allow countless usage [#2](https://github.com/bsm/grape-pagy/pull/2).
16
+
17
+ ## 0.2.0
18
+
19
+ - Improved, simplified and stabilised API [#1](https://github.com/bsm/grape-pagy/pull/1).
20
+
21
+ ## 0.1.0
22
+
23
+ - Initial release.
data/Gemfile.lock CHANGED
@@ -1,62 +1,58 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape-pagy (0.2.0)
4
+ grape-pagy (0.5.0)
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 (6.0.3.4)
11
+ activesupport (6.1.3.1)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- zeitwerk (~> 2.2, >= 2.2.2)
17
- ast (2.4.1)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ ast (2.4.2)
18
18
  builder (3.2.4)
19
- concurrent-ruby (1.1.7)
19
+ concurrent-ruby (1.1.8)
20
20
  diff-lcs (1.4.4)
21
- dry-configurable (0.11.6)
21
+ dry-configurable (0.13.0)
22
22
  concurrent-ruby (~> 1.0)
23
- dry-core (~> 0.4, >= 0.4.7)
24
- dry-equalizer (~> 0.2)
25
- dry-container (0.7.2)
23
+ dry-core (~> 0.6)
24
+ dry-container (0.9.0)
26
25
  concurrent-ruby (~> 1.0)
27
- dry-configurable (~> 0.1, >= 0.1.3)
28
- dry-core (0.4.9)
26
+ dry-configurable (~> 0.13, >= 0.13.0)
27
+ dry-core (0.7.1)
29
28
  concurrent-ruby (~> 1.0)
30
- dry-equalizer (0.3.0)
31
- dry-inflector (0.2.0)
32
- dry-logic (1.0.8)
29
+ dry-inflector (0.2.1)
30
+ dry-logic (1.2.0)
33
31
  concurrent-ruby (~> 1.0)
34
- dry-core (~> 0.2)
35
- dry-equalizer (~> 0.2)
36
- dry-types (1.4.0)
32
+ dry-core (~> 0.5, >= 0.5)
33
+ dry-types (1.5.1)
37
34
  concurrent-ruby (~> 1.0)
38
35
  dry-container (~> 0.3)
39
- dry-core (~> 0.4, >= 0.4.4)
40
- dry-equalizer (~> 0.3)
36
+ dry-core (~> 0.5, >= 0.5)
41
37
  dry-inflector (~> 0.1, >= 0.1.2)
42
38
  dry-logic (~> 1.0, >= 1.0.2)
43
- grape (1.5.0)
39
+ grape (1.6.0)
44
40
  activesupport
45
41
  builder
46
42
  dry-types (>= 1.1)
47
43
  mustermann-grape (~> 1.0.0)
48
44
  rack (>= 1.3.0)
49
45
  rack-accept
50
- i18n (1.8.5)
46
+ i18n (1.8.10)
51
47
  concurrent-ruby (~> 1.0)
52
- minitest (5.14.2)
48
+ minitest (5.14.4)
53
49
  mustermann (1.1.1)
54
50
  ruby2_keywords (~> 0.0.1)
55
51
  mustermann-grape (1.0.1)
56
52
  mustermann (>= 1.0.0)
57
- pagy (3.8.3)
58
- parallel (1.19.2)
59
- parser (2.7.2.0)
53
+ pagy (5.4.0)
54
+ parallel (1.20.1)
55
+ parser (3.0.1.0)
60
56
  ast (~> 2.4.1)
61
57
  rack (2.2.3)
62
58
  rack-accept (0.4.5)
@@ -64,40 +60,57 @@ GEM
64
60
  rack-test (1.1.0)
65
61
  rack (>= 1.0, < 3)
66
62
  rainbow (3.0.0)
67
- rake (13.0.1)
68
- regexp_parser (1.8.1)
69
- rexml (3.2.4)
70
- rspec (3.9.0)
71
- rspec-core (~> 3.9.0)
72
- rspec-expectations (~> 3.9.0)
73
- rspec-mocks (~> 3.9.0)
74
- rspec-core (3.9.3)
75
- rspec-support (~> 3.9.3)
76
- rspec-expectations (3.9.2)
63
+ rake (13.0.3)
64
+ regexp_parser (2.1.1)
65
+ rexml (3.2.5)
66
+ rspec (3.10.0)
67
+ rspec-core (~> 3.10.0)
68
+ rspec-expectations (~> 3.10.0)
69
+ rspec-mocks (~> 3.10.0)
70
+ rspec-core (3.10.1)
71
+ rspec-support (~> 3.10.0)
72
+ rspec-expectations (3.10.1)
77
73
  diff-lcs (>= 1.2.0, < 2.0)
78
- rspec-support (~> 3.9.0)
79
- rspec-mocks (3.9.1)
74
+ rspec-support (~> 3.10.0)
75
+ rspec-mocks (3.10.2)
80
76
  diff-lcs (>= 1.2.0, < 2.0)
81
- rspec-support (~> 3.9.0)
82
- rspec-support (3.9.3)
83
- rubocop (0.92.0)
77
+ rspec-support (~> 3.10.0)
78
+ rspec-support (3.10.2)
79
+ rubocop (1.13.0)
84
80
  parallel (~> 1.10)
85
- parser (>= 2.7.1.5)
81
+ parser (>= 3.0.0.0)
86
82
  rainbow (>= 2.2.2, < 4.0)
87
- regexp_parser (>= 1.7)
83
+ regexp_parser (>= 1.8, < 3.0)
88
84
  rexml
89
- rubocop-ast (>= 0.5.0)
85
+ rubocop-ast (>= 1.2.0, < 2.0)
90
86
  ruby-progressbar (~> 1.7)
91
- unicode-display_width (>= 1.4.0, < 2.0)
92
- rubocop-ast (0.7.1)
87
+ unicode-display_width (>= 1.4.0, < 3.0)
88
+ rubocop-ast (1.4.1)
93
89
  parser (>= 2.7.1.5)
94
- ruby-progressbar (1.10.1)
95
- ruby2_keywords (0.0.2)
96
- thread_safe (0.3.6)
97
- tzinfo (1.2.7)
98
- thread_safe (~> 0.1)
99
- unicode-display_width (1.7.0)
100
- zeitwerk (2.4.0)
90
+ rubocop-bsm (0.5.8)
91
+ rubocop (~> 1.0)
92
+ rubocop-performance
93
+ rubocop-rails
94
+ rubocop-rake
95
+ rubocop-rspec
96
+ rubocop-performance (1.10.2)
97
+ rubocop (>= 0.90.0, < 2.0)
98
+ rubocop-ast (>= 0.4.0)
99
+ rubocop-rails (2.9.1)
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)
106
+ rubocop (~> 1.0)
107
+ rubocop-ast (>= 1.1.0)
108
+ ruby-progressbar (1.11.0)
109
+ ruby2_keywords (0.0.5)
110
+ tzinfo (2.0.4)
111
+ concurrent-ruby (~> 1.0)
112
+ unicode-display_width (2.0.0)
113
+ zeitwerk (2.4.2)
101
114
 
102
115
  PLATFORMS
103
116
  ruby
@@ -108,7 +121,7 @@ DEPENDENCIES
108
121
  rack-test
109
122
  rake
110
123
  rspec
111
- rubocop
124
+ rubocop-bsm
112
125
 
113
126
  BUNDLED WITH
114
- 2.1.4
127
+ 2.2.21
data/LICENSE CHANGED
@@ -1,13 +1,201 @@
1
- Copyright 2020 Black Square Media Ltd
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
2
4
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
6
 
7
- http://www.apache.org/licenses/LICENSE-2.0
7
+ 1. Definitions.
8
8
 
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2021 Black Square Media Ltd
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Grape::Pagy
2
2
 
3
- [![Build Status](https://travis-ci.org/bsm/grape-pagy.png?branch=master)](https://travis-ci.org/bsm/grape-pagy)
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::VARS or by passing options.
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.2.0'
3
+ spec.version = '0.5.0'
4
4
  spec.authors = ['Black Square Media']
5
5
  spec.email = ['info@blacksquaremedia.com']
6
6
  spec.description = 'Pagy paginator for grape API'
@@ -11,14 +11,14 @@ Gem::Specification.new do |spec|
11
11
  spec.files = `git ls-files -z`.split("\x0").reject {|f| f.start_with?('spec/') }
12
12
  spec.test_files = `git ls-files -z -- spec/*`.split("\x0")
13
13
  spec.require_paths = ['lib']
14
- spec.required_ruby_version = '>= 2.5'
14
+ spec.required_ruby_version = '>= 3.0'
15
15
 
16
16
  spec.add_runtime_dependency 'grape', '>= 1.5'
17
- spec.add_runtime_dependency 'pagy'
17
+ spec.add_runtime_dependency 'pagy', '>= 5.4'
18
18
 
19
19
  spec.add_development_dependency 'bundler'
20
20
  spec.add_development_dependency 'rack-test'
21
21
  spec.add_development_dependency 'rake'
22
22
  spec.add_development_dependency 'rspec'
23
- spec.add_development_dependency 'rubocop'
23
+ spec.add_development_dependency 'rubocop-bsm'
24
24
  end
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, via: nil, **opts, &block)
15
- pagy_with_items(opts)
16
- via ||= if collection.respond_to?(:arel_table)
17
- :arel
18
- elsif collection.is_a?(Array)
19
- :array
20
- end
15
+ def paginate(collection, using: nil, **opts, &block)
16
+ opts = pagy_countless_get_vars(nil, opts)
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, via].compact.join('_')
23
+ method = [:pagy, using].compact.join('_')
23
24
  page, scope = send(method, collection, **opts)
24
25
 
25
26
  pagy_headers(page).each(&block)
@@ -30,11 +31,11 @@ module Grape
30
31
  module Helpers
31
32
  extend Grape::API::Helpers
32
33
 
33
- params :pagy do |items: nil, page: nil, **opts|
34
- items ||= ::Pagy::VARS[:items]
35
- page ||= ::Pagy::VARS[:page]
36
- page_param = opts[:page_param] || ::Pagy::VARS[:page_param]
37
- items_param = opts[:items_param] || ::Pagy::VARS[:items_param]
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]
38
39
 
39
40
  @api.route_setting(:pagy_options, opts)
40
41
  optional page_param, type: Integer, default: page, desc: 'Page offset to fetch.'
@@ -44,6 +45,7 @@ module Grape
44
45
  # @param [Array|ActiveRecord::Relation] collection the collection or relation.
45
46
  def pagy(collection, **opts)
46
47
  defaults = route_setting(:pagy_options) || {}
48
+
47
49
  Wrapper.new(request, params).paginate(collection, **defaults, **opts) do |key, value|
48
50
  header key, value
49
51
  end
@@ -5,12 +5,14 @@ describe Grape::Pagy do
5
5
 
6
6
  let(:app) { TestAPI }
7
7
 
8
- it 'should paginate' do
8
+ it 'paginates' do
9
9
  get '/'
10
10
  expect(last_response.status).to eq(200)
11
11
  expect(last_response.headers).to include(
12
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"),
13
+ 'Link' => '<http://example.org/?page=1&items=5>; rel="first", ' \
14
+ '<http://example.org/?page=2&items=5>; rel="next", ' \
15
+ '<http://example.org/?page=3&items=5>; rel="last"',
14
16
  'Page-Items' => '5',
15
17
  'Total-Count' => '12',
16
18
  'Total-Pages' => '3',
@@ -18,7 +20,7 @@ describe Grape::Pagy do
18
20
  expect(last_response.body).to eq(%([1, 2, 3, 4, 5]))
19
21
  end
20
22
 
21
- it 'should accept page and items parameters' do
23
+ it 'accepts page and items parameters' do
22
24
  get '/?page=2&items=3'
23
25
  expect(last_response.status).to eq(200)
24
26
  expect(last_response.headers).to include(
@@ -30,7 +32,7 @@ describe Grape::Pagy do
30
32
  expect(last_response.body).to eq(%([4, 5, 6]))
31
33
  end
32
34
 
33
- it 'should cap items' do
35
+ it 'caps items' do
34
36
  get '/?items=10'
35
37
  expect(last_response.headers).to include('Page-Items' => '6')
36
38
  expect(last_response.body).to eq(%([1, 2, 3, 4, 5, 6]))
@@ -40,7 +42,7 @@ describe Grape::Pagy do
40
42
  expect(last_response.body).to eq(%([1, 2, 3]))
41
43
  end
42
44
 
43
- it 'should ignore overflow' do
45
+ it 'ignores overflow' do
44
46
  get '/?page=99'
45
47
  expect(last_response.status).to eq(200)
46
48
  expect(last_response.headers).to include(
@@ -50,7 +52,26 @@ describe Grape::Pagy do
50
52
  expect(last_response.body).to eq(%([]))
51
53
  end
52
54
 
53
- it 'should inherit helper' do
55
+ it 'allows countless mode' do
56
+ get '/countless?page=2'
57
+ expect(last_response.status).to eq(200)
58
+ expect(last_response.headers).to include(
59
+ 'Current-Page' => '2',
60
+ 'Page-Items' => '3',
61
+ 'Link' => [
62
+ %(<http://example.org/countless?page=1&items=3>; rel="first"),
63
+ %(<http://example.org/countless?page=1&items=3>; rel="prev"),
64
+ %(<http://example.org/countless?page=3&items=3>; rel="next"),
65
+ ].join(', '),
66
+ )
67
+ expect(last_response.headers).not_to include(
68
+ 'Total-Count',
69
+ 'Total-Pages',
70
+ )
71
+ expect(last_response.body).to eq(%([4, 5, 6]))
72
+ end
73
+
74
+ it 'inherits helper' do
54
75
  get '/sub'
55
76
  expect(last_response.status).to eq(200)
56
77
  expect(last_response.headers).to include(
data/spec/spec_helper.rb CHANGED
@@ -4,8 +4,18 @@ require 'rspec'
4
4
  require 'grape/pagy'
5
5
  require 'rack/test'
6
6
 
7
- Pagy::VARS[:items] = 10
8
- Pagy::VARS[:max_items] = 20
7
+ Pagy::DEFAULT[:items] = 10
8
+ Pagy::DEFAULT[:max_items] = 20
9
+
10
+ class TestArray < Array
11
+ def limit(num)
12
+ self.class.new slice(0, num)
13
+ end
14
+
15
+ def offset(num)
16
+ self.class.new slice(num..-1)
17
+ end
18
+ end
9
19
 
10
20
  class TestAPI < Grape::API
11
21
  helpers Grape::Pagy::Helpers
@@ -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.2.0
4
+ version: 0.5.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-10-08 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '5.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '5.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rubocop
98
+ name: rubocop-bsm
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -115,9 +115,9 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/workflows/ruby.yml"
118
119
  - ".gitignore"
119
120
  - ".rubocop.yml"
120
- - ".travis.yml"
121
121
  - CHANGELOG.md
122
122
  - Gemfile
123
123
  - Gemfile.lock
@@ -141,14 +141,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - ">="
143
143
  - !ruby/object:Gem::Version
144
- version: '2.5'
144
+ version: '3.0'
145
145
  required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  requirements: []
151
- rubygems_version: 3.1.2
151
+ rubygems_version: 3.2.15
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: ''
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.7
5
- - 2.6
6
- - 2.5