active_record-cursor_paginator 0.2.0 → 0.3.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: 89a00cae4602011f6cf01aed6e09c6956d7eab352ec7b97c2d6ce712cfba972f
4
- data.tar.gz: c8164ed441e5ed69dfe1874dcdea8337855b2a2cfc128cb481d013e3bb125a7c
3
+ metadata.gz: 19564a0a0f62ea77cf5876fc9d125f27474aba8fec598a6a84e6b215b13edb22
4
+ data.tar.gz: e9856e7730229847a6d345c7b2cab49062b2351216fb02a775c1a4d3d8c19ca6
5
5
  SHA512:
6
- metadata.gz: 0df15ecf4719f1ac64b922193042511a03aa2fc642e0fb98d5f9154043c3c388347646e8e6e566a7418e33b650bfd8017dd55fe9fa276c43c42f7af8b148b1fe
7
- data.tar.gz: 9fe08024a3cb033d6e32b07187f803e379b2c57735b27f4dfeb75621cc4da9672a36d23885038d79291773ce9eff90771591242477e26304b0e276a70372d00a
6
+ metadata.gz: c899b2ea56ffd2a65edabbbd06421bc695263555488b8068cf0c753d4cf84e6ca1c57837b339ed7237d47ab8d200c6242d52ded55ffc991c3df784a0c0056ec6
7
+ data.tar.gz: 3f037675aa41403536d136e99faa7c08ec0184c5756fd91cabb88e6d72bdbec3f2be3cc1cbe83ab8efa2538218d35121e05c8c312e0683c26332ad16cbb8bc8c
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,8 @@
1
+ ## [0.3.0] - 2025-12-10
2
+
3
+ - Fix ambiguous column error
4
+ - Drop ruby v2.x support
5
+
1
6
  ## [0.2.0] - 2024-03-27
2
7
 
3
8
  - Support aliases
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/active_record/cursor_paginator/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'active_record-cursor_paginator'
7
+ spec.version = ActiveRecord::CursorPaginator::VERSION
8
+ spec.authors = ['Shinichi Sugiyama']
9
+ spec.email = ['sugiyama-shinichi@kayac.com']
10
+
11
+ spec.summary = 'cursor pagination for ActiveRecord'
12
+ spec.description =
13
+ 'This library is an implementation of cursor pagination for ActiveRecord relations ' \
14
+ 'based on "https://github.com/xing/rails_cursor_pagination". ' \
15
+ 'Additional features are: ' \
16
+ '- receives a relation with orders, and it is unnecessary to specify orders to this library separately.' \
17
+ '- supports bidirectional pagination.'
18
+
19
+ spec.homepage = 'https://github.com/ssugiyama/active_record-cursor_paginator'
20
+ spec.license = 'MIT'
21
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.0.0')
22
+
23
+ spec.metadata['homepage_uri'] = spec.homepage
24
+ spec.metadata['source_code_uri'] = spec.homepage
25
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/Changelog.md"
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(__dir__) do
30
+ `git ls-files -z`.split("\x0").reject do |f|
31
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
32
+ end
33
+ end
34
+ spec.bindir = 'exe'
35
+ spec.executables = spec.files.grep(%r{\Aexe/}) {|f| File.basename(f) }
36
+ spec.require_paths = ['lib']
37
+
38
+ # Uncomment to register a new dependency of your gem
39
+ # spec.add_dependency "example-gem", "~> 1.0"
40
+ spec.add_dependency 'activerecord', '>= 6.0'
41
+
42
+ # For more information and examples about making a new gem, check out our
43
+ # guide at: https://bundler.io/guides/creating_gem.html
44
+ spec.metadata['rubygems_mfa_required'] = 'true'
45
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  class CursorPaginator
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -256,10 +256,12 @@ module ActiveRecord
256
256
  relation = sorted_relation
257
257
  prev_fields.each do |col, val|
258
258
  col = @aliases[col] if @aliases.has_key? col
259
+ col = qualify_field_if_needed(col)
259
260
  relation = relation.where("#{col} = ?", val)
260
261
  end
261
262
  col, val = current_field
262
263
  col = @aliases[col] if @aliases.has_key? col
264
+ col = qualify_field_if_needed(col)
263
265
  relation.where("#{col} #{op} ?", val)
264
266
  end
265
267
 
@@ -276,7 +278,7 @@ module ActiveRecord
276
278
  # "value [AS|as] alias" という形式に対応する
277
279
  # value: spaceがあってもOK. 最小マッチングのため '?' をつける
278
280
  # 'as' は使わないのでキャプチャしない
279
- match = expr.match(/^(?<value>.+?)\s+(?:as\s+)?(?<alias>\S+)$/i)
281
+ match = expr.match(/\A(?<value>.+?)\s+(?:as\s+)?(?<alias>\S+)\z/i)
280
282
  next if match.nil? || match.length < 3
281
283
 
282
284
  key = trim_quote(match[:alias])
@@ -287,7 +289,25 @@ module ActiveRecord
287
289
  end
288
290
 
289
291
  def trim_quote(field)
290
- field.gsub(/^[`\"]/, '').gsub(/[`\"]$/, '')
292
+ field.gsub(/^[`"]/, '').gsub(/[`"]$/, '')
293
+ end
294
+
295
+ # Qualifies a field name with the table name unless it is already qualified or is a SQL function.
296
+ #
297
+ # If the field name contains a dot (.) or an opening parenthesis, it is assumed to be
298
+ # already qualified or a SQL function and is returned as-is. Otherwise, the field name
299
+ # is trimmed of quotes and prefixed with the table name.
300
+ #
301
+ # @param field [String] The field name to qualify.
302
+ # @return [String] The qualified field name or the original field if already qualified or a function.
303
+ def qualify_field_if_needed(field)
304
+ # qualified なフィールド名とSQL関数を簡易的に判定します
305
+ if field.include?('.') || field.include?('(')
306
+ field
307
+ else
308
+ field = trim_quote(field)
309
+ "#{@relation.table_name}.#{field}"
310
+ end
291
311
  end
292
312
  end
293
313
  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.0
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
@@ -43,6 +42,7 @@ files:
43
42
  - Gemfile
44
43
  - README.md
45
44
  - Rakefile
45
+ - active_record-cursor_paginator.gemspec
46
46
  - lib/active_record/cursor_paginator.rb
47
47
  - lib/active_record/cursor_paginator/version.rb
48
48
  homepage: https://github.com/ssugiyama/active_record-cursor_paginator
@@ -53,7 +53,6 @@ metadata:
53
53
  source_code_uri: https://github.com/ssugiyama/active_record-cursor_paginator
54
54
  changelog_uri: https://github.com/ssugiyama/active_record-cursor_paginator/Changelog.md
55
55
  rubygems_mfa_required: 'true'
56
- post_install_message:
57
56
  rdoc_options: []
58
57
  require_paths:
59
58
  - lib
@@ -61,15 +60,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
60
  requirements:
62
61
  - - ">="
63
62
  - !ruby/object:Gem::Version
64
- version: 2.7.0
63
+ version: 3.0.0
65
64
  required_rubygems_version: !ruby/object:Gem::Requirement
66
65
  requirements:
67
66
  - - ">="
68
67
  - !ruby/object:Gem::Version
69
68
  version: '0'
70
69
  requirements: []
71
- rubygems_version: 3.4.10
72
- signing_key:
70
+ rubygems_version: 3.6.7
73
71
  specification_version: 4
74
72
  summary: cursor pagination for ActiveRecord
75
73
  test_files: []