active_record-cursor_paginator 0.2.0 → 0.3.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: 89a00cae4602011f6cf01aed6e09c6956d7eab352ec7b97c2d6ce712cfba972f
4
- data.tar.gz: c8164ed441e5ed69dfe1874dcdea8337855b2a2cfc128cb481d013e3bb125a7c
3
+ metadata.gz: 0e6079364fab39f26c9d63199730cc44ae0138c5c3d8452aa1b73219e0afa0e1
4
+ data.tar.gz: 36d9c3020d18dafe2905b18a6a50bebee06ab17caff4ff4abd4eb9bb965aa851
5
5
  SHA512:
6
- metadata.gz: 0df15ecf4719f1ac64b922193042511a03aa2fc642e0fb98d5f9154043c3c388347646e8e6e566a7418e33b650bfd8017dd55fe9fa276c43c42f7af8b148b1fe
7
- data.tar.gz: 9fe08024a3cb033d6e32b07187f803e379b2c57735b27f4dfeb75621cc4da9672a36d23885038d79291773ce9eff90771591242477e26304b0e276a70372d00a
6
+ metadata.gz: db459de8e2b52873f5ccb95e9bb7b957af9381a30fcfca97786189874bfacc8808f80fb939ea86d54c8f50cb5983b263089df16f4e7f2294387d41757cf723d1
7
+ data.tar.gz: a344ab46f80d38a5c43d890793031a31194d3f3b7dfe6b53258c94a77a08386470c7201e46f5d6833cd2f9e77c0f3fa940afb0306c951648193b1f04f0530ce9
data/.rubocop.yml CHANGED
@@ -8,7 +8,7 @@ inherit_mode:
8
8
 
9
9
  # 自動生成されるものはチェック対象から除外する
10
10
  AllCops:
11
- TargetRubyVersion: 2.7
11
+ TargetRubyVersion: 3.0
12
12
  SuggestExtensions: false
13
13
  NewCops: enable
14
14
  Exclude:
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-3.3.0
1
+ ruby-3.4.4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.3.1] - 2026-03-06
2
+
3
+ - Add support for Rails enum columns
4
+
5
+ ## [0.3.0] - 2025-12-10
6
+
7
+ - Fix ambiguous column error
8
+ - Drop ruby v2.x support
9
+
1
10
  ## [0.2.0] - 2024-03-27
2
11
 
3
12
  - Support aliases
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  class CursorPaginator
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.1'
6
6
  end
7
7
  end
@@ -160,10 +160,23 @@ module ActiveRecord
160
160
  # value from this other field as well as the records ID to resolve the order
161
161
  # of duplicates in the non-ID field.
162
162
  #
163
+ # For enum columns, we store the raw integer value instead of the string
164
+ # representation to ensure proper SQL comparison in WHERE clauses.
165
+ #
163
166
  # @param record [ActiveRecord] Model instance for which we want the cursor
164
167
  # @return [String]
165
168
  def cursor_for_record(record)
166
- unencoded_cursor = @fields.map {|field| { field.keys.first => record[field.keys.first] } }
169
+ unencoded_cursor = @fields.map do |field|
170
+ field_name = field.keys.first
171
+ value = if record.class.defined_enums.key?(field_name.to_s)
172
+ # For enum columns, get the raw integer value from the database
173
+ record.read_attribute_before_type_cast(field_name)
174
+ else
175
+ # For regular columns, get the typed value
176
+ record[field_name]
177
+ end
178
+ { field_name => value }
179
+ end
167
180
  Base64.strict_encode64(unencoded_cursor.to_json)
168
181
  end
169
182
 
@@ -256,10 +269,12 @@ module ActiveRecord
256
269
  relation = sorted_relation
257
270
  prev_fields.each do |col, val|
258
271
  col = @aliases[col] if @aliases.has_key? col
272
+ col = qualify_field_if_needed(col)
259
273
  relation = relation.where("#{col} = ?", val)
260
274
  end
261
275
  col, val = current_field
262
276
  col = @aliases[col] if @aliases.has_key? col
277
+ col = qualify_field_if_needed(col)
263
278
  relation.where("#{col} #{op} ?", val)
264
279
  end
265
280
 
@@ -276,7 +291,7 @@ module ActiveRecord
276
291
  # "value [AS|as] alias" という形式に対応する
277
292
  # value: spaceがあってもOK. 最小マッチングのため '?' をつける
278
293
  # 'as' は使わないのでキャプチャしない
279
- match = expr.match(/^(?<value>.+?)\s+(?:as\s+)?(?<alias>\S+)$/i)
294
+ match = expr.match(/\A(?<value>.+?)\s+(?:as\s+)?(?<alias>\S+)\z/i)
280
295
  next if match.nil? || match.length < 3
281
296
 
282
297
  key = trim_quote(match[:alias])
@@ -287,7 +302,25 @@ module ActiveRecord
287
302
  end
288
303
 
289
304
  def trim_quote(field)
290
- field.gsub(/^[`\"]/, '').gsub(/[`\"]$/, '')
305
+ field.gsub(/^[`"]/, '').gsub(/[`"]$/, '')
306
+ end
307
+
308
+ # Qualifies a field name with the table name unless it is already qualified or is a SQL function.
309
+ #
310
+ # If the field name contains a dot (.) or an opening parenthesis, it is assumed to be
311
+ # already qualified or a SQL function and is returned as-is. Otherwise, the field name
312
+ # is trimmed of quotes and prefixed with the table name.
313
+ #
314
+ # @param field [String] The field name to qualify.
315
+ # @return [String] The qualified field name or the original field if already qualified or a function.
316
+ def qualify_field_if_needed(field)
317
+ # qualified なフィールド名とSQL関数を簡易的に判定します
318
+ if field.include?('.') || field.include?('(')
319
+ field
320
+ else
321
+ field = trim_quote(field)
322
+ "#{@relation.table_name}.#{field}"
323
+ end
291
324
  end
292
325
  end
293
326
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-cursor_paginator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinichi Sugiyama
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-04-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -53,7 +52,6 @@ metadata:
53
52
  source_code_uri: https://github.com/ssugiyama/active_record-cursor_paginator
54
53
  changelog_uri: https://github.com/ssugiyama/active_record-cursor_paginator/Changelog.md
55
54
  rubygems_mfa_required: 'true'
56
- post_install_message:
57
55
  rdoc_options: []
58
56
  require_paths:
59
57
  - lib
@@ -61,15 +59,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
59
  requirements:
62
60
  - - ">="
63
61
  - !ruby/object:Gem::Version
64
- version: 2.7.0
62
+ version: 3.0.0
65
63
  required_rubygems_version: !ruby/object:Gem::Requirement
66
64
  requirements:
67
65
  - - ">="
68
66
  - !ruby/object:Gem::Version
69
67
  version: '0'
70
68
  requirements: []
71
- rubygems_version: 3.4.10
72
- signing_key:
69
+ rubygems_version: 3.7.2
73
70
  specification_version: 4
74
71
  summary: cursor pagination for ActiveRecord
75
72
  test_files: []