10000 [~] ruby 3 support · davidcelis/api-pagination@f276939 · GitHub
[go: up one dir, main page]

Skip to content

Commit f276939

Browse files
committed
[~] ruby 3 support
1 parent df05199 commit f276939

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ ApiPagination.configure do |config|
5858
config.per_page_param do |params|
5959
params[:page][:size] if params[:page].is_a?(ActionController::Parameters)
6060
end
61-
61+
6262
# Optional: Include the total and last_page link header
6363
# By default, this is set to true
6464
# Note: When using kaminari, this prevents the count call to the database
65-
config.include_total = false
65+
config.include_total = false
6666
end
6767
```
6868

@@ -71,7 +71,7 @@ end
7171
Pagy does not have a built-in way to specify a maximum number of items per page, but `api-pagination` will check if you've set a `:max_per_page` variable. To configure this, you can use the following code somewhere in an initializer:
7272

7373
```ruby
74-
Pagy::VARS[:max_per_page] = 100
74+
Pagy::DEFAULT[:max_per_page] = 100
7575
```
7676

7777
If left unconfigured, clients can request as many items per page as they wish, so it's highly recommended that you configure this.

api-pagination.gemspec

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ Gem::Specification.new do |s|
1616
s.test_files = Dir['spec/**/*']
1717
s.require_paths = ['lib']
1818

19-
s.add_development_dependency 'rspec', '~> 3.0'
20-
s.add_development_dependency 'grape', '>= 0.10.0'
21-
s.add_development_dependency 'railties', '>= 5.0.0'
22-
s.add_development_dependency 'actionpack', '>= 5.0.0'
23-
s.add_development_dependency 'sequel', '>= 4.9.0'
24-
s.add_development_dependency 'activerecord-nulldb-adapter', '>= 0.3.9'
19+
s.required_ruby_version = '> 2.7'
20+
21+
s.add_development_dependency 'kaminari', '~> 1.2', '>= 1.2.1'
22+
s.add_development_dependency 'pagy', '~> 5.1', '>= 5.1.2'
23+
s.add_development_dependency 'will_paginate', '~> 3.3', '>= 3.3.1'
24+
25+
s.add_development_dependency 'rspec', '~> 3.10'
26+
s.add_development_dependency 'grape', '~> 1.6'
27+
s.add_development_dependency 'railties', '~> 6.1', '>= 6.1.4.1'
28+
s.add_development_dependency 'actionpack', '~> 6.1', '>= 6.1.4.1'
29+
s.add_development_dependency 'sequel', '~> 5.49'
30+
s.add_development_dependency 'activerecord-nulldb-adapter', '~> 0.7.0'
2531
end

lib/api-pagination.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def total_from(collection)
4747
private
4848

4949
def paginate_with_pagy(collection, options)
50-
if Pagy::VARS[:max_per_page] && options[:per_page] > Pagy::VARS[:max_per_page]
51-
options[:per_page] = Pagy::VARS[:max_per_page]
50+
if Pagy::DEFAULT[:max_per_page] && options[:per_page] > Pagy::DEFAULT[:max_per_page]
51+
options[:per_page] = Pagy::DEFAULT[:max_per_page]
5252
elsif options[:per_page] <= 0
53-
options[:per_page] = Pagy::VARS[:items]
53+
options[:per_page] = Pagy::DEFAULT[:items]
5454
end
5555

5656
pagy = pagy_from(collection, options)
@@ -69,7 +69,7 @@ def pagy_from(collection, options)
6969
else
7070
count = collection.is_a?(Array) ? collection.count : collection.count(:all)
7171
end
72-
72+
7373
Pagy.new(count: count, items: options[:per_page], page: options[:page])
7474
end
7575

@@ -94,7 +94,7 @@ def paginate_with_kaminari(collection, options, paginate_array_options = {})
9494
options[:per_page] = get_default_per_page_for_kaminari(collection)
9595
end
9696

97-
collection = Kaminari.paginate_array(collection, paginate_array_options) if collection.is_a?(Array)
97+
collection = Kaminari.paginate_array(collection, **paginate_array_options) if collection.is_a?(Array)
9898
collection = collection.page(options[:page]).per(options[:per_page])
9999
collection.without_count if !collection.is_a?(Array) && !ApiPagination.config.include_total
100100
[collection, nil]

spec/api-pagination_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
describe '.paginate' do
1212
it 'should accept paginate_array_options option' do
1313
expect(Kaminari).to receive(:paginate_array)
14-
.with(collection, paginate_array_options)
14+
.with(collection, **paginate_array_options)
1515
.and_call_original
1616

1717
ApiPagination.paginate(

spec/rails_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class Fixnum
262262
end
263263
end
264264

265-
after :all do
265+
after :all do
266266
class Fixnum
267267
class << self
268268
undef_method :default_per_page, :per_page
@@ -286,7 +286,7 @@ class Fixnum
286286

287287
expect(response.header['Per-Page']).to eq(
288288
case ApiPagination.config.paginator
289-
when :pagy then Pagy::VARS[:items].to_s
289+
when :pagy then Pagy::DEFAULT[:items].to_s
290290
when :kaminari then Kaminari.config.default_per_page.to_s
291291
when :will_paginate then WillPaginate.per_page.to_s
292292
end
@@ -295,18 +295,18 @@ class Fixnum
295295
end
296296
end
297297

298-
context 'default per page in objects without paginator defaults' do
298+
context 'default per page in objects without paginator defaults' do
299299
it 'should not fail if model does not respond to per page' do
300300
get :index_with_no_per_page, params: {count: 100}
301301

302302
expect(response.header['Per-Page']).to eq(
303303
case ApiPagination.config.paginator
304-
when :pagy then Pagy::VARS[:items].to_s
304+
when :pagy then Pagy::DEFAULT[:items].to_s
305305
when :kaminari then Kaminari.config.default_per_page.to_s
306306
when :will_paginate then WillPaginate.per_page.to_s
307307
end
308308
)
309309
end
310310
end
311311
end
312-
end
312+
end

0 commit comments

Comments
 (0)
0