wor-paginate 0.3.0 → 0.4.0
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 +4 -4
- data/.github/workflows/ci.yml +52 -0
- data/.gitignore +11 -0
- data/.overcommit.yml +16 -0
- data/.rubocop.yml +19 -12
- data/Appraisals +41 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +21 -19
- data/LICENSE.md +1 -0
- data/README.md +38 -34
- data/lib/generators/wor/paginate/install_generator.rb +1 -1
- data/lib/wor/paginate/adapters/active_record.rb +2 -1
- data/lib/wor/paginate/adapters/enumerable.rb +1 -0
- data/lib/wor/paginate/adapters/kaminari_already_paginated.rb +4 -2
- data/lib/wor/paginate/formatters/ams_formatter.rb +1 -8
- data/lib/wor/paginate/formatters/base.rb +2 -0
- data/lib/wor/paginate/formatters/panko_formatter.rb +1 -0
- data/lib/wor/paginate/rspec.rb +3 -1
- data/lib/wor/paginate/utils/preserve_modes.rb +0 -2
- data/lib/wor/paginate/utils/preserve_records_helper.rb +1 -0
- data/lib/wor/paginate/version.rb +1 -1
- data/wor-paginate.gemspec +3 -3
- metadata +23 -13
- data/.travis.yml +0 -24
- data/test.sqlite3 +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4481aa957c0963f107c5f1bdd9b2c6859cf91930aa7737e1a184a5634ad2bddf
|
|
4
|
+
data.tar.gz: 3a66f12b6c3348f7e43aa98586218d812ba6df36f6917a926d8bd1abc19caf61
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8924bd31085db92676e53a290e5d9ae109295f15af0a908b798dec323a99a5c9b97a1b367cdc17f219126167bf4d6f703cc44a419c5d06acee3d8fe81d96c2d8
|
|
7
|
+
data.tar.gz: 989d4fb9cef8a3e149178c1f1a777195f1b63b54ddf6e2be10e7612b11bb95a04ba6b3280680a90918e56473efba951439bfeb362eb681a98e4f7cdfe5a33254
|
|
@@ -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/
|
|
8
|
-
TargetRubyVersion:
|
|
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
|
-
|
|
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
|
-
|
|
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,8 @@
|
|
|
1
1
|
## Change log
|
|
2
2
|
|
|
3
|
+
### V0.4.0
|
|
4
|
+
* [#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
|
+
|
|
3
6
|
### V0.3.0
|
|
4
7
|
* [#94](https://github.com/Wolox/wor-paginate/pull/94) Add Panko formatter - [@blacksam07](https://github.com/blacksam07).
|
|
5
8
|
* [#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.
|
|
18
|
-
gem '
|
|
19
|
-
gem 'byebug', '~>
|
|
20
|
-
gem '
|
|
21
|
-
gem '
|
|
22
|
-
gem '
|
|
23
|
-
gem '
|
|
24
|
-
gem '
|
|
25
|
-
gem '
|
|
26
|
-
gem 'panko_serializer', '~> 0.
|
|
27
|
-
gem '
|
|
28
|
-
gem '
|
|
29
|
-
gem 'rspec
|
|
30
|
-
gem '
|
|
31
|
-
gem 'rubocop
|
|
32
|
-
gem '
|
|
33
|
-
gem '
|
|
34
|
-
|
|
35
|
-
|
|
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
data/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
Wor::Paginate
|
|
2
2
|
=============
|
|
3
3
|
|
|
4
|
-
[](https://github.com/icoluccio/wor-paginate/actions/workflows/ci.yml)
|
|
5
5
|
[](https://badge.fury.io/rb/wor-paginate)
|
|
6
|
-
[](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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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/
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,40 @@ 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.
|
|
326
|
-
3.
|
|
327
|
-
4.
|
|
328
|
-
5.
|
|
329
|
-
6.
|
|
330
|
-
7.
|
|
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/
|
|
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
|
|
338
|
-
* [
|
|
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
|
-
|
|
348
|
+
Originally at [Wolox](http://www.wolox.com.ar)
|
|
346
349
|
|
|
347
350
|
[](http://www.wolox.com.ar)
|
|
348
351
|
|
|
349
352
|
## License
|
|
350
353
|
|
|
351
|
-
**wor-paginate** is available under the MIT [license](https://raw.githubusercontent.com/
|
|
354
|
+
**wor-paginate** is available under the MIT [license](https://raw.githubusercontent.com/icoluccio/wor-paginate/main/LICENSE.md).
|
|
352
355
|
|
|
353
356
|
Copyright (c) 2017 Wolox
|
|
357
|
+
Copyright (c) 2026 Ignacio Coluccio
|
|
354
358
|
|
|
355
359
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
356
360
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -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('
|
|
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
|
|
@@ -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, :
|
|
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
|
-
|
|
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
|
data/lib/wor/paginate/rspec.rb
CHANGED
data/lib/wor/paginate/version.rb
CHANGED
data/wor-paginate.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
|
10
10
|
s.date = Date.today
|
|
11
11
|
s.authors = ["icoluccio", "mnmallea", "holywyvern", "lucasVoboril"]
|
|
12
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/
|
|
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', '>=
|
|
23
|
-
s.add_dependency 'rails', '>=
|
|
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.
|
|
4
|
+
version: 0.4.0
|
|
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:
|
|
13
|
+
date: 2026-08-01 00:00:00.000000000 Z
|
|
15
14
|
dependencies:
|
|
16
15
|
- !ruby/object:Gem::Dependency
|
|
17
16
|
name: railties
|
|
@@ -19,28 +18,40 @@ dependencies:
|
|
|
19
18
|
requirements:
|
|
20
19
|
- - ">="
|
|
21
20
|
- !ruby/object:Gem::Version
|
|
22
|
-
version:
|
|
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:
|
|
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: '
|
|
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: '
|
|
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
|
|
@@ -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
|
-
-
|
|
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/
|
|
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:
|
|
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
|