cursor_pager 0.1.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +12 -6
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -1
- data/Appraisals +4 -0
- data/CHANGELOG.md +47 -1
- data/Gemfile.lock +50 -48
- data/README.md +19 -3
- data/cursor_pager.gemspec +2 -2
- data/gemfiles/activerecord_5.2.gemfile.lock +37 -34
- data/gemfiles/activerecord_6.0.gemfile.lock +39 -36
- data/gemfiles/activerecord_6.1.gemfile +13 -0
- data/gemfiles/activerecord_6.1.gemfile.lock +88 -0
- data/lib/cursor_pager/configuration.rb +14 -0
- data/lib/cursor_pager/page.rb +69 -10
- data/lib/cursor_pager/version.rb +1 -1
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f09f4f6c7c439bf8dc8d20ca19bce69cd7b67d0f6ffe9f8c91be7f3a673ccd6
|
4
|
+
data.tar.gz: c79f9159200f3013be13892fd72b51f4ccba8c5111bd17411bde6db2deb9ea8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 469e8c30a4974b1f7be434169c46b82518de4c2f034f4c36ba01abf09b23855dd87b1d3689ef426b27b119283db25c4ba878462304c143084205e196571a7acd
|
7
|
+
data.tar.gz: b16fd57909391d6d442291baef95adb33ec39181db7a4a1063cbb993ed0cea678fcf9e2ba502992bd91991e18d9246c564b47f1ca83e912c46da2a85bdc0b427
|
data/.github/workflows/ci.yml
CHANGED
@@ -2,17 +2,23 @@ name: CI
|
|
2
2
|
|
3
3
|
on:
|
4
4
|
push:
|
5
|
-
branches: [
|
5
|
+
branches: [main]
|
6
6
|
pull_request:
|
7
|
-
branches: [
|
7
|
+
branches: [main]
|
8
8
|
|
9
9
|
jobs:
|
10
10
|
test:
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
strategy:
|
13
|
+
fail-fast: false
|
13
14
|
matrix:
|
14
|
-
|
15
|
-
|
15
|
+
include:
|
16
|
+
- ruby-version: "2.6"
|
17
|
+
activerecord-version: "5.2"
|
18
|
+
- ruby-version: "2.7"
|
19
|
+
activerecord-version: "6.0"
|
20
|
+
- ruby-version: "3.0"
|
21
|
+
activerecord-version: "6.1"
|
16
22
|
|
17
23
|
services:
|
18
24
|
db:
|
@@ -31,9 +37,9 @@ jobs:
|
|
31
37
|
uses: actions/cache@v1
|
32
38
|
with:
|
33
39
|
path: vendor/bundle
|
34
|
-
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
40
|
+
key: ${{ runner.os }}-gems-${{ matrix.ruby-version }}-${{ hashFiles('**/Gemfile.lock') }}
|
35
41
|
restore-keys: |
|
36
|
-
${{ runner.os }}-gems-
|
42
|
+
${{ runner.os }}-gems-${{ matrix.ruby-version }}-
|
37
43
|
|
38
44
|
- name: Set up Ruby ${{ matrix.ruby-version }}
|
39
45
|
uses: ruby/setup-ruby@v1
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.7.
|
1
|
+
2.7.2
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,4 +5,50 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
-
## Unreleased
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
## [0.2.4] - 2021-04-01
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
|
14
|
+
* Fix `Page#next_page?` when given a grouped relation #15
|
15
|
+
|
16
|
+
## [0.2.3] - 2020-11-23
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
|
20
|
+
* Fix using cursors with preloaded or eager loaded associations #13
|
21
|
+
|
22
|
+
## [0.2.2] - 2020-09-29
|
23
|
+
|
24
|
+
### Fixed
|
25
|
+
|
26
|
+
* Fix checking if the next page exists when a custom select is given #12
|
27
|
+
|
28
|
+
## [0.2.1] - 2020-05-13
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
|
32
|
+
* Fix fetching cursor values when relation has join and string order values #9
|
33
|
+
|
34
|
+
## [0.2.0] - 2020-04-23
|
35
|
+
|
36
|
+
### Added
|
37
|
+
|
38
|
+
* `first_cursor` & `last_cursor` convenience methods
|
39
|
+
* Configurable default & maximum page sizes #6
|
40
|
+
|
41
|
+
## [0.1.0] - 2020-04-23
|
42
|
+
|
43
|
+
### Added
|
44
|
+
|
45
|
+
* First implementation of cursor-pased pagination #2
|
46
|
+
* Configurable cursor encoder #3
|
47
|
+
|
48
|
+
[Unreleased]: https://github.com/check24-profis/shared-cursor-pager/compare/v0.2.4...HEAD
|
49
|
+
[0.2.4]: https://github.com/check24-profis/shared-cursor-pager/compare/v0.2.3...v0.2.4
|
50
|
+
[0.2.3]: https://github.com/check24-profis/shared-cursor-pager/compare/v0.2.2...v0.2.3
|
51
|
+
[0.2.2]: https://github.com/check24-profis/shared-cursor-pager/compare/v0.2.1...v0.2.2
|
52
|
+
[0.2.1]: https://github.com/check24-profis/shared-cursor-pager/compare/v0.2.0...v0.2.1
|
53
|
+
[0.2.0]: https://github.com/check24-profis/shared-cursor-pager/compare/v0.1.0...v0.2.0
|
54
|
+
[0.1.0]: https://github.com/check24-profis/shared-cursor-pager/releases/tag/v0.1.0
|
data/Gemfile.lock
CHANGED
@@ -1,73 +1,75 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cursor_pager (0.
|
4
|
+
cursor_pager (0.2.4)
|
5
5
|
activerecord (>= 5.2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (6.
|
11
|
-
activesupport (= 6.
|
12
|
-
activerecord (6.
|
13
|
-
activemodel (= 6.
|
14
|
-
activesupport (= 6.
|
15
|
-
activesupport (6.
|
10
|
+
activemodel (6.1.3.1)
|
11
|
+
activesupport (= 6.1.3.1)
|
12
|
+
activerecord (6.1.3.1)
|
13
|
+
activemodel (= 6.1.3.1)
|
14
|
+
activesupport (= 6.1.3.1)
|
15
|
+
activesupport (6.1.3.1)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
-
i18n (>=
|
18
|
-
minitest (
|
19
|
-
tzinfo (~>
|
20
|
-
zeitwerk (~> 2.
|
21
|
-
appraisal (2.
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
minitest (>= 5.1)
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
zeitwerk (~> 2.3)
|
21
|
+
appraisal (2.4.0)
|
22
22
|
bundler
|
23
23
|
rake
|
24
24
|
thor (>= 0.14.0)
|
25
|
-
ast (2.4.
|
26
|
-
concurrent-ruby (1.1.
|
27
|
-
database_cleaner (
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
diff-lcs (1.
|
32
|
-
i18n (1.8.
|
25
|
+
ast (2.4.2)
|
26
|
+
concurrent-ruby (1.1.8)
|
27
|
+
database_cleaner-active_record (2.0.0)
|
28
|
+
activerecord (>= 5.a)
|
29
|
+
database_cleaner-core (~> 2.0.0)
|
30
|
+
database_cleaner-core (2.0.1)
|
31
|
+
diff-lcs (1.4.4)
|
32
|
+
i18n (1.8.10)
|
33
33
|
concurrent-ruby (~> 1.0)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
ast (~> 2.4.0)
|
34
|
+
minitest (5.14.4)
|
35
|
+
parallel (1.20.1)
|
36
|
+
parser (3.0.0.0)
|
37
|
+
ast (~> 2.4.1)
|
39
38
|
pg (1.2.3)
|
40
39
|
rainbow (3.0.0)
|
41
40
|
rake (12.3.3)
|
41
|
+
regexp_parser (2.1.1)
|
42
42
|
rexml (3.2.4)
|
43
|
-
rspec (3.
|
44
|
-
rspec-core (~> 3.
|
45
|
-
rspec-expectations (~> 3.
|
46
|
-
rspec-mocks (~> 3.
|
47
|
-
rspec-core (3.
|
48
|
-
rspec-support (~> 3.
|
49
|
-
rspec-expectations (3.
|
43
|
+
rspec (3.10.0)
|
44
|
+
rspec-core (~> 3.10.0)
|
45
|
+
rspec-expectations (~> 3.10.0)
|
46
|
+
rspec-mocks (~> 3.10.0)
|
47
|
+
rspec-core (3.10.1)
|
48
|
+
rspec-support (~> 3.10.0)
|
49
|
+
rspec-expectations (3.10.1)
|
50
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
-
rspec-support (~> 3.
|
52
|
-
rspec-mocks (3.
|
51
|
+
rspec-support (~> 3.10.0)
|
52
|
+
rspec-mocks (3.10.2)
|
53
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
-
rspec-support (~> 3.
|
55
|
-
rspec-support (3.
|
56
|
-
rubocop (
|
57
|
-
jaro_winkler (~> 1.5.1)
|
54
|
+
rspec-support (~> 3.10.0)
|
55
|
+
rspec-support (3.10.2)
|
56
|
+
rubocop (1.12.0)
|
58
57
|
parallel (~> 1.10)
|
59
|
-
parser (>=
|
58
|
+
parser (>= 3.0.0.0)
|
60
59
|
rainbow (>= 2.2.2, < 4.0)
|
60
|
+
regexp_parser (>= 1.8, < 3.0)
|
61
61
|
rexml
|
62
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
62
63
|
ruby-progressbar (~> 1.7)
|
63
|
-
unicode-display_width (>= 1.4.0, <
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
64
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
65
|
+
rubocop-ast (1.4.1)
|
66
|
+
parser (>= 2.7.1.5)
|
67
|
+
ruby-progressbar (1.11.0)
|
68
|
+
thor (1.1.0)
|
69
|
+
tzinfo (2.0.4)
|
70
|
+
concurrent-ruby (~> 1.0)
|
71
|
+
unicode-display_width (2.0.0)
|
72
|
+
zeitwerk (2.4.2)
|
71
73
|
|
72
74
|
PLATFORMS
|
73
75
|
ruby
|
@@ -82,4 +84,4 @@ DEPENDENCIES
|
|
82
84
|
rubocop
|
83
85
|
|
84
86
|
BUNDLED WITH
|
85
|
-
2.
|
87
|
+
2.2.15
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# CursorPager
|
2
2
|
|
3
|
-
![build](https://github.com/
|
3
|
+
![build](https://github.com/check24-profis/shared-cursor-pager/workflows/CI/badge.svg) [![Gem Version](https://badge.fury.io/rb/cursor_pager.svg)](https://badge.fury.io/rb/cursor_pager)
|
4
4
|
|
5
5
|
A small and easy-to-use library that aims to make it easy to build Rails APIs
|
6
6
|
with cursor-based pagination (aka keyset pagination).
|
@@ -45,7 +45,9 @@ To get information about the page or generate a cursor
|
|
45
45
|
```ruby
|
46
46
|
page.previous_page? # Tells you if there is a previous page
|
47
47
|
page.next_page? # Tells you if there is a next page
|
48
|
-
page.cursor_for(page.records.last) #
|
48
|
+
page.cursor_for(page.records.last) # Generates a cursor for a specific item
|
49
|
+
page.first_cursor # Generates a cursor for the first item
|
50
|
+
page.last_cursor # Generates a cursor for the last item
|
49
51
|
```
|
50
52
|
|
51
53
|
To fetch the first then usres after a certain cursor
|
@@ -65,6 +67,8 @@ page.records
|
|
65
67
|
|
66
68
|
## Configuration
|
67
69
|
|
70
|
+
### Encoder
|
71
|
+
|
68
72
|
By default cursors are base64 encoded primary keys of the records. If you wish
|
69
73
|
to change that because you want to add encryption or something similiar, you
|
70
74
|
can provide your own encoder class.
|
@@ -85,6 +89,18 @@ CursorPager.configure do |config|
|
|
85
89
|
end
|
86
90
|
```
|
87
91
|
|
92
|
+
### Default & Maximum Page Size
|
93
|
+
|
94
|
+
The default & maximum page sizes are configured as `nil` (unlimited) by default.
|
95
|
+
You can however set your own values.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
CursorPager.configure do |config|
|
99
|
+
config.default_page_size = 25
|
100
|
+
config.maximum_page_size = 100
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
88
104
|
## Not (yet) supported
|
89
105
|
|
90
106
|
* Ordering by SQL alias or function
|
@@ -103,5 +119,5 @@ The gem is available as open source under the terms of the [MIT License].
|
|
103
119
|
|
104
120
|
[JSON API Cursor Pagination]: https://jsonapi.org/profiles/ethanresnick/cursor-pagination/
|
105
121
|
[Relay's GraphQL Cursor Connection]: https://relay.dev/graphql/connections.htm
|
106
|
-
[code of conduct]: https://github.com/
|
122
|
+
[code of conduct]: https://github.com/check24-profis/shared-cursor-pager/blob/main/CODE_OF_CONDUCT.md
|
107
123
|
[MIT License]: https://opensource.org/licenses/MIT
|
data/cursor_pager.gemspec
CHANGED
@@ -9,14 +9,14 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["bastian.bartmann@check24.de"]
|
10
10
|
|
11
11
|
spec.summary = "Cursor-based pagination for ActiveRecord relations."
|
12
|
-
spec.homepage = "https://github.com/
|
12
|
+
spec.homepage = "https://github.com/check24-profis/shared-cursor-pager"
|
13
13
|
spec.license = "MIT"
|
14
14
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
15
15
|
|
16
16
|
spec.metadata["homepage_uri"] = spec.homepage
|
17
17
|
spec.metadata["source_code_uri"] = spec.homepage
|
18
18
|
spec.metadata["changelog_uri"] =
|
19
|
-
"https://github.com/
|
19
|
+
"https://github.com/check24-profis/shared-cursor-pager/blob/main/CHANGELOG.md"
|
20
20
|
|
21
21
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
22
|
`git ls-files -z`
|
@@ -1,71 +1,74 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
cursor_pager (0.
|
4
|
+
cursor_pager (0.2.4)
|
5
5
|
activerecord (>= 5.2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (5.2.4.
|
11
|
-
activesupport (= 5.2.4.
|
12
|
-
activerecord (5.2.4.
|
13
|
-
activemodel (= 5.2.4.
|
14
|
-
activesupport (= 5.2.4.
|
10
|
+
activemodel (5.2.4.4)
|
11
|
+
activesupport (= 5.2.4.4)
|
12
|
+
activerecord (5.2.4.4)
|
13
|
+
activemodel (= 5.2.4.4)
|
14
|
+
activesupport (= 5.2.4.4)
|
15
15
|
arel (>= 9.0)
|
16
|
-
activesupport (5.2.4.
|
16
|
+
activesupport (5.2.4.4)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 0.7, < 2)
|
19
19
|
minitest (~> 5.1)
|
20
20
|
tzinfo (~> 1.1)
|
21
|
-
appraisal (2.
|
21
|
+
appraisal (2.3.0)
|
22
22
|
bundler
|
23
23
|
rake
|
24
24
|
thor (>= 0.14.0)
|
25
25
|
arel (9.0.0)
|
26
|
-
ast (2.4.
|
27
|
-
concurrent-ruby (1.1.
|
28
|
-
database_cleaner (1.8.
|
26
|
+
ast (2.4.1)
|
27
|
+
concurrent-ruby (1.1.7)
|
28
|
+
database_cleaner (1.8.5)
|
29
29
|
database_cleaner-active_record (1.8.0)
|
30
30
|
activerecord
|
31
31
|
database_cleaner (~> 1.8.0)
|
32
|
-
diff-lcs (1.
|
33
|
-
i18n (1.8.
|
32
|
+
diff-lcs (1.4.4)
|
33
|
+
i18n (1.8.5)
|
34
34
|
concurrent-ruby (~> 1.0)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
ast (~> 2.4.0)
|
35
|
+
minitest (5.14.2)
|
36
|
+
parallel (1.20.1)
|
37
|
+
parser (2.7.2.0)
|
38
|
+
ast (~> 2.4.1)
|
40
39
|
pg (1.2.3)
|
41
40
|
rainbow (3.0.0)
|
42
41
|
rake (12.3.3)
|
42
|
+
regexp_parser (1.8.2)
|
43
43
|
rexml (3.2.4)
|
44
|
-
rspec (3.
|
45
|
-
rspec-core (~> 3.
|
46
|
-
rspec-expectations (~> 3.
|
47
|
-
rspec-mocks (~> 3.
|
48
|
-
rspec-core (3.
|
49
|
-
rspec-support (~> 3.
|
50
|
-
rspec-expectations (3.
|
44
|
+
rspec (3.10.0)
|
45
|
+
rspec-core (~> 3.10.0)
|
46
|
+
rspec-expectations (~> 3.10.0)
|
47
|
+
rspec-mocks (~> 3.10.0)
|
48
|
+
rspec-core (3.10.0)
|
49
|
+
rspec-support (~> 3.10.0)
|
50
|
+
rspec-expectations (3.10.0)
|
51
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
-
rspec-support (~> 3.
|
53
|
-
rspec-mocks (3.
|
52
|
+
rspec-support (~> 3.10.0)
|
53
|
+
rspec-mocks (3.10.0)
|
54
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
-
rspec-support (~> 3.
|
56
|
-
rspec-support (3.
|
57
|
-
rubocop (
|
58
|
-
jaro_winkler (~> 1.5.1)
|
55
|
+
rspec-support (~> 3.10.0)
|
56
|
+
rspec-support (3.10.0)
|
57
|
+
rubocop (1.4.0)
|
59
58
|
parallel (~> 1.10)
|
60
|
-
parser (>= 2.7.
|
59
|
+
parser (>= 2.7.1.5)
|
61
60
|
rainbow (>= 2.2.2, < 4.0)
|
61
|
+
regexp_parser (>= 1.8)
|
62
62
|
rexml
|
63
|
+
rubocop-ast (>= 1.1.1)
|
63
64
|
ruby-progressbar (~> 1.7)
|
64
65
|
unicode-display_width (>= 1.4.0, < 2.0)
|
66
|
+
rubocop-ast (1.1.1)
|
67
|
+
parser (>= 2.7.1.5)
|
65
68
|
ruby-progressbar (1.10.1)
|
66
69
|
thor (1.0.1)
|
67
70
|
thread_safe (0.3.6)
|
68
|
-
tzinfo (1.2.
|
71
|
+
tzinfo (1.2.8)
|
69
72
|
thread_safe (~> 0.1)
|
70
73
|
unicode-display_width (1.7.0)
|
71
74
|
|
@@ -83,4 +86,4 @@ DEPENDENCIES
|
|
83
86
|
rubocop
|
84
87
|
|
85
88
|
BUNDLED WITH
|
86
|
-
2.
|
89
|
+
2.2.15
|
@@ -1,73 +1,76 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
cursor_pager (0.
|
4
|
+
cursor_pager (0.2.4)
|
5
5
|
activerecord (>= 5.2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (6.0.
|
11
|
-
activesupport (= 6.0.
|
12
|
-
activerecord (6.0.
|
13
|
-
activemodel (= 6.0.
|
14
|
-
activesupport (= 6.0.
|
15
|
-
activesupport (6.0.
|
10
|
+
activemodel (6.0.3.4)
|
11
|
+
activesupport (= 6.0.3.4)
|
12
|
+
activerecord (6.0.3.4)
|
13
|
+
activemodel (= 6.0.3.4)
|
14
|
+
activesupport (= 6.0.3.4)
|
15
|
+
activesupport (6.0.3.4)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 0.7, < 2)
|
18
18
|
minitest (~> 5.1)
|
19
19
|
tzinfo (~> 1.1)
|
20
|
-
zeitwerk (~> 2.2)
|
21
|
-
appraisal (2.
|
20
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
21
|
+
appraisal (2.3.0)
|
22
22
|
bundler
|
23
23
|
rake
|
24
24
|
thor (>= 0.14.0)
|
25
|
-
ast (2.4.
|
26
|
-
concurrent-ruby (1.1.
|
27
|
-
database_cleaner (1.8.
|
25
|
+
ast (2.4.1)
|
26
|
+
concurrent-ruby (1.1.7)
|
27
|
+
database_cleaner (1.8.5)
|
28
28
|
database_cleaner-active_record (1.8.0)
|
29
29
|
activerecord
|
30
30
|
database_cleaner (~> 1.8.0)
|
31
|
-
diff-lcs (1.
|
32
|
-
i18n (1.8.
|
31
|
+
diff-lcs (1.4.4)
|
32
|
+
i18n (1.8.5)
|
33
33
|
concurrent-ruby (~> 1.0)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
ast (~> 2.4.0)
|
34
|
+
minitest (5.14.2)
|
35
|
+
parallel (1.20.1)
|
36
|
+
parser (2.7.2.0)
|
37
|
+
ast (~> 2.4.1)
|
39
38
|
pg (1.2.3)
|
40
39
|
rainbow (3.0.0)
|
41
40
|
rake (12.3.3)
|
41
|
+
regexp_parser (1.8.2)
|
42
42
|
rexml (3.2.4)
|
43
|
-
rspec (3.
|
44
|
-
rspec-core (~> 3.
|
45
|
-
rspec-expectations (~> 3.
|
46
|
-
rspec-mocks (~> 3.
|
47
|
-
rspec-core (3.
|
48
|
-
rspec-support (~> 3.
|
49
|
-
rspec-expectations (3.
|
43
|
+
rspec (3.10.0)
|
44
|
+
rspec-core (~> 3.10.0)
|
45
|
+
rspec-expectations (~> 3.10.0)
|
46
|
+
rspec-mocks (~> 3.10.0)
|
47
|
+
rspec-core (3.10.0)
|
48
|
+
rspec-support (~> 3.10.0)
|
49
|
+
rspec-expectations (3.10.0)
|
50
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
-
rspec-support (~> 3.
|
52
|
-
rspec-mocks (3.
|
51
|
+
rspec-support (~> 3.10.0)
|
52
|
+
rspec-mocks (3.10.0)
|
53
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
-
rspec-support (~> 3.
|
55
|
-
rspec-support (3.
|
56
|
-
rubocop (
|
57
|
-
jaro_winkler (~> 1.5.1)
|
54
|
+
rspec-support (~> 3.10.0)
|
55
|
+
rspec-support (3.10.0)
|
56
|
+
rubocop (1.4.0)
|
58
57
|
parallel (~> 1.10)
|
59
|
-
parser (>= 2.7.
|
58
|
+
parser (>= 2.7.1.5)
|
60
59
|
rainbow (>= 2.2.2, < 4.0)
|
60
|
+
regexp_parser (>= 1.8)
|
61
61
|
rexml
|
62
|
+
rubocop-ast (>= 1.1.1)
|
62
63
|
ruby-progressbar (~> 1.7)
|
63
64
|
unicode-display_width (>= 1.4.0, < 2.0)
|
65
|
+
rubocop-ast (1.1.1)
|
66
|
+
parser (>= 2.7.1.5)
|
64
67
|
ruby-progressbar (1.10.1)
|
65
68
|
thor (1.0.1)
|
66
69
|
thread_safe (0.3.6)
|
67
|
-
tzinfo (1.2.
|
70
|
+
tzinfo (1.2.8)
|
68
71
|
thread_safe (~> 0.1)
|
69
72
|
unicode-display_width (1.7.0)
|
70
|
-
zeitwerk (2.
|
73
|
+
zeitwerk (2.4.1)
|
71
74
|
|
72
75
|
PLATFORMS
|
73
76
|
ruby
|
@@ -83,4 +86,4 @@ DEPENDENCIES
|
|
83
86
|
rubocop
|
84
87
|
|
85
88
|
BUNDLED WITH
|
86
|
-
2.
|
89
|
+
2.2.15
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal"
|
6
|
+
gem "database_cleaner-active_record"
|
7
|
+
gem "pg"
|
8
|
+
gem "rake", "~> 12.0"
|
9
|
+
gem "rspec", "~> 3.0"
|
10
|
+
gem "rubocop"
|
11
|
+
gem "activerecord", "~> 6.1.0"
|
12
|
+
|
13
|
+
gemspec path: "../"
|
@@ -0,0 +1,88 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
cursor_pager (0.2.4)
|
5
|
+
activerecord (>= 5.2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (6.1.3.1)
|
11
|
+
activesupport (= 6.1.3.1)
|
12
|
+
activerecord (6.1.3.1)
|
13
|
+
activemodel (= 6.1.3.1)
|
14
|
+
activesupport (= 6.1.3.1)
|
15
|
+
activesupport (6.1.3.1)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
minitest (>= 5.1)
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
zeitwerk (~> 2.3)
|
21
|
+
appraisal (2.4.0)
|
22
|
+
bundler
|
23
|
+
rake
|
24
|
+
thor (>= 0.14.0)
|
25
|
+
ast (2.4.2)
|
26
|
+
concurrent-ruby (1.1.8)
|
27
|
+
database_cleaner-active_record (2.0.0)
|
28
|
+
activerecord (>= 5.a)
|
29
|
+
database_cleaner-core (~> 2.0.0)
|
30
|
+
database_cleaner-core (2.0.1)
|
31
|
+
diff-lcs (1.4.4)
|
32
|
+
i18n (1.8.10)
|
33
|
+
concurrent-ruby (~> 1.0)
|
34
|
+
minitest (5.14.4)
|
35
|
+
parallel (1.20.1)
|
36
|
+
parser (3.0.0.0)
|
37
|
+
ast (~> 2.4.1)
|
38
|
+
pg (1.2.3)
|
39
|
+
rainbow (3.0.0)
|
40
|
+
rake (12.3.3)
|
41
|
+
regexp_parser (2.1.1)
|
42
|
+
rexml (3.2.4)
|
43
|
+
rspec (3.10.0)
|
44
|
+
rspec-core (~> 3.10.0)
|
45
|
+
rspec-expectations (~> 3.10.0)
|
46
|
+
rspec-mocks (~> 3.10.0)
|
47
|
+
rspec-core (3.10.1)
|
48
|
+
rspec-support (~> 3.10.0)
|
49
|
+
rspec-expectations (3.10.1)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.10.0)
|
52
|
+
rspec-mocks (3.10.2)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.10.0)
|
55
|
+
rspec-support (3.10.2)
|
56
|
+
rubocop (1.12.0)
|
57
|
+
parallel (~> 1.10)
|
58
|
+
parser (>= 3.0.0.0)
|
59
|
+
rainbow (>= 2.2.2, < 4.0)
|
60
|
+
regexp_parser (>= 1.8, < 3.0)
|
61
|
+
rexml
|
62
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
63
|
+
ruby-progressbar (~> 1.7)
|
64
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
65
|
+
rubocop-ast (1.4.1)
|
66
|
+
parser (>= 2.7.1.5)
|
67
|
+
ruby-progressbar (1.11.0)
|
68
|
+
thor (1.1.0)
|
69
|
+
tzinfo (2.0.4)
|
70
|
+
concurrent-ruby (~> 1.0)
|
71
|
+
unicode-display_width (2.0.0)
|
72
|
+
zeitwerk (2.4.2)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
x86_64-darwin-19
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
activerecord (~> 6.1.0)
|
79
|
+
appraisal
|
80
|
+
cursor_pager!
|
81
|
+
database_cleaner-active_record
|
82
|
+
pg
|
83
|
+
rake (~> 12.0)
|
84
|
+
rspec (~> 3.0)
|
85
|
+
rubocop
|
86
|
+
|
87
|
+
BUNDLED WITH
|
88
|
+
2.2.15
|
@@ -5,10 +5,24 @@ module CursorPager
|
|
5
5
|
# Encapulates all the configuration for the library.
|
6
6
|
class Configuration
|
7
7
|
# The encoder that will be used to encode & decode cursors.
|
8
|
+
# Defaults to `Base64Encoder`.
|
8
9
|
attr_accessor :encoder
|
9
10
|
|
11
|
+
# The default page size that will be used if no `first` or `last` were
|
12
|
+
# specified. Every record fitting the cursor constraints will be returned
|
13
|
+
# if it's set to `nil`.
|
14
|
+
# Defaults to `nil`.
|
15
|
+
attr_accessor :default_page_size
|
16
|
+
|
17
|
+
# The maximum allowed page size. Clients will never receive more records per
|
18
|
+
# page than is sepcified here. There is no maximum if this is set to `nil`.
|
19
|
+
# Defaults to `nil`.
|
20
|
+
attr_accessor :maximum_page_size
|
21
|
+
|
10
22
|
def initialize
|
11
23
|
@encoder = Base64Encoder
|
24
|
+
@default_page_size = nil
|
25
|
+
@maximum_page_size = nil
|
12
26
|
end
|
13
27
|
end
|
14
28
|
|
data/lib/cursor_pager/page.rb
CHANGED
@@ -3,12 +3,19 @@
|
|
3
3
|
module CursorPager
|
4
4
|
# The main class that coordinates the whole pagination.
|
5
5
|
class Page
|
6
|
-
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
attr_reader :relation, :first_value, :last_value, :after, :before,
|
9
|
+
:order_values
|
10
|
+
|
11
|
+
def_delegators :@configuration, :encoder, :default_page_size,
|
12
|
+
:maximum_page_size
|
7
13
|
|
8
14
|
def initialize(relation, first: nil, last: nil, after: nil, before: nil)
|
15
|
+
@configuration = CursorPager.configuration
|
9
16
|
@relation = relation
|
10
|
-
@
|
11
|
-
@
|
17
|
+
@first_value = first
|
18
|
+
@last_value = last
|
12
19
|
@after = after
|
13
20
|
@before = before
|
14
21
|
@order_values = OrderValues.from_relation(relation)
|
@@ -17,6 +24,28 @@ module CursorPager
|
|
17
24
|
verify_order_directions!
|
18
25
|
end
|
19
26
|
|
27
|
+
# A capped `first` value.
|
28
|
+
# The underlying instance variable `first_value` doesn't have limits on it.
|
29
|
+
# If neither `first` nor `last` is given, but `default_page_size` or
|
30
|
+
# `maximum_page_size` are configured, they will be used for first.
|
31
|
+
def first
|
32
|
+
@first ||= begin
|
33
|
+
capped = limit_pagination_argument(first_value)
|
34
|
+
|
35
|
+
if capped.nil? && last.nil?
|
36
|
+
capped = default_page_size || maximum_page_size
|
37
|
+
end
|
38
|
+
|
39
|
+
capped
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# A capped `last` value.
|
44
|
+
# The underlying instance variable `last_value` doesn't have limits on it.
|
45
|
+
def last
|
46
|
+
@last ||= limit_pagination_argument(last_value)
|
47
|
+
end
|
48
|
+
|
20
49
|
def previous_page?
|
21
50
|
@previous_page ||= if after_limit_value.present?
|
22
51
|
true
|
@@ -31,16 +60,26 @@ module CursorPager
|
|
31
60
|
@next_page ||= if before_limit_value.present?
|
32
61
|
true
|
33
62
|
elsif first
|
34
|
-
sliced_relation.
|
63
|
+
sliced_relation.offset(first).exists?
|
35
64
|
else
|
36
65
|
false
|
37
66
|
end
|
38
67
|
end
|
39
68
|
|
40
69
|
def cursor_for(item)
|
70
|
+
return if item.nil?
|
71
|
+
|
41
72
|
encoder.encode(item.id.to_s)
|
42
73
|
end
|
43
74
|
|
75
|
+
def first_cursor
|
76
|
+
cursor_for(records.first)
|
77
|
+
end
|
78
|
+
|
79
|
+
def last_cursor
|
80
|
+
cursor_for(records.last)
|
81
|
+
end
|
82
|
+
|
44
83
|
def records
|
45
84
|
@records ||= limited_relation.to_a
|
46
85
|
end
|
@@ -67,6 +106,21 @@ module CursorPager
|
|
67
106
|
raise ConflictingOrdersError
|
68
107
|
end
|
69
108
|
|
109
|
+
# Used to cap `first` and `last` arguments.
|
110
|
+
# Returns `nil` if the argument is `nil`, otherwise a value between `0` and
|
111
|
+
# `maximum_page_size`.
|
112
|
+
def limit_pagination_argument(argument)
|
113
|
+
return if argument.nil?
|
114
|
+
|
115
|
+
if argument.negative?
|
116
|
+
argument = 0
|
117
|
+
elsif maximum_page_size && argument > maximum_page_size
|
118
|
+
argument = maximum_page_size
|
119
|
+
end
|
120
|
+
|
121
|
+
argument
|
122
|
+
end
|
123
|
+
|
70
124
|
def limited_relation
|
71
125
|
@limited_relation ||= LimitRelation.new(sliced_relation, first, last).call
|
72
126
|
end
|
@@ -93,18 +147,23 @@ module CursorPager
|
|
93
147
|
end
|
94
148
|
|
95
149
|
def limit_value_for(cursor)
|
96
|
-
|
97
|
-
|
98
|
-
selects = order_values.map(&:select_string)
|
99
|
-
item = relation.where(id: id).select(selects).first
|
150
|
+
item = limit_item_for(cursor)
|
100
151
|
|
101
152
|
raise CursorNotFoundError, cursor if item.blank?
|
102
153
|
|
103
154
|
order_values.map { |value| item[value.select_alias] }
|
104
155
|
end
|
105
156
|
|
106
|
-
def
|
107
|
-
|
157
|
+
def limit_item_for(cursor)
|
158
|
+
id = encoder.decode(cursor)
|
159
|
+
|
160
|
+
selects = order_values.map(&:select_string)
|
161
|
+
ordered_relation_copy = ordered_relation.dup
|
162
|
+
|
163
|
+
ordered_relation_copy.preload_values = []
|
164
|
+
ordered_relation_copy.eager_load_values = []
|
165
|
+
ordered_relation_copy
|
166
|
+
.unscope(:includes).where(id: id).select(selects).first
|
108
167
|
end
|
109
168
|
end
|
110
169
|
end
|
data/lib/cursor_pager/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cursor_pager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bastian Bartmann
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 5.2.0
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- bastian.bartmann@check24.de
|
30
30
|
executables: []
|
@@ -53,6 +53,8 @@ files:
|
|
53
53
|
- gemfiles/activerecord_5.2.gemfile.lock
|
54
54
|
- gemfiles/activerecord_6.0.gemfile
|
55
55
|
- gemfiles/activerecord_6.0.gemfile.lock
|
56
|
+
- gemfiles/activerecord_6.1.gemfile
|
57
|
+
- gemfiles/activerecord_6.1.gemfile.lock
|
56
58
|
- lib/cursor_pager.rb
|
57
59
|
- lib/cursor_pager/base64_encoder.rb
|
58
60
|
- lib/cursor_pager/configuration.rb
|
@@ -66,14 +68,14 @@ files:
|
|
66
68
|
- lib/cursor_pager/page.rb
|
67
69
|
- lib/cursor_pager/slice_relation.rb
|
68
70
|
- lib/cursor_pager/version.rb
|
69
|
-
homepage: https://github.com/
|
71
|
+
homepage: https://github.com/check24-profis/shared-cursor-pager
|
70
72
|
licenses:
|
71
73
|
- MIT
|
72
74
|
metadata:
|
73
|
-
homepage_uri: https://github.com/
|
74
|
-
source_code_uri: https://github.com/
|
75
|
-
changelog_uri: https://github.com/
|
76
|
-
post_install_message:
|
75
|
+
homepage_uri: https://github.com/check24-profis/shared-cursor-pager
|
76
|
+
source_code_uri: https://github.com/check24-profis/shared-cursor-pager
|
77
|
+
changelog_uri: https://github.com/check24-profis/shared-cursor-pager/blob/main/CHANGELOG.md
|
78
|
+
post_install_message:
|
77
79
|
rdoc_options: []
|
78
80
|
require_paths:
|
79
81
|
- lib
|
@@ -88,8 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
90
|
- !ruby/object:Gem::Version
|
89
91
|
version: '0'
|
90
92
|
requirements: []
|
91
|
-
rubygems_version: 3.1.
|
92
|
-
signing_key:
|
93
|
+
rubygems_version: 3.1.4
|
94
|
+
signing_key:
|
93
95
|
specification_version: 4
|
94
96
|
summary: Cursor-based pagination for ActiveRecord relations.
|
95
97
|
test_files: []
|