pagy_cursor 0.6.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b30060ea35c9a871c94d64e1bca0a9d289e13a9c3751b34aca9b5d358df1e7bf
4
- data.tar.gz: cc89b1199ee954188859776d4db32b6634ad8efef34f7ffa94a917802a5fd701
3
+ metadata.gz: 1aa8174327f3bb06b60e699eee881febd9d18671244ce25ebe2800466ea40158
4
+ data.tar.gz: 559f1193f7628bf2ae5137f050b42520f470ef49de90372bd1c2641765d1ba28
5
5
  SHA512:
6
- metadata.gz: 7450e19adcb2c85ff8cff5af659790ee7094a47580edc9e18ea6d5735da3c635357ca041908a2b160a1e19d3e45966c6e7f4757ea5d0881afa6d885d040f1cff
7
- data.tar.gz: bda797625d3c5579f6ae4f10f0a9a0623b41c11f82536047b3d95beabee13b8f0c16b2dc0fbf1daf390229f50c0e8e547cb2920ca7c47ca98f86e1fe69a776b8
6
+ metadata.gz: '0278d99df9abb81c852d8195e09376c7d3965f07a181357bfb16d3437aaa614240e59b81b7e9fc6f662370f6c1a26fe08bf54b920b9b08e092dffcebea866461'
7
+ data.tar.gz: 4a5469f8224cb91bf7f315f98f14a96e2488ebb24b76161834e9b6052b9a93de8fa8189e54beba3d1fee17e1965530e16cd0196556c9b3d597e6af6394d2c336
@@ -34,12 +34,17 @@ jobs:
34
34
  - ruby-version: 3.1
35
35
  env:
36
36
  BUNDLE_GEMFILE: gemfiles/active_record_70.gemfile
37
-
37
+ - ruby-version: 3.2
38
+ env:
39
+ BUNDLE_GEMFILE: gemfiles/active_record_70.gemfile
40
+ - ruby-version: 3.3
41
+ env:
42
+ BUNDLE_GEMFILE: gemfiles/active_record_71.gemfile
38
43
  fail-fast: false
39
44
  env: ${{ matrix.env }}
40
45
 
41
46
  steps:
42
- - uses: actions/checkout@v2
47
+ - uses: actions/checkout@v3
43
48
 
44
49
  - name: Set up ruby
45
50
  uses: ruby/setup-ruby@v1
@@ -80,10 +85,16 @@ jobs:
80
85
  - ruby-version: 3.1
81
86
  env:
82
87
  BUNDLE_GEMFILE: gemfiles/active_record_70.gemfile
88
+ - ruby-version: 3.2
89
+ env:
90
+ BUNDLE_GEMFILE: gemfiles/active_record_70.gemfile
91
+ - ruby-version: 3.3
92
+ env:
93
+ BUNDLE_GEMFILE: gemfiles/active_record_71.gemfile
83
94
  fail-fast: false
84
95
  env: ${{ matrix.env }}
85
96
  steps:
86
- - uses: actions/checkout@v2
97
+ - uses: actions/checkout@v3
87
98
 
88
99
  - name: Set up ruby
89
100
  uses: ruby/setup-ruby@v1
@@ -11,10 +11,10 @@ jobs:
11
11
 
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
- - name: Set up Ruby 2.6
14
+ - name: Set up Ruby 3.1
15
15
  uses: actions/setup-ruby@v1
16
16
  with:
17
- version: 2.6.x
17
+ version: 3.1
18
18
 
19
19
  - name: Publish to RubyGems
20
20
  run: |
data/Gemfile CHANGED
@@ -2,10 +2,10 @@ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
- gem "rails", "~> 7.0.0"
5
+ gem "rails", "~> 7.1.0"
6
6
  gem "pg"
7
- gem "sqlite3"
8
- # gem "mysql2"
9
- gem "pry"
7
+ gem "sqlite3", "~> 1.4"
8
+ gem "mysql2"
9
+
10
10
  # Specify your gem's dependencies in pagy_cursor.gemspec
11
11
  gemspec path: "./"
data/Gemfile.lock CHANGED
@@ -1,184 +1,214 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pagy_cursor (0.6.0)
4
+ pagy_cursor (0.7.0)
5
5
  activerecord (>= 5)
6
- pagy (>= 6, < 7)
6
+ pagy (>= 6, < 9)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (7.0.4.3)
12
- actionpack (= 7.0.4.3)
13
- activesupport (= 7.0.4.3)
11
+ actioncable (7.1.3.4)
12
+ actionpack (= 7.1.3.4)
13
+ activesupport (= 7.1.3.4)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (>= 0.6.1)
16
- actionmailbox (7.0.4.3)
17
- actionpack (= 7.0.4.3)
18
- activejob (= 7.0.4.3)
19
- activerecord (= 7.0.4.3)
20
- activestorage (= 7.0.4.3)
21
- activesupport (= 7.0.4.3)
16
+ zeitwerk (~> 2.6)
17
+ actionmailbox (7.1.3.4)
18
+ actionpack (= 7.1.3.4)
19
+ activejob (= 7.1.3.4)
20
+ activerecord (= 7.1.3.4)
21
+ activestorage (= 7.1.3.4)
22
+ activesupport (= 7.1.3.4)
22
23
  mail (>= 2.7.1)
23
24
  net-imap
24
25
  net-pop
25
26
  net-smtp
26
- actionmailer (7.0.4.3)
27
- actionpack (= 7.0.4.3)
28
- actionview (= 7.0.4.3)
29
- activejob (= 7.0.4.3)
30
- activesupport (= 7.0.4.3)
27
+ actionmailer (7.1.3.4)
28
+ actionpack (= 7.1.3.4)
29
+ actionview (= 7.1.3.4)
30
+ activejob (= 7.1.3.4)
31
+ activesupport (= 7.1.3.4)
31
32
  mail (~> 2.5, >= 2.5.4)
32
33
  net-imap
33
34
  net-pop
34
35
  net-smtp
35
- rails-dom-testing (~> 2.0)
36
- actionpack (7.0.4.3)
37
- actionview (= 7.0.4.3)
38
- activesupport (= 7.0.4.3)
39
- rack (~> 2.0, >= 2.2.0)
36
+ rails-dom-testing (~> 2.2)
37
+ actionpack (7.1.3.4)
38
+ actionview (= 7.1.3.4)
39
+ activesupport (= 7.1.3.4)
40
+ nokogiri (>= 1.8.5)
41
+ racc
42
+ rack (>= 2.2.4)
43
+ rack-session (>= 1.0.1)
40
44
  rack-test (>= 0.6.3)
41
- rails-dom-testing (~> 2.0)
42
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
- actiontext (7.0.4.3)
44
- actionpack (= 7.0.4.3)
45
- activerecord (= 7.0.4.3)
46
- activestorage (= 7.0.4.3)
47
- activesupport (= 7.0.4.3)
45
+ rails-dom-testing (~> 2.2)
46
+ rails-html-sanitizer (~> 1.6)
47
+ actiontext (7.1.3.4)
48
+ actionpack (= 7.1.3.4)
49
+ activerecord (= 7.1.3.4)
50
+ activestorage (= 7.1.3.4)
51
+ activesupport (= 7.1.3.4)
48
52
  globalid (>= 0.6.0)
49
53
  nokogiri (>= 1.8.5)
50
- actionview (7.0.4.3)
51
- activesupport (= 7.0.4.3)
54
+ actionview (7.1.3.4)
55
+ activesupport (= 7.1.3.4)
52
56
  builder (~> 3.1)
53
- erubi (~> 1.4)
54
- rails-dom-testing (~> 2.0)
55
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
- activejob (7.0.4.3)
57
- activesupport (= 7.0.4.3)
57
+ erubi (~> 1.11)
58
+ rails-dom-testing (~> 2.2)
59
+ rails-html-sanitizer (~> 1.6)
60
+ activejob (7.1.3.4)
61
+ activesupport (= 7.1.3.4)
58
62
  globalid (>= 0.3.6)
59
- activemodel (7.0.4.3)
60
- activesupport (= 7.0.4.3)
61
- activerecord (7.0.4.3)
62
- activemodel (= 7.0.4.3)
63
- activesupport (= 7.0.4.3)
64
- activestorage (7.0.4.3)
65
- actionpack (= 7.0.4.3)
66
- activejob (= 7.0.4.3)
67
- activerecord (= 7.0.4.3)
68
- activesupport (= 7.0.4.3)
63
+ activemodel (7.1.3.4)
64
+ activesupport (= 7.1.3.4)
65
+ activerecord (7.1.3.4)
66
+ activemodel (= 7.1.3.4)
67
+ activesupport (= 7.1.3.4)
68
+ timeout (>= 0.4.0)
69
+ activestorage (7.1.3.4)
70
+ actionpack (= 7.1.3.4)
71
+ activejob (= 7.1.3.4)
72
+ activerecord (= 7.1.3.4)
73
+ activesupport (= 7.1.3.4)
69
74
  marcel (~> 1.0)
70
- mini_mime (>= 1.1.0)
71
- activesupport (7.0.4.3)
75
+ activesupport (7.1.3.4)
76
+ base64
77
+ bigdecimal
72
78
  concurrent-ruby (~> 1.0, >= 1.0.2)
79
+ connection_pool (>= 2.2.5)
80
+ drb
73
81
  i18n (>= 1.6, < 2)
74
82
  minitest (>= 5.1)
83
+ mutex_m
75
84
  tzinfo (~> 2.0)
76
- builder (3.2.4)
77
- coderay (1.1.3)
78
- concurrent-ruby (1.2.2)
85
+ base64 (0.2.0)
86
+ bigdecimal (3.1.8)
87
+ builder (3.3.0)
88
+ concurrent-ruby (1.3.3)
89
+ connection_pool (2.4.1)
79
90
  crass (1.0.6)
80
- date (3.3.3)
81
- diff-lcs (1.5.0)
82
- erubi (1.12.0)
83
- globalid (1.1.0)
84
- activesupport (>= 5.0)
85
- i18n (1.12.0)
91
+ date (3.3.4)
92
+ diff-lcs (1.5.1)
93
+ drb (2.2.1)
94
+ erubi (1.13.0)
95
+ globalid (1.2.1)
96
+ activesupport (>= 6.1)
97
+ i18n (1.14.5)
86
98
  concurrent-ruby (~> 1.0)
87
- loofah (2.20.0)
99
+ io-console (0.7.2)
100
+ irb (1.14.0)
101
+ rdoc (>= 4.0.0)
102
+ reline (>= 0.4.2)
103
+ loofah (2.22.0)
88
104
  crass (~> 1.0.2)
89
- nokogiri (>= 1.5.9)
105
+ nokogiri (>= 1.12.0)
90
106
  mail (2.8.1)
91
107
  mini_mime (>= 0.1.1)
92
108
  net-imap
93
109
  net-pop
94
110
  net-smtp
95
- marcel (1.0.2)
96
- method_source (1.0.0)
97
- mini_mime (1.1.2)
98
- minitest (5.18.0)
99
- net-imap (0.3.4)
111
+ marcel (1.0.4)
112
+ mini_mime (1.1.5)
113
+ minitest (5.24.1)
114
+ mutex_m (0.2.0)
115
+ mysql2 (0.5.6)
116
+ net-imap (0.4.14)
100
117
  date
101
118
  net-protocol
102
119
  net-pop (0.1.2)
103
120
  net-protocol
104
- net-protocol (0.2.1)
121
+ net-protocol (0.2.2)
105
122
  timeout
106
- net-smtp (0.3.3)
123
+ net-smtp (0.5.0)
107
124
  net-protocol
108
- nio4r (2.5.9)
109
- nokogiri (1.14.3-x86_64-darwin)
125
+ nio4r (2.7.3)
126
+ nokogiri (1.16.7-x86_64-linux)
110
127
  racc (~> 1.4)
111
- pagy (6.0.3)
112
- pg (1.4.6)
113
- pry (0.14.2)
114
- coderay (~> 1.1)
115
- method_source (~> 1.0)
116
- racc (1.6.2)
117
- rack (2.2.6.4)
128
+ pagy (8.6.3)
129
+ pg (1.5.7)
130
+ psych (5.1.2)
131
+ stringio
132
+ racc (1.8.1)
133
+ rack (3.1.7)
134
+ rack-session (2.0.0)
135
+ rack (>= 3.0.0)
118
136
  rack-test (2.1.0)
119
137
  rack (>= 1.3)
120
- rails (7.0.4.3)
121
- actioncable (= 7.0.4.3)
122
- actionmailbox (= 7.0.4.3)
123
- actionmailer (= 7.0.4.3)
124
- actionpack (= 7.0.4.3)
125
- actiontext (= 7.0.4.3)
126
- actionview (= 7.0.4.3)
127
- activejob (= 7.0.4.3)
128
- activemodel (= 7.0.4.3)
129
- activerecord (= 7.0.4.3)
130
- activestorage (= 7.0.4.3)
131
- activesupport (= 7.0.4.3)
138
+ rackup (2.1.0)
139
+ rack (>= 3)
140
+ webrick (~> 1.8)
141
+ rails (7.1.3.4)
142
+ actioncable (= 7.1.3.4)
143
+ actionmailbox (= 7.1.3.4)
144
+ actionmailer (= 7.1.3.4)
145
+ actionpack (= 7.1.3.4)
146
+ actiontext (= 7.1.3.4)
147
+ actionview (= 7.1.3.4)
148
+ activejob (= 7.1.3.4)
149
+ activemodel (= 7.1.3.4)
150
+ activerecord (= 7.1.3.4)
151
+ activestorage (= 7.1.3.4)
152
+ activesupport (= 7.1.3.4)
132
153
  bundler (>= 1.15.0)
133
- railties (= 7.0.4.3)
134
- rails-dom-testing (2.0.3)
135
- activesupport (>= 4.2.0)
154
+ railties (= 7.1.3.4)
155
+ rails-dom-testing (2.2.0)
156
+ activesupport (>= 5.0.0)
157
+ minitest
136
158
  nokogiri (>= 1.6)
137
- rails-html-sanitizer (1.5.0)
138
- loofah (~> 2.19, >= 2.19.1)
139
- railties (7.0.4.3)
140
- actionpack (= 7.0.4.3)
141
- activesupport (= 7.0.4.3)
142
- method_source
159
+ rails-html-sanitizer (1.6.0)
160
+ loofah (~> 2.21)
161
+ nokogiri (~> 1.14)
162
+ railties (7.1.3.4)
163
+ actionpack (= 7.1.3.4)
164
+ activesupport (= 7.1.3.4)
165
+ irb
166
+ rackup (>= 1.0.0)
143
167
  rake (>= 12.2)
144
- thor (~> 1.0)
145
- zeitwerk (~> 2.5)
146
- rake (13.0.6)
147
- rspec (3.12.0)
148
- rspec-core (~> 3.12.0)
149
- rspec-expectations (~> 3.12.0)
150
- rspec-mocks (~> 3.12.0)
151
- rspec-core (3.12.2)
152
- rspec-support (~> 3.12.0)
153
- rspec-expectations (3.12.3)
168
+ thor (~> 1.0, >= 1.2.2)
169
+ zeitwerk (~> 2.6)
170
+ rake (13.2.1)
171
+ rdoc (6.7.0)
172
+ psych (>= 4.0.0)
173
+ reline (0.5.9)
174
+ io-console (~> 0.5)
175
+ rspec (3.13.0)
176
+ rspec-core (~> 3.13.0)
177
+ rspec-expectations (~> 3.13.0)
178
+ rspec-mocks (~> 3.13.0)
179
+ rspec-core (3.13.0)
180
+ rspec-support (~> 3.13.0)
181
+ rspec-expectations (3.13.1)
154
182
  diff-lcs (>= 1.2.0, < 2.0)
155
- rspec-support (~> 3.12.0)
156
- rspec-mocks (3.12.5)
183
+ rspec-support (~> 3.13.0)
184
+ rspec-mocks (3.13.1)
157
185
  diff-lcs (>= 1.2.0, < 2.0)
158
- rspec-support (~> 3.12.0)
159
- rspec-support (3.12.0)
160
- sqlite3 (1.6.2-x86_64-darwin)
161
- thor (1.2.1)
162
- timeout (0.3.2)
186
+ rspec-support (~> 3.13.0)
187
+ rspec-support (3.13.1)
188
+ sqlite3 (1.7.3-x86_64-linux)
189
+ stringio (3.1.1)
190
+ thor (1.3.1)
191
+ timeout (0.4.1)
163
192
  tzinfo (2.0.6)
164
193
  concurrent-ruby (~> 1.0)
165
- websocket-driver (0.7.5)
194
+ webrick (1.8.1)
195
+ websocket-driver (0.7.6)
166
196
  websocket-extensions (>= 0.1.0)
167
197
  websocket-extensions (0.1.5)
168
- zeitwerk (2.6.7)
198
+ zeitwerk (2.6.17)
169
199
 
170
200
  PLATFORMS
171
- x86_64-darwin-19
201
+ x86_64-linux
172
202
 
173
203
  DEPENDENCIES
174
- bundler (~> 2.0)
204
+ bundler (~> 2)
205
+ mysql2
175
206
  pagy_cursor!
176
207
  pg
177
- pry
178
- rails (~> 7.0.0)
179
- rake (~> 13.0)
180
- rspec (~> 3.0)
181
- sqlite3
208
+ rails (~> 7.1.0)
209
+ rake (~> 13)
210
+ rspec (~> 3)
211
+ sqlite3 (~> 1.4)
182
212
 
183
213
  BUNDLED WITH
184
- 2.2.22
214
+ 2.5.11
data/README.md CHANGED
@@ -55,8 +55,10 @@ pagy_cursor(Post.all, after: 10, order: {updated_at: :desc})
55
55
 
56
56
  Many thanks to:
57
57
  - [Uysim](https://github.com/Uysim)
58
+ - [Hirokazu Hata](https://github.com/h-michael)
58
59
  - [M. Yunan Helmy](https://github.com/yunanhelmy)
59
60
  - [Eumir Gaspar](https://github.com/corroded)
61
+ - [Jasl](https://github.com/jasl)
60
62
 
61
63
  ## Support Databases
62
64
 
@@ -73,7 +75,7 @@ To run tests in root folder of gem:
73
75
  - ```bundle exec rspec ```
74
76
 
75
77
  To test on specific Rails version
76
- ```export BUNDLE_GEMFILE=gemfiles/active_record_52.gemfile``` to work with Rails 5.2
78
+ ```export BUNDLE_GEMFILE=gemfiles/active_record_70.gemfile``` to work with Rails 7
77
79
 
78
80
  To play with app cd test/dummy and rails s -b 0.0.0.0 (before rails db:migrate).
79
81
 
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem "rails", "~> 7.1.0"
6
+ gem "pg"
7
+ gem "sqlite3", "~> 1.4"
8
+ gem "mysql2"
9
+
10
+ # Specify your gem's dependencies in pagy_cursor.gemspec
11
+ gemspec path: "../"
@@ -1,12 +1,13 @@
1
- class Pagy
1
+ # frozen_string_literal: true
2
2
 
3
+ class Pagy
3
4
  class Cursor < Pagy
4
- attr_reader :before, :after, :arel_table, :primary_key, :order, :comparation, :position
5
+ attr_reader :before, :after, :arel_table, :primary_key, :order, :comparison, :position
5
6
  attr_accessor :has_more
6
7
  alias_method :has_more?, :has_more
7
8
 
8
9
  def initialize(vars)
9
- @vars = DEFAULT.merge(vars.delete_if{|_,v| v.nil? || v == '' })
10
+ @vars = DEFAULT.merge(vars.delete_if { |_, v| v.nil? || v == "" })
10
11
  @items = vars[:items] || DEFAULT[:items]
11
12
  @before = vars[:before]
12
13
  @after = vars[:after]
@@ -15,32 +16,30 @@ class Pagy
15
16
  @reorder = vars[:order] || {}
16
17
 
17
18
  if @before.present? and @after.present?
18
- raise(ArgumentError, 'before and after can not be both mentioned')
19
+ raise(ArgumentError, "before and after can not be both mentioned")
19
20
  end
20
21
 
21
- if vars[:backend] == 'uuid'
22
-
23
- @comparation = 'lt' # arel table less than
22
+ if vars[:backend] == "uuid"
23
+ @comparison = "lt" # arel table less than
24
24
  @position = @before
25
- @order = @reorder.merge({ :created_at => :desc , @primary_key => :desc })
25
+ @order = @reorder.merge({ :created_at => :desc, @primary_key => :desc })
26
26
 
27
- if @after.present? || (@reorder.present? && @reorder.values.uniq.first.to_sym == :asc)
28
- @comparation = 'gt' # arel table greater than
27
+ if @after.present? || (@reorder.present? && @reorder.values.uniq.first&.to_sym == :asc)
28
+ @comparison = "gt" # arel table greater than
29
29
  @position = @after
30
- @order = @reorder.merge({ :created_at => :asc , @primary_key => :asc })
30
+ @order = @reorder.merge({ :created_at => :asc, @primary_key => :asc })
31
31
  end
32
32
  else
33
-
34
- @comparation = 'lt'
33
+ @comparison = "lt"
35
34
  @position = @before
36
35
  @order = @reorder.merge({ @primary_key => :desc })
37
36
 
38
- if @after.present? || (@reorder.present? && @reorder.values.uniq.first.to_sym == :asc)
39
- @comparation = 'gt'
37
+ if @after.present? || (@reorder.present? && @reorder.values.uniq.first&.to_sym == :asc)
38
+ @comparison = "gt"
40
39
  @position = @after
41
40
  @order = @reorder.merge({ @primary_key => :asc })
42
41
  end
43
42
  end
44
43
  end
45
44
  end
46
- end
45
+ end
@@ -1,29 +1,30 @@
1
- require 'pagy_cursor/pagy/cursor'
2
- class Pagy
3
-
4
- module Backend ; private # the whole module is private so no problem with including it in a controller
1
+ # frozen_string_literal: true
5
2
 
3
+ class Pagy
4
+ module Backend; private # the whole module is private so no problem with including it in a controller
6
5
  # Return Pagy object and items
7
- def pagy_cursor(collection, vars={}, options={})
6
+ def pagy_cursor(collection, vars = {})
8
7
  pagy = Pagy::Cursor.new(pagy_cursor_get_vars(collection, vars))
9
8
 
10
- items = pagy_cursor_get_items(collection, pagy, pagy.position)
11
- pagy.has_more = pagy_cursor_has_more?(items, pagy)
9
+ items = pagy_cursor_get_items(collection, pagy, pagy.position)
10
+ pagy.has_more = pagy_cursor_has_more?(items, pagy)
12
11
 
13
- return pagy, items
12
+ [pagy, items]
14
13
  end
15
14
 
16
15
  def pagy_cursor_get_vars(collection, vars)
16
+ pagy_set_items_from_params(vars) if defined?(ItemsExtra)
17
+
17
18
  vars[:arel_table] = collection.arel_table
18
19
  vars[:primary_key] = collection.primary_key
19
- vars[:backend] = 'sequence'
20
+ vars[:backend] = "sequence"
20
21
  vars
21
22
  end
22
23
 
23
- def pagy_cursor_get_items(collection, pagy, position=nil)
24
+ def pagy_cursor_get_items(collection, pagy, position = nil)
24
25
  if position.present?
25
- sql_comparation = pagy.arel_table[pagy.primary_key].send(pagy.comparation, position)
26
- collection.where(sql_comparation).reorder(pagy.order).limit(pagy.items)
26
+ sql_comparison = pagy.arel_table[pagy.primary_key].send(pagy.comparison, position)
27
+ collection.where(sql_comparison).reorder(pagy.order).limit(pagy.items)
27
28
  else
28
29
  collection.reorder(pagy.order).limit(pagy.items)
29
30
  end
@@ -1,33 +1,47 @@
1
- require 'pagy_cursor/pagy/cursor'
2
- class Pagy
3
-
4
- module Backend ; private # the whole module is private so no problem with including it in a controller
1
+ # frozen_string_literal: true
5
2
 
3
+ class Pagy
4
+ module Backend; private # the whole module is private so no problem with including it in a controller
6
5
  # Return Pagy object and items
7
- def pagy_uuid_cursor(collection, vars={})
6
+ def pagy_uuid_cursor(collection, vars = {})
8
7
  pagy = Pagy::Cursor.new(pagy_uuid_cursor_get_vars(collection, vars))
9
- items = pagy_uuid_cursor_get_items(collection, pagy, pagy.position)
10
- pagy.has_more = pagy_uuid_cursor_has_more?(items, pagy)
8
+ items = pagy_uuid_cursor_get_items(collection, pagy, pagy.position)
9
+ pagy.has_more = pagy_uuid_cursor_has_more?(items, pagy)
11
10
 
12
11
  return pagy, items
13
12
  end
14
13
 
15
14
  def pagy_uuid_cursor_get_vars(collection, vars)
15
+ pagy_set_items_from_params(vars) if defined?(ItemsExtra)
16
+
16
17
  vars[:arel_table] = collection.arel_table
17
18
  vars[:primary_key] = collection.primary_key
18
- vars[:backend] = 'uuid'
19
+ vars[:backend] = "uuid"
19
20
  vars
20
21
  end
21
22
 
22
- def pagy_uuid_cursor_get_items(collection, pagy, position=nil)
23
+ def pagy_uuid_cursor_get_items(collection, pagy, position = nil)
23
24
  if position.present?
24
25
  arel_table = pagy.arel_table
25
26
 
26
- select_created_at = arel_table.project(arel_table[:created_at]).where(arel_table[pagy.primary_key].eq(position))
27
- select_the_sample_created_at = arel_table[:created_at].eq(select_created_at).and(arel_table[pagy.primary_key].send(pagy.comparation, position))
28
- sql_comparation = arel_table[:created_at].send(pagy.comparation, select_created_at).or(select_the_sample_created_at)
27
+ # If the primary sort key is not "created_at"
28
+
29
+ # Select the primary sort key
30
+ # pagy.order should be something like:
31
+ # [:created_at, :id] or [:foo_column, ..., :created_at, :id]
32
+ primary_sort_key = pagy.order.keys.detect { |order_key| ![:created_at, :id].include?(order_key.to_sym) } || :created_at
33
+
34
+ select_previous_row = arel_table.project(arel_table[primary_sort_key]).
35
+ where(arel_table[pagy.primary_key].eq(position))
36
+
37
+ sql_comparison = arel_table[primary_sort_key].
38
+ send(pagy.comparison, select_previous_row).
39
+ or(
40
+ arel_table[primary_sort_key].eq(select_previous_row).
41
+ and(arel_table[pagy.primary_key].send(pagy.comparison, position))
42
+ )
29
43
 
30
- collection = collection.where(sql_comparation)
44
+ collection = collection.where(sql_comparison)
31
45
  end
32
46
  collection.reorder(pagy.order).limit(pagy.items)
33
47
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PagyCursor
2
- VERSION = "0.6.0"
4
+ VERSION = "0.8.0"
3
5
  end
data/lib/pagy_cursor.rb CHANGED
@@ -1,6 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "pagy"
4
+ require "pagy_cursor/pagy/cursor"
5
+ require "pagy_cursor/pagy/extras/cursor"
6
+ require "pagy_cursor/pagy/extras/uuid_cursor"
7
+
2
8
  require "pagy_cursor/version"
9
+
3
10
  module PagyCursor
4
- class Error < StandardError; end
5
- # Your code goes here...
6
11
  end
data/pagy_cursor.gemspec CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "pagy_cursor/version"
@@ -9,8 +8,8 @@ Gem::Specification.new do |spec|
9
8
  spec.authors = ["Uysim"]
10
9
  spec.email = ["uysimty@gmail.com"]
11
10
 
12
- spec.summary = "cursor paginations for pagy"
13
- spec.description = "use pagy for cursor paginations with rails"
11
+ spec.summary = "cursor-based pagination for pagy"
12
+ spec.description = "use pagy for cursor-based pagination with rails"
14
13
  spec.homepage = "https://github.com/Uysim/pagy-cursor"
15
14
  spec.license = "MIT"
16
15
 
@@ -22,10 +21,10 @@ Gem::Specification.new do |spec|
22
21
  spec.bindir = "exe"
23
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
23
  spec.require_paths = ["lib"]
25
- spec.add_dependency "pagy", ">= 6", "< 7"
24
+ spec.add_dependency "pagy", ">= 6", "< 9"
26
25
  spec.add_dependency "activerecord", ">= 5"
27
26
 
28
- spec.add_development_dependency "bundler", "~> 2.0"
29
- spec.add_development_dependency "rake", "~> 13.0"
30
- spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "bundler", "~> 2"
28
+ spec.add_development_dependency "rake", "~> 13"
29
+ spec.add_development_dependency "rspec", "~> 3"
31
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagy_cursor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uysim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-21 00:00:00.000000000 Z
11
+ date: 2024-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pagy
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '6'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7'
22
+ version: '9'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '6'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7'
32
+ version: '9'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activerecord
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -50,43 +50,43 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '2.0'
53
+ version: '2'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '2.0'
60
+ version: '2'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '13.0'
67
+ version: '13'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '13.0'
74
+ version: '13'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rspec
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '3.0'
81
+ version: '3'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '3.0'
89
- description: use pagy for cursor paginations with rails
88
+ version: '3'
89
+ description: use pagy for cursor-based pagination with rails
90
90
  email:
91
91
  - uysimty@gmail.com
92
92
  executables: []
@@ -108,6 +108,7 @@ files:
108
108
  - gemfiles/active_record_52.gemfile
109
109
  - gemfiles/active_record_61.gemfile
110
110
  - gemfiles/active_record_70.gemfile
111
+ - gemfiles/active_record_71.gemfile
111
112
  - lib/pagy_cursor.rb
112
113
  - lib/pagy_cursor/pagy/cursor.rb
113
114
  - lib/pagy_cursor/pagy/extras/cursor.rb
@@ -133,8 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
134
  - !ruby/object:Gem::Version
134
135
  version: '0'
135
136
  requirements: []
136
- rubygems_version: 3.3.26
137
+ rubygems_version: 3.4.19
137
138
  signing_key:
138
139
  specification_version: 4
139
- summary: cursor paginations for pagy
140
+ summary: cursor-based pagination for pagy
140
141
  test_files: []