grape-pagy 0.5.0 → 0.6.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: 5cf4286de9e78c7b5a4f4f9ea1fdf9ad8c5e688a64b44e4551c26e300509d42c
4
- data.tar.gz: ca06ad206ff3fb7dadc9dcf9f37848afd58645d35f9b8af0dbe7819182694c1e
3
+ metadata.gz: 37ebea78807a69b217decab0117ac82528ae01db94c909b18025e3c85e6a2c6f
4
+ data.tar.gz: 03547b0d4bd43a7241237c7c8acf7a204d919f55fec94339edca859daab4c2fc
5
5
  SHA512:
6
- metadata.gz: 0b6094898f98b12b1bf636963d9e3254efa554469f6a179c0ea047022955c9f716c01c1961756d31b53a77f18947026d1929e4eaea80352de47771c2f92769c9
7
- data.tar.gz: 8141124754f358828ae5c248fac72acd3dcd4788aac64b3db54e9afbcbbc7b7e366739227c0e081b5249d6e010e6596293f18f06e1dfe5286241bc46b0ed4ac7
6
+ metadata.gz: 20e8746a4919de9dc56870934e3f24ca0ff18be31470713c614073c24901d13ab4e4f27bf87706d271397af7c61f78a423bc2d13111b2833e081e8fef42078ab
7
+ data.tar.gz: 2530fe8611153f8a1f7958207e416056ecb4cbafcb9c97442e5d37946f62b9fc7e6036a63ca7e613d21f67fc1a4fd3c9a7c381812ae9b6929d2e7dd904525485
@@ -11,9 +11,9 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  strategy:
13
13
  matrix:
14
- ruby-version: ["3.0"]
14
+ ruby-version: ["3.0", "3.1", "3.2"]
15
15
  steps:
16
- - uses: actions/checkout@v2
16
+ - uses: actions/checkout@v3
17
17
  - uses: ruby/setup-ruby@v1
18
18
  with:
19
19
  ruby-version: ${{ matrix.ruby-version }}
data/Gemfile CHANGED
@@ -1,2 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
+
4
+ gem 'bundler'
5
+ gem 'rack-test'
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'rubocop-bsm'
data/Gemfile.lock CHANGED
@@ -1,116 +1,110 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape-pagy (0.5.0)
4
+ grape-pagy (0.6.0)
5
5
  grape (>= 1.5)
6
- pagy (>= 5.4)
6
+ pagy (>= 6.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.1.3.1)
11
+ activesupport (7.0.4.2)
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.8)
20
- diff-lcs (1.4.4)
21
- dry-configurable (0.13.0)
18
+ concurrent-ruby (1.2.0)
19
+ diff-lcs (1.5.0)
20
+ dry-core (1.0.0)
22
21
  concurrent-ruby (~> 1.0)
23
- dry-core (~> 0.6)
24
- dry-container (0.9.0)
22
+ zeitwerk (~> 2.6)
23
+ dry-inflector (1.0.0)
24
+ dry-logic (1.5.0)
25
25
  concurrent-ruby (~> 1.0)
26
- dry-configurable (~> 0.13, >= 0.13.0)
27
- dry-core (0.7.1)
26
+ dry-core (~> 1.0, < 2)
27
+ zeitwerk (~> 2.6)
28
+ dry-types (1.7.0)
28
29
  concurrent-ruby (~> 1.0)
29
- dry-inflector (0.2.1)
30
- dry-logic (1.2.0)
31
- concurrent-ruby (~> 1.0)
32
- dry-core (~> 0.5, >= 0.5)
33
- dry-types (1.5.1)
34
- concurrent-ruby (~> 1.0)
35
- dry-container (~> 0.3)
36
- dry-core (~> 0.5, >= 0.5)
37
- dry-inflector (~> 0.1, >= 0.1.2)
38
- dry-logic (~> 1.0, >= 1.0.2)
39
- grape (1.6.0)
30
+ dry-core (~> 1.0, < 2)
31
+ dry-inflector (~> 1.0, < 2)
32
+ dry-logic (>= 1.4, < 2)
33
+ zeitwerk (~> 2.6)
34
+ grape (1.7.0)
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.8.10)
41
+ i18n (1.12.0)
47
42
  concurrent-ruby (~> 1.0)
48
- minitest (5.14.4)
49
- mustermann (1.1.1)
43
+ json (2.6.3)
44
+ minitest (5.17.0)
45
+ mustermann (3.0.0)
50
46
  ruby2_keywords (~> 0.0.1)
51
- mustermann-grape (1.0.1)
47
+ mustermann-grape (1.0.2)
52
48
  mustermann (>= 1.0.0)
53
- pagy (5.4.0)
54
- parallel (1.20.1)
55
- parser (3.0.1.0)
49
+ pagy (6.0.1)
50
+ parallel (1.22.1)
51
+ parser (3.2.0.0)
56
52
  ast (~> 2.4.1)
57
- rack (2.2.3)
53
+ rack (3.0.4.1)
58
54
  rack-accept (0.4.5)
59
55
  rack (>= 0.4)
60
- rack-test (1.1.0)
61
- rack (>= 1.0, < 3)
62
- rainbow (3.0.0)
63
- rake (13.0.3)
64
- regexp_parser (2.1.1)
56
+ rack-test (2.0.2)
57
+ rack (>= 1.3)
58
+ rainbow (3.1.1)
59
+ rake (13.0.6)
60
+ regexp_parser (2.6.2)
65
61
  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)
62
+ rspec (3.12.0)
63
+ rspec-core (~> 3.12.0)
64
+ rspec-expectations (~> 3.12.0)
65
+ rspec-mocks (~> 3.12.0)
66
+ rspec-core (3.12.0)
67
+ rspec-support (~> 3.12.0)
68
+ rspec-expectations (3.12.2)
73
69
  diff-lcs (>= 1.2.0, < 2.0)
74
- rspec-support (~> 3.10.0)
75
- rspec-mocks (3.10.2)
70
+ rspec-support (~> 3.12.0)
71
+ rspec-mocks (3.12.3)
76
72
  diff-lcs (>= 1.2.0, < 2.0)
77
- rspec-support (~> 3.10.0)
78
- rspec-support (3.10.2)
79
- rubocop (1.13.0)
73
+ rspec-support (~> 3.12.0)
74
+ rspec-support (3.12.0)
75
+ rubocop (1.44.1)
76
+ json (~> 2.3)
80
77
  parallel (~> 1.10)
81
- parser (>= 3.0.0.0)
78
+ parser (>= 3.2.0.0)
82
79
  rainbow (>= 2.2.2, < 4.0)
83
80
  regexp_parser (>= 1.8, < 3.0)
84
- rexml
85
- rubocop-ast (>= 1.2.0, < 2.0)
81
+ rexml (>= 3.2.5, < 4.0)
82
+ rubocop-ast (>= 1.24.1, < 2.0)
86
83
  ruby-progressbar (~> 1.7)
87
- unicode-display_width (>= 1.4.0, < 3.0)
88
- rubocop-ast (1.4.1)
89
- parser (>= 2.7.1.5)
90
- rubocop-bsm (0.5.8)
84
+ unicode-display_width (>= 2.4.0, < 3.0)
85
+ rubocop-ast (1.24.1)
86
+ parser (>= 3.1.1.0)
87
+ rubocop-bsm (0.6.1)
91
88
  rubocop (~> 1.0)
92
89
  rubocop-performance
93
- rubocop-rails
94
90
  rubocop-rake
95
91
  rubocop-rspec
96
- rubocop-performance (1.10.2)
97
- rubocop (>= 0.90.0, < 2.0)
92
+ rubocop-capybara (2.17.0)
93
+ rubocop (~> 1.41)
94
+ rubocop-performance (1.15.2)
95
+ rubocop (>= 1.7.0, < 2.0)
98
96
  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)
97
+ rubocop-rake (0.6.0)
106
98
  rubocop (~> 1.0)
107
- rubocop-ast (>= 1.1.0)
99
+ rubocop-rspec (2.18.1)
100
+ rubocop (~> 1.33)
101
+ rubocop-capybara (~> 2.17)
108
102
  ruby-progressbar (1.11.0)
109
103
  ruby2_keywords (0.0.5)
110
- tzinfo (2.0.4)
104
+ tzinfo (2.0.5)
111
105
  concurrent-ruby (~> 1.0)
112
- unicode-display_width (2.0.0)
113
- zeitwerk (2.4.2)
106
+ unicode-display_width (2.4.2)
107
+ zeitwerk (2.6.6)
114
108
 
115
109
  PLATFORMS
116
110
  ruby
@@ -124,4 +118,4 @@ DEPENDENCIES
124
118
  rubocop-bsm
125
119
 
126
120
  BUNDLED WITH
127
- 2.2.21
121
+ 2.4.1
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.5.0'
3
+ spec.version = '0.6.0'
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,11 @@ 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
13
  spec.required_ruby_version = '>= 3.0'
15
14
 
16
15
  spec.add_runtime_dependency 'grape', '>= 1.5'
17
- spec.add_runtime_dependency 'pagy', '>= 5.4'
16
+ spec.add_runtime_dependency 'pagy', '>= 6.0'
18
17
 
19
- spec.add_development_dependency 'bundler'
20
- spec.add_development_dependency 'rack-test'
21
- spec.add_development_dependency 'rake'
22
- spec.add_development_dependency 'rspec'
23
- spec.add_development_dependency 'rubocop-bsm'
18
+ spec.metadata['rubygems_mfa_required'] = 'true'
24
19
  end
data/lib/grape/pagy.rb CHANGED
@@ -31,15 +31,16 @@ module Grape
31
31
  module Helpers
32
32
  extend Grape::API::Helpers
33
33
 
34
- params :pagy do |opts|
34
+ params :pagy do |**opts|
35
35
  items = opts.delete(:items) || ::Pagy::DEFAULT[:items]
36
36
  page = opts.delete(:page) || ::Pagy::DEFAULT[:page]
37
37
  page_param = opts[:page_param] || ::Pagy::DEFAULT[:page_param]
38
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: 'Number of items to return per page.'
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.
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.5.0
4
+ version: 0.6.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: 2021-11-19 00:00:00.000000000 Z
11
+ date: 2023-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -30,84 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.4'
33
+ version: '6.0'
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: '5.4'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rack-test
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop-bsm
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
40
+ version: '6.0'
111
41
  description: Pagy paginator for grape API
112
42
  email:
113
43
  - info@blacksquaremedia.com
@@ -127,12 +57,11 @@ files:
127
57
  - grape-pagy.gemspec
128
58
  - lib/grape-pagy.rb
129
59
  - lib/grape/pagy.rb
130
- - spec/grape/pagy_spec.rb
131
- - spec/spec_helper.rb
132
60
  homepage: ''
133
61
  licenses:
134
62
  - Apache-2.0
135
- metadata: {}
63
+ metadata:
64
+ rubygems_mfa_required: 'true'
136
65
  post_install_message:
137
66
  rdoc_options: []
138
67
  require_paths:
@@ -148,10 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
77
  - !ruby/object:Gem::Version
149
78
  version: '0'
150
79
  requirements: []
151
- rubygems_version: 3.2.15
80
+ rubygems_version: 3.4.1
152
81
  signing_key:
153
82
  specification_version: 4
154
83
  summary: ''
155
- test_files:
156
- - spec/grape/pagy_spec.rb
157
- - spec/spec_helper.rb
84
+ test_files: []
@@ -1,94 +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&items=5>; rel="first", ' \
14
- '<http://example.org/?page=2&items=5>; rel="next", ' \
15
- '<http://example.org/?page=3&items=5>; rel="last"',
16
- 'Page-Items' => '5',
17
- 'Total-Count' => '12',
18
- 'Total-Pages' => '3',
19
- )
20
- expect(last_response.body).to eq(%([1, 2, 3, 4, 5]))
21
- end
22
-
23
- it 'accepts page and items parameters' do
24
- get '/?page=2&items=3'
25
- expect(last_response.status).to eq(200)
26
- expect(last_response.headers).to include(
27
- 'Current-Page' => '2',
28
- 'Page-Items' => '3',
29
- 'Total-Count' => '12',
30
- 'Total-Pages' => '4',
31
- )
32
- expect(last_response.body).to eq(%([4, 5, 6]))
33
- end
34
-
35
- it 'caps items' do
36
- get '/?items=10'
37
- expect(last_response.headers).to include('Page-Items' => '6')
38
- expect(last_response.body).to eq(%([1, 2, 3, 4, 5, 6]))
39
-
40
- get '/?items=3'
41
- expect(last_response.headers).to include('Page-Items' => '3')
42
- expect(last_response.body).to eq(%([1, 2, 3]))
43
- end
44
-
45
- it 'ignores overflow' do
46
- get '/?page=99'
47
- expect(last_response.status).to eq(200)
48
- expect(last_response.headers).to include(
49
- 'Current-Page' => '99',
50
- 'Total-Pages' => '3',
51
- )
52
- expect(last_response.body).to eq(%([]))
53
- end
54
-
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
75
- get '/sub'
76
- expect(last_response.status).to eq(200)
77
- expect(last_response.headers).to include(
78
- 'Current-Page' => '1',
79
- 'Page-Items' => '10',
80
- 'Total-Count' => '13',
81
- 'Total-Pages' => '2',
82
- )
83
- expect(last_response.body).to eq(%([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
84
-
85
- get '/sub?per_page=20'
86
- expect(last_response.status).to eq(200)
87
- expect(last_response.headers).to include(
88
- 'Current-Page' => '1',
89
- 'Page-Items' => '20',
90
- 'Total-Count' => '13',
91
- 'Total-Pages' => '1',
92
- )
93
- end
94
- 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::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
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