wor-paginate 0.3.0 → 0.4.1

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: 616213ea69272167621606631c90c60e4c14bdb5a2e31f933576ccc5d8dc04e8
4
- data.tar.gz: 24486490fa441d027284f1ef4d53ec686d849dc21f0d12bbc81116ed51865c4e
3
+ metadata.gz: 2382535974a5955b672ae5a22548b2100126afa69237fd5f76e7b5c18f6cd9e1
4
+ data.tar.gz: 977102640aba1c02a50d36181d2a4cc2fa3ab5e0bfe57b86587ae24fc4ada4ca
5
5
  SHA512:
6
- metadata.gz: d3eb17ff497fae64cdc0edd117591ac02bc03b74669f82271475202e7d7d0d7c341c85804bbc93f7220751d28c45659265b1c68fd122557d8b558e00d7822d11
7
- data.tar.gz: 8a76d0a58b6a8b9fb5af30e450de603a91fa8efd9de0f1e4a881cf813be5d19386b65fd60c7ed4d40d7b63c7a3ea4dd8d570f2a0f5ba08a7ebee3ce166e1fd82
6
+ metadata.gz: acfa22f022acd7468c674cf723ca74b366deddf18d58320570951bd1067a36573a039468134ea4e1ee7586ea61e5fb685451e6fd1eb9f0a182d716a324177d2c
7
+ data.tar.gz: 2e1397984c3da7db0defdbe42e05f14e8692496d0411e9318e83f020ce3a3fe7e72ecfbfe7c748c3fd93263725d3752b89b8eda7e09fb3e729f3d6dacebf0cfb
@@ -0,0 +1,52 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ name: "Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}"
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby: ['3.2', '3.3', '3.4']
16
+ rails: ['6.1', '7.0', '7.1', '7.2', '8.0', '8.1']
17
+ steps:
18
+ - uses: actions/checkout@v7
19
+ - uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ bundler-cache: false
23
+ - name: Generate appraisal gemfiles
24
+ run: |
25
+ bundle install
26
+ bundle exec appraisal generate
27
+ - name: Install dependencies for this Rails version
28
+ env:
29
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails }}.gemfile
30
+ run: bundle install
31
+ - name: Prepare test database
32
+ env:
33
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails }}.gemfile
34
+ RAILS_ENV: test
35
+ working-directory: spec/dummy
36
+ run: bundle exec rails db:schema:load
37
+ - name: Run tests
38
+ env:
39
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails }}.gemfile
40
+ run: bundle exec rspec
41
+
42
+ lint:
43
+ name: RuboCop
44
+ runs-on: ubuntu-latest
45
+ steps:
46
+ - uses: actions/checkout@v7
47
+ - uses: ruby/setup-ruby@v1
48
+ with:
49
+ ruby-version: '3.4'
50
+ bundler-cache: true
51
+ - name: Run RuboCop
52
+ run: bundle exec rubocop lib spec --format simple
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  spec/dummy/db/*.sqlite3
2
2
  spec/dummy/db/*.sqlite3-journal
3
+ /test.sqlite3
3
4
  spec/dummy/log/*.log
4
5
  spec/dummy/tmp/
5
6
 
@@ -330,3 +331,13 @@ $RECYCLE.BIN/
330
331
  *.lnk
331
332
 
332
333
  # End of https://www.gitignore.io/api/ruby,rubymine,rails,emacs,vim,sublimetext,osx,macos,linux,windows
334
+
335
+ ### Claude Code / superpowers ###
336
+ CLAUDE.md
337
+ .claude/
338
+ docs/superpowers/
339
+ .superpowers/
340
+
341
+ ### Appraisal ###
342
+ /gemfiles/*.gemfile
343
+ /gemfiles/*.gemfile.lock
data/.overcommit.yml ADDED
@@ -0,0 +1,16 @@
1
+ PrePush:
2
+ ALL:
3
+ problem_on_unmodified_line: report
4
+ requires_files: false
5
+ quiet: false
6
+
7
+ RuboCop:
8
+ enabled: true
9
+ command: ['bundle', 'exec', 'rubocop']
10
+
11
+ CustomScript:
12
+ enabled: true
13
+ description: 'Run RSpec with 100% coverage gate'
14
+ command: ['bundle', 'exec', 'rspec']
15
+ env:
16
+ BUNDLE_GEMFILE: gemfiles/rails_8.1.gemfile
data/.rubocop.yml CHANGED
@@ -1,19 +1,23 @@
1
+ plugins:
2
+ - rubocop-rspec
3
+
1
4
  AllCops:
2
5
  Exclude:
3
6
  - wor-paginate.gemspec
4
- - spec/spy.rb
5
7
  - spec/dummy/db/**/*
6
8
  - spec/dummy/config/**/*
7
- - spec/spec_helper.rb
8
- TargetRubyVersion: 2.3.8
9
+ - spec/dummy/bin/**/*
10
+ TargetRubyVersion: 3.2
11
+ NewCops: disable
12
+ SuggestExtensions: false
9
13
 
10
- Documentation:
14
+ Style/Documentation:
11
15
  Enabled: false
12
16
 
13
- LineLength:
17
+ Layout/LineLength:
14
18
  Max: 99
15
19
 
16
- FrozenStringLiteralComment:
20
+ Style/FrozenStringLiteralComment:
17
21
  Enabled: false
18
22
 
19
23
  Metrics/BlockLength:
@@ -23,9 +27,7 @@ Metrics/BlockLength:
23
27
 
24
28
  # rubocop-rspec custom configurations
25
29
 
26
- require: rubocop-rspec
27
-
28
- Style/VariableNumber:
30
+ Naming/VariableNumber:
29
31
  EnforcedStyle: snake_case
30
32
 
31
33
  RSpec/ExampleLength:
@@ -46,8 +48,13 @@ Lint/AmbiguousBlockAssociation:
46
48
  RSpec/LetSetup:
47
49
  Enabled: false
48
50
 
49
- RSpec/FilePath:
51
+ # matchers_spec.rb describes DummyModelsController to test the be_paginated
52
+ # matcher against real responses, not to test the controller itself, so its
53
+ # name doesn't follow the described-class convention on purpose.
54
+ RSpec/SpecFilePathFormat:
55
+ Exclude:
56
+ - spec/matchers_spec.rb
57
+
58
+ RSpec/SpecFilePathSuffix:
50
59
  Exclude:
51
- - spec/dummy_controller_without_gems_spec.rb
52
60
  - spec/matchers_spec.rb
53
- - spec/dummy_controller_spec.rb
data/Appraisals ADDED
@@ -0,0 +1,41 @@
1
+ # sqlite3 is pinned per Rails version here, not in the Gemfile: activerecord
2
+ # 6.1/7.0 hard-pin "~> 1.4" internally, 8.0/8.1 need ">= 2.1", and Bundler
3
+ # won't allow the same gem pinned twice in one Gemfile.
4
+
5
+ appraise 'rails-6.1' do
6
+ gem 'rails', '~> 6.1.0'
7
+
8
+ # activesupport 6.1.x requires mutex_m without declaring it; Ruby 3.4+ no
9
+ # longer bundles it by default.
10
+ gem 'mutex_m'
11
+
12
+ # Same issue for benchmark, removed by default in Ruby 4.0.
13
+ gem 'benchmark'
14
+
15
+ gem 'sqlite3', '~> 1.4'
16
+ end
17
+
18
+ appraise 'rails-7.0' do
19
+ gem 'rails', '~> 7.0.0'
20
+ gem 'sqlite3', '~> 1.4'
21
+ end
22
+
23
+ appraise 'rails-7.1' do
24
+ gem 'rails', '~> 7.1.0'
25
+ gem 'sqlite3', '~> 2.9'
26
+ end
27
+
28
+ appraise 'rails-7.2' do
29
+ gem 'rails', '~> 7.2.0'
30
+ gem 'sqlite3', '~> 2.9'
31
+ end
32
+
33
+ appraise 'rails-8.0' do
34
+ gem 'rails', '~> 8.0.0'
35
+ gem 'sqlite3', '~> 2.9'
36
+ end
37
+
38
+ appraise 'rails-8.1' do
39
+ gem 'rails', '~> 8.1.0'
40
+ gem 'sqlite3', '~> 2.9'
41
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Change log
2
2
 
3
+ ### V0.4.1
4
+ * [#2](https://github.com/icoluccio/wor-paginate/pull/2) Remove remaining dead Wolox links - [@icoluccio](https://github.com/icoluccio).
5
+
6
+ ### V0.4.0
7
+ * [#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).
8
+
3
9
  ### V0.3.0
4
10
  * [#94](https://github.com/Wolox/wor-paginate/pull/94) Add Panko formatter - [@blacksam07](https://github.com/blacksam07).
5
11
  * [#96](https://github.com/Wolox/wor-paginate/pull/96) Dynamic Adapters - [@juanpablo-rojas](https://github.com/juanpablo-rojas).
data/Gemfile CHANGED
@@ -14,23 +14,25 @@ gemspec
14
14
  # gem 'byebug', group: [:development, :test]
15
15
 
16
16
  group :development, :test do
17
- gem 'active_model_serializers', '~> 0.10.0'
18
- gem 'bundler', '>= 2.0.1'
19
- gem 'byebug', '~> 9.0'
20
- gem 'codeclimate-test-reporter', '~> 1.0.0'
21
- gem 'database_cleaner', '~> 1.6.0'
22
- gem 'factory_girl_rails', '~> 4.7.0'
23
- gem 'faker', '~> 1.7.0'
24
- gem 'generator_spec', '~> 0.9.0'
25
- gem 'kaminari', '~> 0.17.0'
26
- gem 'panko_serializer', '~> 0.7.2'
27
- gem 'rake', '~> 10.0'
28
- gem 'rspec', '~> 3.0'
29
- gem 'rspec-rails', '~> 3.6.0'
30
- gem 'rubocop', '~> 0.49.1'
31
- gem 'rubocop-rspec', '~> 1.15.0'
32
- gem 'simplecov', '~> 0.13.0'
33
- gem 'sqlite3', '~> 1.4'
34
- gem 'webmock', '~> 3.0.0'
35
- gem 'will_paginate', '~> 3.1.0'
17
+ gem 'active_model_serializers', '~> 0.10.16'
18
+ gem 'appraisal', '~> 2.5'
19
+ gem 'byebug', '~> 13.0'
20
+ gem 'database_cleaner-active_record', '~> 2.2', require: 'database_cleaner/active_record'
21
+ gem 'factory_bot_rails', '~> 6.5'
22
+ gem 'faker', '~> 3.8'
23
+ gem 'generator_spec', '~> 0.10'
24
+ gem 'kaminari', '~> 1.2'
25
+ gem 'overcommit', '~> 0.71'
26
+ gem 'panko_serializer', '~> 0.8.5'
27
+ gem 'puma', '~> 6.0'
28
+ gem 'rake', '~> 13.0'
29
+ gem 'rspec', '~> 3.13'
30
+ gem 'rspec-rails', '>= 6.0', '< 9'
31
+ gem 'rubocop', '~> 1.88'
32
+ gem 'rubocop-rspec', '~> 3.10'
33
+ gem 'simplecov', '~> 0.22'
34
+ # sqlite3 is pinned per Rails version in Appraisals instead, since the
35
+ # required range differs across supported versions.
36
+ gem 'webmock', '~> 3.26'
37
+ gem 'will_paginate', '~> 4.0'
36
38
  end
data/LICENSE.md CHANGED
@@ -1,6 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2017 Wolox
4
+ Copyright (c) 2026 Ignacio Coluccio
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,9 +1,8 @@
1
1
  Wor::Paginate
2
2
  =============
3
3
 
4
- [![Build Status](https://travis-ci.org/Wolox/wor-paginate.svg?branch=master)](https://travis-ci.org/Wolox/wor-paginate)
4
+ [![CI](https://github.com/icoluccio/wor-paginate/actions/workflows/ci.yml/badge.svg)](https://github.com/icoluccio/wor-paginate/actions/workflows/ci.yml)
5
5
  [![Gem Version](https://badge.fury.io/rb/wor-paginate.svg)](https://badge.fury.io/rb/wor-paginate)
6
- [![Code Climate](https://codeclimate.com/github/Wolox/wor-paginate/badges/gpa.svg)](https://codeclimate.com/github/Wolox/wor-paginate)
7
6
 
8
7
  # Table of contents
9
8
  - [Description](#description)
@@ -49,7 +48,7 @@ Then you can run `rails generate wor:paginate:install` to create the initializer
49
48
 
50
49
  ## Usage
51
50
  ### Basic usage
52
- The basic use case is to paginate using default values. This is achieved by including the module in a controller and calling render_paginate in the method that needs pagination.
51
+ The basic use case is to paginate using default values. This is achieved by including the module in a controller and calling render_paginated in the method that needs pagination.
53
52
  ```ruby
54
53
  class DummyModelsController < ApplicationController
55
54
  include Wor::Paginate
@@ -92,11 +91,11 @@ The response to the index will then be:
92
91
  "previous_page": null,
93
92
  "next_page": 2,
94
93
  "previous_page_url": null,
95
- "next_page_url": "http://api.example.com/users?page=2
94
+ "next_page_url": "http://api.example.com/users?page=2"
96
95
  }
97
96
  ```
98
97
 
99
- Page number is passed through the `page` option of the `render_paginated` method. If none is supplied, `params[:page]` will be used, (or the default parameter configured in the initializer).
98
+ Page number is passed through the `page` option of the `render_paginated` method. If none is supplied, `params[:page]` will be used (or the default parameter configured in the initializer).
100
99
  By default, if the page parameter is not present we will use 1 as the page (or the default `page` parameter configured in the initializer).
101
100
  The amount of items is passed through the `limit` option of the `render_paginated` method. If none is supplied, `params[:limit]` will be used (or the default parameter configured in the initializer). Default is 25.
102
101
  The default serializer and formatter will be used.
@@ -111,7 +110,7 @@ where the serializer is just an [`ActiveModel::Serializer`](https://github.com/r
111
110
 
112
111
  #### Custom options
113
112
  ##### max_limit
114
- The max amount of items is passed through the `max_limit` option, You can set the value in the initializer or in the `render_paginated` method, (If none is supplied, take the default value configured in the initializer). Default is 50.
113
+ The max amount of items is passed through the `max_limit` option. You can set the value in the initializer or in the `render_paginated` method (If none is supplied, take the default value configured in the initializer). Default is 50.
115
114
 
116
115
  ```ruby
117
116
  render_paginated DummyModel, max_limit: 100
@@ -135,7 +134,7 @@ end
135
134
  ```
136
135
 
137
136
  ##### total_count
138
- You can overwrite the `total_count` pagination param by passing it as a single option to the method. This could be used if the whole collection to be paginated is complex and has the risk to broke when counting all the records.
137
+ You can overwrite the `total_count` pagination param by passing it as a single option to the method. This could be used if the whole collection to be paginated is complex and has the risk to break when counting all the records.
139
138
 
140
139
  ```ruby
141
140
  render_paginated DummyModel, total_count: 50
@@ -144,7 +143,7 @@ You can overwrite the `total_count` pagination param by passing it as a single o
144
143
  ##### preserve_records
145
144
  > WARNING: This option only works with an ActiveRecord collection.
146
145
 
147
- Preserve records option can be added to `render_paginated` to mantain current records. This allow to navigate pages like an infinite scroll without adding new records when switching pages.
146
+ Preserve records option can be added to `render_paginated` to maintain current records. This allows to navigate pages like an infinite scroll without adding new records when switching pages.
148
147
 
149
148
  - Timestamp mode (default)
150
149
  ```ruby
@@ -178,7 +177,7 @@ render_paginated DummyModel, formatter: CustomFormatter
178
177
  ```
179
178
  or it can also be set as a default in the initializer.
180
179
 
181
- A new formatter can be created inheriting from the default one. The `format` method should be redefined returning something that can be converted to json.
180
+ A new formatter can be created inheriting from the default one. The `format` method should be redefined returning something that can be converted to JSON.
182
181
 
183
182
  ```ruby
184
183
  class CustomFormatter < Wor::Paginate::Formatters::Base
@@ -205,7 +204,7 @@ render_paginated DummyModel, adapter: CustomAdapter
205
204
  or it can also be set as a default in the initializer.
206
205
 
207
206
  A new adapter can be created inheriting from the default Base Adapter. Some methods must be redefined in order to make the adapter "adaptable" to the content that will be rendered.
208
- Below is an example of a simple posible CustomAdapter that extends from the base Adapter.
207
+ Below is an example of a simple possible CustomAdapter that extends from the base Adapter.
209
208
 
210
209
  ```ruby
211
210
  class CustomAdapter < Wor::Paginate::Adapters::Base
@@ -234,7 +233,7 @@ Here's a brief explanation on every overwritten method in this CustomAdapter exa
234
233
  These will be the methods (as symbols) that the content to be rendered has to support. The next expression will be evaluated for every method added here: `@content.respond_to? method`. All required_methods must answer `true` to the previous expression, in order to make the adapter "adaptable" for the content. For example, if we rendered an ActiveRecord::Relation, this CustomAdapter would be adaptable because an ActiveRecord::Relation responds to the `#count` method. At least one symbol has to be returned in this method, otherwise the adapter won't be able to render content.
235
234
 
236
235
  ##### `#paginated_content`
237
- This is how the content will be shown. As the content comes in the inherited instance variable `@content`, we can transform the content however we want. In the CustomAdapter example, will always be shown the first 5 records.
236
+ This is how the content will be shown. As the content comes in the inherited instance variable `@content`, we can transform the content however we want. In the CustomAdapter example, the first 5 records will always be shown.
238
237
 
239
238
  ##### `#total_pages`
240
239
  This could be defined as the number of pages, given the limit requested. As the other values, this can be a custom number of pages, depending on your needs. For this example, this number is just an integer calculation of the total pages, depending on the limit. Also, like `@content`, we are inheriting the `@limit` variable, which allows us to operate with it however we want.
@@ -243,29 +242,29 @@ This could be defined as the number of pages, given the limit requested. As the
243
242
  This will be the number that will tell us 'how many records is returning the request'. Again, we can customize it however we want. For this particular example this will be just the count of `@content`.
244
243
 
245
244
  ##### `#count` method as delegate
246
- In the end of the CustomAdapter we are delegating the `#count` method to the `paginated_content`. This is because the Base Adapter delegates that method to the inherited adapter, so our custom adapter has to know "how to calculate" that method, that's why we are defining a `#count` method in the delegation (It is always mandatory to define the `#count` method in a custom adapter, whether is a method definition or a delegate).
245
+ At the end of the CustomAdapter we are delegating the `#count` method to the `paginated_content`. This is because the Base Adapter delegates that method to the inherited adapter, so our custom adapter has to know "how to calculate" that method, that's why we are defining a `#count` method in the delegation (It is always mandatory to define the `#count` method in a custom adapter, whether it is a method definition or a delegate).
247
246
 
248
- If the content is an ActiveRecord::Relation, for example, this adapter would work, because `paginated_content` would become an ActiveRecord::Relation, which actually knows "how to calculate" the count method. This works as a delegate, because ActiveRecord::Relation has an internal `#count` definition, but we would have to provide the needed method definition if it is a custom method, or we want a custom behaviour of a known method.
247
+ If the content is an ActiveRecord::Relation, for example, this adapter would work, because `paginated_content` would become an ActiveRecord::Relation, which actually knows "how to calculate" the count method. This works as a delegate, because ActiveRecord::Relation has an internal `#count` definition, but we would have to provide the needed method definition if it is a custom method, or if we want a custom behaviour of a known method.
249
248
 
250
249
  ##### Other available methods to overwrite
251
250
  `Wor::Paginate::Adapters::Base` also has implementations for `#next_page` and `#previous_page` methods (which calculate the number of the next and previous pages, respectively). If you want, you can also overwrite those methods, to calculate custom 'next' and 'previous' page numbers.
252
251
 
253
- To understand better the implementation of the Base Adapter and how you could overwrite methods in order to make a functional Custom Adapter, take a look at its definition in: [Base adapter Class](https://github.com/Wolox/wor-paginate/blob/master/lib/wor/paginate/adapters/base.rb).
252
+ To understand better the implementation of the Base Adapter and how you could overwrite methods in order to make a functional Custom Adapter, take a look at its definition in: [Base adapter Class](https://github.com/icoluccio/wor-paginate/blob/main/lib/wor/paginate/adapters/base.rb).
254
253
  Keep in mind that an instance of your Custom Adapter must answer `true` to the `#adapt?` method inherited from the Base Adapter, in order to make it "adaptable" to the content.
255
254
 
256
255
  #### Adapters Operations
257
- There are also helper methods available to dynamically operate the gem's adapters, so you can configurate them, whether in the initializer or in an internal part of your application. Once you include the gem, you'll be provided with the following methods, inside the Config module:
256
+ There are also helper methods available to dynamically operate the gem's adapters, so you can configure them, whether in the initializer or in an internal part of your application. Once you include the gem, you'll be provided with the following methods, inside the Config module:
258
257
  * `Wor::Paginate::Config.add_adapter(adapter)`: Add a specific adapter to the array of the gem's adapters. The 'adapter' variable must be a Class reference to an Adapter Class (that class has to have a similar structure as the CustomAdapter example above).
259
- * `Wor::Paginate::Config.remove_adapter(adapter)`: Remove an specific adapter from the array of the gem's adapters.
258
+ * `Wor::Paginate::Config.remove_adapter(adapter)`: Remove a specific adapter from the array of the gem's adapters.
260
259
  * `Wor::Paginate::Config.clear_adapters`: This method empties the array of the gem's adapters.
261
260
  * `Wor::Paginate::Config.adapters`: Returns all the current internal adapters inside the gem.
262
- * `Wor::Paginate::Config.reset_adapters!`: This helper resets the gem's adapters to its default array of adapters. You can see how the array of default adapters looks like at the beggining of the `Wor::Paginate::Config` module: [Config module](https://github.com/Wolox/wor-paginate/blob/master/lib/wor/paginate/config.rb).
261
+ * `Wor::Paginate::Config.reset_adapters!`: This helper resets the gem's adapters to its default array of adapters. You can see how the array of default adapters looks like at the beginning of the `Wor::Paginate::Config` module: [Config module](https://github.com/icoluccio/wor-paginate/blob/main/lib/wor/paginate/config.rb).
263
262
 
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) are you leaving in the `Wor::Paginate::Config.adapters` array, because depending on those, the gem will try to adapt the content.
263
+ 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.
265
264
 
266
265
 
267
266
  ### Working with Kaminari or will_paginate
268
- If either Kaminari or will_paginate are required in the project, Wor::Paginate will use them for pagination with no code or configuration change.
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.
269
268
 
270
269
  ### Test helpers
271
270
  You can use the `be_paginated` matcher to test your endpoints. It also accepts the `with` chain method to receive a formatter.
@@ -304,15 +303,15 @@ end
304
303
  ### Working with panko-serializer
305
304
 
306
305
  The default formatter is [Active Model Serializer](https://github.com/rails-api/active_model_serializers).
307
- If you want to change it, you should replace the formatter to another one. In this section, we are going to work with `PankoFormatter`
306
+ If you want to change it, you should replace the formatter with another one. In this section, we are going to work with `PankoFormatter`
308
307
 
309
308
  #### example
310
309
  ```ruby
311
- Wor::Paginate.configure do |config
310
+ Wor::Paginate.configure do |config|
312
311
  config.formatter = Wor::Paginate::Formatters::PankoFormatter
313
312
  end
314
313
  ```
315
- and next pass the specific serializer that you can use in the specific endpoint
314
+ and next, pass the specific serializer that you can use in the specific endpoint
316
315
 
317
316
  ```ruby
318
317
  def index
@@ -322,35 +321,38 @@ and next pass the specific serializer that you can use in the specific endpoint
322
321
  ## Contributing
323
322
 
324
323
  1. Fork it
325
- 2. Create your feature branch (`git checkout -b my-new-feature`)
326
- 3. Commit your changes (`git commit -am 'Add some feature'`)
327
- 4. Run rubocop lint (`bundle exec rubocop -R --format simple`)
328
- 5. Run rspec tests (`bundle exec rspec`)
329
- 6. Push your branch (`git push origin my-new-feature`)
330
- 7. Create a new Pull Request to `master` branch
324
+ 2. Run `bundle install && bundle exec appraisal generate` once, to install dependencies and generate the per-Rails-version gemfiles (`gemfiles/rails_*.gemfile`) used for testing
325
+ 3. Run `bundle exec overcommit --install` once, to enable the pre-push hook (runs RuboCop and the full spec suite with its 100%-coverage gate automatically on every `git push`)
326
+ 4. Create your feature branch (`git checkout -b my-new-feature`)
327
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
328
+ 6. Run RuboCop lint (`bundle exec rubocop lib spec --format simple`)
329
+ 7. Run rspec tests (`BUNDLE_GEMFILE=gemfiles/rails_8.1.gemfile bundle exec rspec`)
330
+ 8. Push your branch (`git push origin my-new-feature`) — the pre-push hook re-verifies both automatically
331
+ 9. Create a new Pull Request to `main` branch
331
332
 
332
333
  ## Releases
333
- 📢 [See what's changed in a recent version](https://github.com/Wolox/wor-paginate/releases)
334
+ 📢 [See what's changed in a recent version](https://github.com/icoluccio/wor-paginate/releases)
334
335
 
335
336
  ## About ##
336
337
 
337
- The current maintainers of this gem are :
338
- * [Martín Mallea](https://github.com/mnmallea)
338
+ The current maintainer of this gem is:
339
+ * [Ignacio Coluccio](https://github.com/icoluccio)
339
340
 
340
341
  This project was developed by:
341
- * [Hugo Farji](https://github.com/hdf1986)
342
342
  * [Ignacio Coluccio](https://github.com/icoluccio)
343
+ * [Martín Mallea](https://github.com/mnmallea)
344
+ * [Samir Tapiero](https://github.com/blacksam07)
345
+ * [Hugo Farji](https://github.com/hdf1986)
343
346
  * [Alan Halatian](https://github.com/alanhala)
344
347
 
345
- At [Wolox](http://www.wolox.com.ar)
346
-
347
- [![Wolox](https://raw.githubusercontent.com/Wolox/press-kit/master/logos/logo_banner.png)](http://www.wolox.com.ar)
348
+ Originally at Wolox
348
349
 
349
350
  ## License
350
351
 
351
- **wor-paginate** is available under the MIT [license](https://raw.githubusercontent.com/Wolox/wor-paginate/master/LICENSE.md).
352
+ **wor-paginate** is available under the MIT [license](https://raw.githubusercontent.com/icoluccio/wor-paginate/main/LICENSE.md).
352
353
 
353
354
  Copyright (c) 2017 Wolox
355
+ Copyright (c) 2026 Ignacio Coluccio
354
356
 
355
357
  Permission is hereby granted, free of charge, to any person obtaining a copy
356
358
  of this software and associated documentation files (the "Software"), to deal
@@ -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
@@ -2,7 +2,7 @@ module Wor
2
2
  module Paginate
3
3
  module Generators
4
4
  class InstallGenerator < Rails::Generators::Base
5
- source_root File.expand_path('../../../templates', __FILE__)
5
+ source_root File.expand_path('../../templates', __dir__)
6
6
  desc 'Creates Wor-Paginate initializer for your application'
7
7
 
8
8
  def copy_initializer
@@ -24,13 +24,14 @@ module Wor
24
24
  end
25
25
 
26
26
  def total_pages
27
- (total_count.to_f / @limit.to_f).ceil
27
+ (total_count.to_f / @limit).ceil
28
28
  end
29
29
 
30
30
  private
31
31
 
32
32
  def offset
33
33
  return 0 if @page.zero?
34
+
34
35
  (@page - 1) * @limit
35
36
  end
36
37
  end
@@ -12,6 +12,7 @@ module Wor
12
12
 
13
13
  def paginated_content
14
14
  return @paginated_content if @paginated_content
15
+
15
16
  content_array = @content.to_a
16
17
  @paginated_content = content_array.slice((page - 1) * @limit, @limit) || []
17
18
  end
@@ -6,9 +6,11 @@ module Wor
6
6
  class KaminariAlreadyPaginated < Base
7
7
  def required_methods
8
8
  # Methods Kaminari adds to ActiveRecord relations:
9
- ### [:padding, :per, :total_pages, :num_pages, :current_page, :first_page?,
9
+ ### [:padding, :per, :total_pages, :current_page, :first_page?,
10
10
  ### :prev_page, :last_page?, :next_page, :out_of_range?, :total_count, :entry_name]
11
- %i[padding total_count num_pages current_page prev_page]
11
+ # num_pages was removed upstream (kaminari-core 1.2.2 only defines
12
+ # total_pages); checking for it made adapt? always fail.
13
+ %i[padding total_count total_pages current_page prev_page]
12
14
  end
13
15
 
14
16
  def paginated_content
@@ -2,12 +2,9 @@ module Wor
2
2
  module Paginate
3
3
  module Formatters
4
4
  class AmsFormatter < Base
5
- include ActiveSupport::Callbacks
6
- define_callbacks :raise_dependency_error
7
- set_callback :raise_dependency_error, :before, :serialized_content, unless: :ams_defined?
8
-
9
5
  def serialized_content
10
6
  return serializable_resource.new(paginated_content).as_json unless serializer.present?
7
+
11
8
  raise_dependency_error unless serializer.respond_to?('_attributes_data')
12
9
  paginated_content.map { |item| serializer.new(item, options) }
13
10
  end
@@ -18,10 +15,6 @@ module Wor
18
15
  ActiveModelSerializers::SerializableResource
19
16
  end
20
17
 
21
- def ams_defined?
22
- defined? serializable_resource
23
- end
24
-
25
18
  def raise_dependency_error
26
19
  raise Wor::Paginate::Exceptions::DependencyError
27
20
  end
@@ -35,7 +35,9 @@ 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.
38
39
  @content ||= adapter.paginated_content
40
+ # rubocop:enable Naming/MemoizedInstanceVariableName
39
41
  end
40
42
 
41
43
  def serialized_content
@@ -4,6 +4,7 @@ module Wor
4
4
  class PankoFormatter < Base
5
5
  def serialized_content
6
6
  raise Wor::Paginate::Exceptions::DependencyError unless valid_serializer
7
+
7
8
  ActiveRecord::Base.transaction do
8
9
  Panko::ArraySerializer.new(paginated_content, each_serializer: serializer).to_a
9
10
  end
@@ -1,5 +1,7 @@
1
1
  class MockedAdapter < Wor::Paginate::Adapters::Base
2
- def initialize; end
2
+ def initialize
3
+ super(nil, 1, 1)
4
+ end
3
5
 
4
6
  def count
5
7
  3
@@ -11,8 +11,6 @@ module Wor
11
11
  query_param_value ? Time.parse(query_param_value) : now_timestamp
12
12
  end
13
13
 
14
- private_class_method
15
-
16
14
  def self.now_timestamp
17
15
  Time.zone.now.iso8601(10)
18
16
  end
@@ -25,6 +25,7 @@ module Wor
25
25
  by = options[:by]&.to_s || 'timestamp'
26
26
  raise ArgumentError, "'by' option should be 'id' or 'timestamp'" unless
27
27
  %w[timestamp id].include? by
28
+
28
29
  "Wor::Paginate::Utils::PreserveModes::#{by.classify}".constantize
29
30
  end
30
31
  end
@@ -1,5 +1,5 @@
1
1
  module Wor
2
2
  module Paginate
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.4.1'.freeze
4
4
  end
5
5
  end
data/wor-paginate.gemspec CHANGED
@@ -9,8 +9,8 @@ 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"]
13
- s.homepage = "https://github.com/Wolox/wor-paginate"
12
+ s.email = ["ignacio.coluccio@gmail.com", "martin.mallea@wolox.com.ar", "ramiro.rojo@wolox.com.ar", "lucas.voboril@wolox.com.ar"]
13
+ s.homepage = "https://github.com/icoluccio/wor-paginate"
14
14
  s.summary = "Simplified pagination for Rails API controllers"
15
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"
16
16
  s.license = "MIT"
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ['lib']
20
20
 
21
21
 
22
- s.add_dependency 'railties', '>= 4.1.0'
23
- s.add_dependency 'rails', '>= 4.0'
22
+ s.add_dependency 'railties', '>= 6.1', '< 9'
23
+ s.add_dependency 'rails', '>= 6.1', '< 9'
24
24
  end
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wor-paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - icoluccio
8
8
  - mnmallea
9
9
  - holywyvern
10
10
  - lucasVoboril
11
- autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2020-09-17 00:00:00.000000000 Z
13
+ date: 2026-08-01 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: railties
@@ -19,34 +18,46 @@ dependencies:
19
18
  requirements:
20
19
  - - ">="
21
20
  - !ruby/object:Gem::Version
22
- version: 4.1.0
21
+ version: '6.1'
22
+ - - "<"
23
+ - !ruby/object:Gem::Version
24
+ version: '9'
23
25
  type: :runtime
24
26
  prerelease: false
25
27
  version_requirements: !ruby/object:Gem::Requirement
26
28
  requirements:
27
29
  - - ">="
28
30
  - !ruby/object:Gem::Version
29
- version: 4.1.0
31
+ version: '6.1'
32
+ - - "<"
33
+ - !ruby/object:Gem::Version
34
+ version: '9'
30
35
  - !ruby/object:Gem::Dependency
31
36
  name: rails
32
37
  requirement: !ruby/object:Gem::Requirement
33
38
  requirements:
34
39
  - - ">="
35
40
  - !ruby/object:Gem::Version
36
- version: '4.0'
41
+ version: '6.1'
42
+ - - "<"
43
+ - !ruby/object:Gem::Version
44
+ version: '9'
37
45
  type: :runtime
38
46
  prerelease: false
39
47
  version_requirements: !ruby/object:Gem::Requirement
40
48
  requirements:
41
49
  - - ">="
42
50
  - !ruby/object:Gem::Version
43
- version: '4.0'
51
+ version: '6.1'
52
+ - - "<"
53
+ - !ruby/object:Gem::Version
54
+ version: '9'
44
55
  description: Wor::Paginate is a gem for Rails that simplifies pagination, particularly
45
56
  for controller methods, while standardizing JSON output for APIs. It's meant to
46
57
  work both as a standalone pagination gem and as an extra layer over Kaminari and
47
58
  will_paginate
48
59
  email:
49
- - ignacio.coluccio@wolox.com.ar
60
+ - ignacio.coluccio@gmail.com
50
61
  - martin.mallea@wolox.com.ar
51
62
  - ramiro.rojo@wolox.com.ar
52
63
  - lucas.voboril@wolox.com.ar
@@ -54,9 +65,11 @@ executables: []
54
65
  extensions: []
55
66
  extra_rdoc_files: []
56
67
  files:
68
+ - ".github/workflows/ci.yml"
57
69
  - ".gitignore"
70
+ - ".overcommit.yml"
58
71
  - ".rubocop.yml"
59
- - ".travis.yml"
72
+ - Appraisals
60
73
  - CHANGELOG.md
61
74
  - Gemfile
62
75
  - LICENSE.md
@@ -88,13 +101,11 @@ files:
88
101
  - lib/wor/paginate/utils/uri_helper.rb
89
102
  - lib/wor/paginate/version.rb
90
103
  - pull_request_template.md
91
- - test.sqlite3
92
104
  - wor-paginate.gemspec
93
- homepage: https://github.com/Wolox/wor-paginate
105
+ homepage: https://github.com/icoluccio/wor-paginate
94
106
  licenses:
95
107
  - MIT
96
108
  metadata: {}
97
- post_install_message:
98
109
  rdoc_options: []
99
110
  require_paths:
100
111
  - lib
@@ -109,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
120
  - !ruby/object:Gem::Version
110
121
  version: '0'
111
122
  requirements: []
112
- rubygems_version: 3.0.3
113
- signing_key:
123
+ rubygems_version: 4.0.6
114
124
  specification_version: 4
115
125
  summary: Simplified pagination for Rails API controllers
116
126
  test_files: []
data/.travis.yml DELETED
@@ -1,24 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.8
4
- - 2.4.7
5
- - 2.5.6
6
- - 2.6.4
7
- - 2.7.0
8
- - ruby-head
9
-
10
- before_install:
11
- - gem install bundler -v 2.0.1
12
-
13
- install:
14
- - bundle _2.0.1_ install --retry=3
15
- - bundle exec rake db:migrate RAILS_ENV=test -f spec/dummy/Rakefile
16
-
17
- script:
18
- - bundle exec rubocop lib spec --format simple
19
- - bundle exec rspec
20
- - bundle exec codeclimate-test-reporter
21
-
22
- matrix:
23
- allow_failures:
24
- - rvm : ruby-head
data/test.sqlite3 DELETED
File without changes