Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gemspec
# Without these, Bundler may override gemspec constraints and install incompatible versions
gem "kaminari", "~> 1.2", ">= 1.2.1", require: false
gem "will_paginate", "~> 3.3", ">= 3.3.1", require: false
gem "pagy", "~> 43.0", require: false
gem "pagy", "~> 43.3", require: false

gem "sqlite3", require: false
gem "sequel", "~> 5.49", require: false
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ gem 'rails-api'
gem 'grape', '>= 0.10.0'

# Then choose your preferred paginator from the following:
gem 'pagy', '>= 43.0.0' # Due to breaking changes, newer versions of api-pagination require pagy 43.0.0 or later
gem 'pagy'
gem 'kaminari'
gem 'will_paginate'

Expand Down Expand Up @@ -71,7 +71,7 @@ end
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:

```ruby
Pagy.options[:max_per_page] = 100
Pagy::OPTIONS[:max_per_page] = 100
```

If left unconfigured, clients can request as many items per page as they wish, so it's highly recommended that you configure this.
Expand Down
2 changes: 1 addition & 1 deletion api-pagination.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = "> 2.7"

s.add_development_dependency "kaminari", "~> 1.2", ">= 1.2.1"
s.add_development_dependency "pagy", "~> 43.0"
s.add_development_dependency "pagy", "~> 43.3"
s.add_development_dependency "will_paginate", "~> 3.3", ">= 3.3.1"

s.add_development_dependency "rspec", "~> 3.10"
Expand Down
6 changes: 3 additions & 3 deletions lib/api-pagination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def total_from(collection)
private

def paginate_with_pagy(collection, options)
if Pagy.options[:max_per_page] && options[:per_page] > Pagy.options[:max_per_page]
options[:per_page] = Pagy.options[:max_per_page]
if Pagy::OPTIONS[:max_per_page] && options[:per_page] > Pagy::OPTIONS[:max_per_page]
options[:per_page] = Pagy::OPTIONS[:max_per_page]
elsif options[:per_page] <= 0
options[:per_page] = Pagy.options[:limit]
options[:per_page] = Pagy::OPTIONS[:limit]
end

pagy = pagy_from(collection, options)
Expand Down
4 changes: 2 additions & 2 deletions spec/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class << Integer

expect(response.header["Per-Page"]).to eq(
case ApiPagination.config.paginator
when :pagy then Pagy.options[:limit].to_s
when :pagy then Pagy::OPTIONS[:limit].to_s
when :kaminari then Kaminari.config.default_per_page.to_s
when :will_paginate then WillPaginate.per_page.to_s
end
Expand All @@ -300,7 +300,7 @@ class << Integer

expect(response.header["Per-Page"]).to eq(
case ApiPagination.config.paginator
when :pagy then Pagy.options[:limit].to_s
when :pagy then Pagy::OPTIONS[:limit].to_s
when :kaminari then Kaminari.config.default_per_page.to_s
when :will_paginate then WillPaginate.per_page.to_s
end
Expand Down
Loading