Skip to content

Commit 9a5811e

Browse files
committed
Add support for and require pagy v43
Pagy v43 contains some major changes to the API, primarily moving all options into Pagy.options, and forcing you to choose a paginator instead of directly using the Pagy class. This commit requires the use of Pagy >= v43 going forward, and updates the integration to use the new API.
1 parent 5e98241 commit 9a5811e

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ gemspec
77
# Without these, Bundler may override gemspec constraints and install incompatible versions
88
gem "kaminari", "~> 1.2", ">= 1.2.1", require: false
99
gem "will_paginate", "~> 3.3", ">= 3.3.1", require: false
10-
gem "pagy", ">= 9.4.0", "< 10.0.0", require: false
10+
gem "pagy", "~> 43.0", require: false
1111

1212
gem "sqlite3", require: false
1313
gem "sequel", "~> 5.49", require: false

api-pagination.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
1717
s.required_ruby_version = "> 2.7"
1818

1919
s.add_development_dependency "kaminari", "~> 1.2", ">= 1.2.1"
20-
s.add_development_dependency "pagy", ">= 9.4.0", "< 10.0.0"
20+
s.add_development_dependency "pagy", "~> 43.0"
2121
s.add_development_dependency "will_paginate", "~> 3.3", ">= 3.3.1"
2222

2323
s.add_development_dependency "rspec", "~> 3.10"

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::DEFAULT[:max_per_page] && options[:per_page] > Pagy::DEFAULT[:max_per_page]
51-
options[:per_page] = Pagy::DEFAULT[:max_per_page]
50+
if Pagy.options[:max_per_page] && options[:per_page] > Pagy.options[:max_per_page]
51+
options[:per_page] = Pagy.options[:max_per_page]
5252
elsif options[:per_page] <= 0
53-
options[:per_page] = Pagy::DEFAULT[:limit]
53+
options[:per_page] = Pagy.options[:limit]
5454
end
5555

5656
pagy = pagy_from(collection, options)
@@ -73,14 +73,14 @@ def pagy_from(collection, options)
7373
# Pagy 9.x requires keyword arguments
7474
# Use explicit keyword argument syntax to avoid Ruby version quirks
7575
pagy_options = {count: count, limit: options[:per_page], page: options[:page]}
76-
Pagy.new(**pagy_options)
76+
Pagy::Offset.new(**pagy_options)
7777
end
7878

7979
def pagy_pages_from(pagy)
8080
{}.tap do |pages|
8181
unless pagy.page == 1
8282
pages[:first] = 1
83-
pages[:prev] = pagy.prev
83+
pages[:prev] = pagy.previous
8484
end
8585

8686
unless pagy.page == pagy.pages

spec/rails_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class << Integer
285285

286286
expect(response.header["Per-Page"]).to eq(
287287
case ApiPagination.config.paginator
288-
when :pagy then Pagy::DEFAULT[:limit].to_s
288+
when :pagy then Pagy.options[:limit].to_s
289289
when :kaminari then Kaminari.config.default_per_page.to_s
290290
when :will_paginate then WillPaginate.per_page.to_s
291291
end
@@ -300,7 +300,7 @@ class << Integer
300300

301301
expect(response.header["Per-Page"]).to eq(
302302
case ApiPagination.config.paginator
303-
when :pagy then Pagy::DEFAULT[:limit].to_s
303+
when :pagy then Pagy.options[:limit].to_s
304304
when :kaminari then Kaminari.config.default_per_page.to_s
305305
when :will_paginate then WillPaginate.per_page.to_s
306306
end

0 commit comments

Comments
 (0)