Skip to content

Commit

Permalink
Merge pull request #139 from Slokilla/pagy9
Browse files Browse the repository at this point in the history
Add Pagy 9 support
  • Loading branch information
davidcelis authored Jul 29, 2024
2 parents d173212 + 7384b51 commit 2eb59fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/api-pagination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ def paginate_with_pagy(collection, options)
if Pagy::DEFAULT[:max_per_page] && options[:per_page] > Pagy::DEFAULT[:max_per_page]
options[:per_page] = Pagy::DEFAULT[:max_per_page]
elsif options[:per_page] <= 0
options[:per_page] = Pagy::DEFAULT[:items]
options[:per_page] = Pagy::DEFAULT[:limit]
end

pagy = pagy_from(collection, options)
collection = if collection.respond_to?(:offset) && collection.respond_to?(:limit)
collection.offset(pagy.offset).limit(pagy.items)
collection.offset(pagy.offset).limit(pagy.limit)
else
collection[pagy.offset, pagy.items]
collection[pagy.offset, pagy.limit]
end

return [collection, pagy]
Expand All @@ -70,7 +70,7 @@ def pagy_from(collection, options)
count = collection.is_a?(Array) ? collection.count : collection.count(:all)
end

Pagy.new(count: count, items: options[:per_page], page: options[:page])
Pagy.new(count: count, limit: options[:per_page], page: options[:page])
end

def pagy_pages_from(pagy)
Expand Down
4 changes: 2 additions & 2 deletions spec/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class Fixnum

expect(response.header['Per-Page']).to eq(
case ApiPagination.config.paginator
when :pagy then Pagy::DEFAULT[:items].to_s
when :pagy then Pagy::DEFAULT[: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 @@ -301,7 +301,7 @@ class Fixnum

expect(response.header['Per-Page']).to eq(
case ApiPagination.config.paginator
when :pagy then Pagy::DEFAULT[:items].to_s
when :pagy then Pagy::DEFAULT[: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

0 comments on commit 2eb59fd

Please sign in to comment.