wor-paginate 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4481aa957c0963f107c5f1bdd9b2c6859cf91930aa7737e1a184a5634ad2bddf
4
- data.tar.gz: 3a66f12b6c3348f7e43aa98586218d812ba6df36f6917a926d8bd1abc19caf61
3
+ metadata.gz: bd8ccaf4d5f8af78619449bf39383c133e41d193e3db20db6bb98f79077b6bdc
4
+ data.tar.gz: d42ed079f99f0ed72379507f0f9bfa4225e977074d9eea85dace43ef7120dce0
5
5
  SHA512:
6
- metadata.gz: 8924bd31085db92676e53a290e5d9ae109295f15af0a908b798dec323a99a5c9b97a1b367cdc17f219126167bf4d6f703cc44a419c5d06acee3d8fe81d96c2d8
7
- data.tar.gz: 989d4fb9cef8a3e149178c1f1a777195f1b63b54ddf6e2be10e7612b11bb95a04ba6b3280680a90918e56473efba951439bfeb362eb681a98e4f7cdfe5a33254
6
+ metadata.gz: f6bd84a58f0c0879756e2954c0e25ee7e0cdf3206c471b4640304f2cd9853e60029857d21000618a95d6678aa60b2c14a24fac4c6991f9d9df95419c4651a7d7
7
+ data.tar.gz: 3066ece4481767bf0adcdbe2c295c453b7ad2c8340d0175a20b27680886c79e01ede4c102b59aed0f806405275509e3108545c79448cd670e4b791af7b0ad8b4
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  spec/dummy/db/*.sqlite3
2
2
  spec/dummy/db/*.sqlite3-journal
3
+ spec/dummy/db/*.sqlite3-shm
4
+ spec/dummy/db/*.sqlite3-wal
3
5
  /test.sqlite3
4
6
  spec/dummy/log/*.log
5
7
  spec/dummy/tmp/
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## Change log
2
2
 
3
+ ### V0.4.2
4
+ * [#3](https://github.com/icoluccio/wor-paginate/pull/3) Add Pagy adapter - [@icoluccio](https://github.com/icoluccio).
5
+ * [#4](https://github.com/icoluccio/wor-paginate/pull/4) Remove remaining rubocop:disable/:enable comments - [@icoluccio](https://github.com/icoluccio).
6
+ * [#5](https://github.com/icoluccio/wor-paginate/pull/5) Document Kaminari/will_paginate Model.page collision - [@icoluccio](https://github.com/icoluccio).
7
+
8
+ ### V0.4.1
9
+ * [#2](https://github.com/icoluccio/wor-paginate/pull/2) Remove remaining dead Wolox links - [@icoluccio](https://github.com/icoluccio).
10
+
3
11
  ### V0.4.0
4
12
  * [#1](https://github.com/icoluccio/wor-paginate/pull/1) Add Rails 8.0/8.1 support, HTTP-level request specs, and rubocop cleanup - [@icoluccio](https://github.com/icoluccio).
5
13
 
data/Gemfile CHANGED
@@ -23,6 +23,7 @@ group :development, :test do
23
23
  gem 'generator_spec', '~> 0.10'
24
24
  gem 'kaminari', '~> 1.2'
25
25
  gem 'overcommit', '~> 0.71'
26
+ gem 'pagy', '~> 43.0'
26
27
  gem 'panko_serializer', '~> 0.8.5'
27
28
  gem 'puma', '~> 6.0'
28
29
  gem 'rake', '~> 13.0'
data/README.md CHANGED
@@ -14,7 +14,8 @@ Wor::Paginate
14
14
  - [Custom options](#custom-options)
15
15
  - [Custom formatters](#custom-formatters)
16
16
  - [Custom adapters](#custom-adapters)
17
- - [Working with Kaminari or will_paginate](#working-with-kaminari-or-will_paginate)
17
+ - [Working with Kaminari, will_paginate, or Pagy](#working-with-kaminari-will_paginate-or-pagy)
18
+ - [Kaminari and will_paginate both define `Model.page`](#kaminari-and-will_paginate-both-define-modelpage)
18
19
  - [Test helpers](#test-helpers)
19
20
  - [Contributing](#contributing)
20
21
  - [Releases](#releases)
@@ -263,8 +264,39 @@ There are also helper methods available to dynamically operate the gem's adapter
263
264
  When the gem paginates, it tries to adapt the content to the first adapter that is "adaptable" for the content (unless a custom adapter has been passed to render_paginated or a default_adapter has been defined in the initializer). So beware of which adapters (and in which order) you are leaving in the `Wor::Paginate::Config.adapters` array, because depending on those, the gem will try to adapt the content.
264
265
 
265
266
 
266
- ### Working with Kaminari or will_paginate
267
- If either Kaminari or will_paginate is required in the project, Wor::Paginate will use them for pagination with no code or configuration change.
267
+ ### Working with Kaminari, will_paginate, or Pagy
268
+ If Kaminari, will_paginate, or [Pagy](https://github.com/ddnexus/pagy) is required in the project, Wor::Paginate will use it for pagination with no code or configuration change.
269
+
270
+ If more than one is available, Wor::Paginate prefers will_paginate, then Kaminari, then Pagy (the order they're checked in `Config::DEFAULT_ADAPTERS`). To opt out of one, for example if Pagy happens to be in your bundle for unrelated reasons, call `Wor::Paginate::Config.remove_adapter(Wor::Paginate::Adapters::Pagy)` in the initializer.
271
+
272
+ #### Kaminari and will_paginate both define `Model.page`
273
+ Kaminari and will_paginate each add their own `page` class method to your models, for the same purpose but with a different return value. Whichever gem's Rails initializer happens to run last silently overwrites the other's definition. This isn't affected by Gemfile order.
274
+
275
+ Wor::Paginate's own adapter selection already routes around this (see the precedence above). If you specifically need Kaminari's own pagination behavior while will_paginate is also installed, rename Kaminari's method and subclass the built-in Kaminari adapter, overriding only the two methods that call `.page` literally:
276
+
277
+ ```ruby
278
+ # config/initializers/kaminari.rb
279
+ Kaminari.configure do |config|
280
+ config.page_method_name = :kpage
281
+ end
282
+ ```
283
+
284
+ ```ruby
285
+ # app/adapters/kaminari_renamed_adapter.rb
286
+ class KaminariRenamedAdapter < Wor::Paginate::Adapters::Kaminari
287
+ def required_methods
288
+ %i[kpage]
289
+ end
290
+
291
+ def paginated_content
292
+ @paginated_content ||= @content.kpage(@page).per(@limit)
293
+ end
294
+ end
295
+ ```
296
+
297
+ ```ruby
298
+ render_paginated SomeModel, adapter: KaminariRenamedAdapter
299
+ ```
268
300
 
269
301
  ### Test helpers
270
302
  You can use the `be_paginated` matcher to test your endpoints. It also accepts the `with` chain method to receive a formatter.
@@ -345,9 +377,7 @@ This project was developed by:
345
377
  * [Hugo Farji](https://github.com/hdf1986)
346
378
  * [Alan Halatian](https://github.com/alanhala)
347
379
 
348
- Originally at [Wolox](http://www.wolox.com.ar)
349
-
350
- [![Wolox](https://raw.githubusercontent.com/Wolox/press-kit/master/logos/logo_banner.png)](http://www.wolox.com.ar)
380
+ Originally at Wolox
351
381
 
352
382
  ## License
353
383
 
@@ -8,7 +8,7 @@ Wor::Paginate.configure do |config|
8
8
  # In case you want to use other format for your response, you can override our formatter here
9
9
  # You can extend from Wor::Paginate::Formatters::Base and override the 'format' method
10
10
  # For more info about available methods for formatters see:
11
- # https://github.com/Wolox/wor-paginate/blob/master/lib/wor/paginate/formatters/base.rb
11
+ # https://github.com/icoluccio/wor-paginate/blob/main/lib/wor/paginate/formatters/base.rb
12
12
  # config.formatter = Wor::Paginate::Formatters::AmsFormatter
13
13
 
14
14
  # Configure a default adapter to use on pagination
@@ -20,6 +20,7 @@ Wor::Paginate.configure do |config|
20
20
  # Wor::Paginate::Adapters::WillPaginateAlreadyPaginated
21
21
  # Wor::Paginate::Adapters::WillPaginate
22
22
  # Wor::Paginate::Adapters::Kaminari
23
+ # Wor::Paginate::Adapters::Pagy
23
24
  # Wor::Paginate::Adapters::ActiveRecord
24
25
  # Wor::Paginate::Adapters::Enumerable
25
26
 
@@ -30,6 +31,7 @@ Wor::Paginate.configure do |config|
30
31
  # Adapters::WillPaginateAlreadyPaginated,
31
32
  # Adapters::WillPaginate,
32
33
  # Adapters::Kaminari,
34
+ # Adapters::Pagy,
33
35
  # Adapters::ActiveRecord,
34
36
  # Adapters::Enumerable
35
37
  # ]
@@ -0,0 +1,46 @@
1
+ require_relative 'helpers/total_count'
2
+
3
+ # Used when render_paginated is called with an ActiveRecord directly, with the
4
+ # pagy gem loaded. Something like
5
+ ### render_paginated DummyModel
6
+ module Wor
7
+ module Paginate
8
+ module Adapters
9
+ class Pagy < Base
10
+ include Helpers::TotalCount
11
+
12
+ def adapt?
13
+ defined?(::Pagy::Offset) && super
14
+ end
15
+
16
+ def required_methods
17
+ %i[offset limit table_name]
18
+ end
19
+
20
+ def paginated_content
21
+ @paginated_content ||= pagy.records(@content)
22
+ end
23
+
24
+ delegate :count, to: :paginated_content
25
+
26
+ def total_pages
27
+ pagy.pages
28
+ end
29
+
30
+ def next_page
31
+ pagy.next
32
+ end
33
+
34
+ def previous_page
35
+ pagy.previous
36
+ end
37
+
38
+ private
39
+
40
+ def pagy
41
+ @pagy ||= ::Pagy::Offset.new(count: total_count, page: @page, limit: @limit)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -16,6 +16,7 @@ module Wor
16
16
  will_paginate_paginated: Adapters::WillPaginateAlreadyPaginated,
17
17
  will_paginate: Adapters::WillPaginate,
18
18
  kaminari: Adapters::Kaminari,
19
+ pagy: Adapters::Pagy,
19
20
  active_record: Adapters::ActiveRecord,
20
21
  enumerable: Adapters::Enumerable
21
22
  }.freeze
@@ -5,7 +5,7 @@ module Wor
5
5
  module Formatters
6
6
  class Base
7
7
  include Utils::UriHelper
8
- attr_accessor :adapter, :content, :formatter, :options
8
+ attr_accessor :adapter, :formatter, :options
9
9
 
10
10
  def initialize(adapter, options = {})
11
11
  @adapter = adapter
@@ -35,9 +35,7 @@ module Wor
35
35
  end
36
36
 
37
37
  def paginated_content
38
- # rubocop:disable Naming/MemoizedInstanceVariableName -- @content matches the public `content` attr_accessor above; renaming it would silently change what `content` returns.
39
- @content ||= adapter.paginated_content
40
- # rubocop:enable Naming/MemoizedInstanceVariableName
38
+ @paginated_content ||= adapter.paginated_content
41
39
  end
42
40
 
43
41
  def serialized_content
@@ -1,5 +1,5 @@
1
1
  module Wor
2
2
  module Paginate
3
- VERSION = '0.4.0'.freeze
3
+ VERSION = '0.4.2'.freeze
4
4
  end
5
5
  end
data/lib/wor/paginate.rb CHANGED
@@ -3,6 +3,7 @@ require_relative 'paginate/adapters/active_record'
3
3
  require_relative 'paginate/adapters/enumerable'
4
4
  require_relative 'paginate/adapters/kaminari'
5
5
  require_relative 'paginate/adapters/will_paginate'
6
+ require_relative 'paginate/adapters/pagy'
6
7
  require_relative 'paginate/adapters/kaminari_already_paginated'
7
8
  require_relative 'paginate/adapters/will_paginate_already_paginated'
8
9
  require_relative 'paginate/exceptions/dependency_error'
data/wor-paginate.gemspec CHANGED
@@ -9,10 +9,10 @@ Gem::Specification.new do |s|
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.date = Date.today
11
11
  s.authors = ["icoluccio", "mnmallea", "holywyvern", "lucasVoboril"]
12
- s.email = ["ignacio.coluccio@wolox.com.ar", "martin.mallea@wolox.com.ar", "ramiro.rojo@wolox.com.ar", "lucas.voboril@wolox.com.ar"]
12
+ s.email = ["ignacio.coluccio@gmail.com", "martin.mallea@wolox.com.ar", "ramiro.rojo@wolox.com.ar", "lucas.voboril@wolox.com.ar"]
13
13
  s.homepage = "https://github.com/icoluccio/wor-paginate"
14
14
  s.summary = "Simplified pagination for Rails API controllers"
15
- s.description = "Wor::Paginate is a gem for Rails that simplifies pagination, particularly for controller methods, while standardizing JSON output for APIs. It's meant to work both as a standalone pagination gem and as an extra layer over Kaminari and will_paginate"
15
+ s.description = "Wor::Paginate is a gem for Rails that simplifies pagination, particularly for controller methods, while standardizing JSON output for APIs. It's meant to work both as a standalone pagination gem and as an extra layer over Kaminari, will_paginate, or Pagy"
16
16
  s.license = "MIT"
17
17
 
18
18
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec)/}) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wor-paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - icoluccio
@@ -10,7 +10,7 @@ authors:
10
10
  - lucasVoboril
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2026-08-01 00:00:00.000000000 Z
13
+ date: 2026-08-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '9'
55
55
  description: Wor::Paginate is a gem for Rails that simplifies pagination, particularly
56
56
  for controller methods, while standardizing JSON output for APIs. It's meant to
57
- work both as a standalone pagination gem and as an extra layer over Kaminari and
58
- will_paginate
57
+ work both as a standalone pagination gem and as an extra layer over Kaminari, will_paginate,
58
+ or Pagy
59
59
  email:
60
- - ignacio.coluccio@wolox.com.ar
60
+ - ignacio.coluccio@gmail.com
61
61
  - martin.mallea@wolox.com.ar
62
62
  - ramiro.rojo@wolox.com.ar
63
63
  - lucas.voboril@wolox.com.ar
@@ -84,6 +84,7 @@ files:
84
84
  - lib/wor/paginate/adapters/helpers/total_count.rb
85
85
  - lib/wor/paginate/adapters/kaminari.rb
86
86
  - lib/wor/paginate/adapters/kaminari_already_paginated.rb
87
+ - lib/wor/paginate/adapters/pagy.rb
87
88
  - lib/wor/paginate/adapters/will_paginate.rb
88
89
  - lib/wor/paginate/adapters/will_paginate_already_paginated.rb
89
90
  - lib/wor/paginate/config.rb