arel_extensions 2.2.2 → 2.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: ec5e40945328be87eb2078d58b5bbe144f9927f76f44d636b207e9c79ed8d083
4
- data.tar.gz: a829d89fbafe6717a773b3cd1deb4a86c4a230d30b712f8dc9c2d87967fb325d
3
+ metadata.gz: bec346d9bbce78a1d91d023e0291903cb1c61b115237681cb4d9b4174e5f370a
4
+ data.tar.gz: b2e307f12bdb154129d29179093a04e1c7cd632feb2ed4d5e706a97acbfd0526
5
5
  SHA512:
6
- metadata.gz: 868227bed38916facdf1f48b0961b48a41bcfb65a5741c17947e73fa3e28d7c9b01ccef238396f1b23288d3ca12dd5c4dfdbedcf9a900dd17efe08dc1e3ef139
7
- data.tar.gz: a8843d2c5a52ea04a9b0b46bf6b4563697829cd2ea63b39c23fdf2d4790c8e25902d302165392997c617ab13c06b5465f560b4de185a4152804ed493df8c8246
6
+ metadata.gz: 90fc4233e4699e6a7da8d7141351f21d1d33d72d9f3220a2b47f5f9e425bca147be2db7a1f062696b17b593cb5191bf5fe75be2f68022139c4e7fce6021a43a9
7
+ data.tar.gz: 5c49180d1bb19d6ad2338a509811010c0749bcb6beda93c9d1d8e68c46f4316bd9bf3cc22768695bf790c2d4f6ddd68d7378819dbf10ad38823cf55030c3aff9
data/NEWS.md CHANGED
@@ -2,14 +2,19 @@
2
2
 
3
3
  ## [unreleased]
4
4
 
5
+ ## Release v2.3.0/v1.5.0 (19-12-2024)
6
+
7
+ - Use ActiveSupport's deprecation machinery instead of Ruby's Warning module.
8
+ - Fix a bug with group concat that didn't correctly check for the separator value.
9
+
5
10
  ## Release v2.2.2/v1.4.2 (27-11-2024)
6
11
 
7
- - Fix deprecartion warnings for `==` and `!=`, showing the true location.
8
- - Always emit deprecartion warnings for `==` and `!=`.
12
+ - Fix deprecation warnings for `==` and `!=`, showing the true location.
13
+ - Always emit deprecation warnings for `==` and `!=`.
9
14
 
10
15
  ## Release v2.2.1/v1.4.1 (08-11-2024)
11
16
 
12
- - Improved deprecartion warnings for `==` and `!=`, showing the location where they're called.
17
+ - Improved deprecation warnings for `==` and `!=`, showing the location where they're called.
13
18
 
14
19
  ## Release v2.2.0/v1.4.0
15
20
 
@@ -28,6 +28,14 @@ group :development, :test do
28
28
  gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
29
29
  gem 'jdbc-mssql', platforms: :jruby, require: true
30
30
  gem 'jdbc-sqlite3', platforms: :jruby
31
+
32
+ # Ruby 3.4+ removes the following gems from the standard distribution.
33
+ # Warnings are emitted from 3.3 .
34
+ if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0')
35
+ gem 'base64'
36
+ gem 'bigdecimal'
37
+ gem 'mutex_m'
38
+ end
31
39
  end
32
40
 
33
41
  gemspec path: Dir.pwd
@@ -28,6 +28,14 @@ group :development, :test do
28
28
  gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
29
29
  gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
30
30
  gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
31
+
32
+ # Ruby 3.4+ removes the following gems from the standard distribution.
33
+ # Warnings are emitted from 3.3 .
34
+ if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0')
35
+ gem 'base64'
36
+ gem 'bigdecimal'
37
+ gem 'mutex_m'
38
+ end
31
39
  end
32
40
 
33
41
  gemspec path: Dir.pwd
@@ -22,12 +22,21 @@ group :development, :test do
22
22
  gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0' if ENV.has_key? 'ORACLE_HOME'
23
23
 
24
24
  # for JRuby
25
+ gem 'jar-dependencies', '0.4.1', platforms: :jruby
25
26
  gem 'jdbc-mssql', platforms: :jruby, require: true
26
27
  gem 'jdbc-sqlite3', platform: :jruby
27
28
  gem 'activerecord-jdbc-alt-adapter', '~> 71.0.0.alpha1', platform: :jruby, require: true
28
29
  gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
29
30
  gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
30
31
  gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
32
+
33
+ # Ruby 3.4+ removes the following gems from the standard distribution.
34
+ # Warnings are emitted from 3.3 .
35
+ if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0')
36
+ gem 'base64'
37
+ gem 'bigdecimal'
38
+ gem 'mutex_m'
39
+ end
31
40
  end
32
41
 
33
42
  gemspec path: Dir.pwd
@@ -28,6 +28,14 @@ group :development, :test do
28
28
  gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
29
29
  gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
30
30
  gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
31
+
32
+ # Ruby 3.4+ removes the following gems from the standard distribution.
33
+ # Warnings are emitted from 3.3 .
34
+ if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0')
35
+ gem 'base64'
36
+ gem 'bigdecimal'
37
+ gem 'mutex_m'
38
+ end
31
39
  end
32
40
 
33
41
  gemspec path: Dir.pwd
@@ -17,18 +17,15 @@ module ArelExtensions
17
17
  include ArelExtensions::NullFunctions
18
18
  include ArelExtensions::StringFunctions
19
19
  include ArelExtensions::Predications
20
+ include ArelExtensions::Warning
20
21
 
21
22
  def ==(other)
22
- if Gem::Version.create(ArelExtensions::VERSION) >= Gem::Version.create('2.2')
23
- warn("#{caller(1..1).first} arel_extensions: `==` is now deprecated and will be removed soon. Use `.eq` instead.")
24
- end
23
+ deprecated 'Use `.eq` instead.' if Gem::Version.create(ArelExtensions::VERSION) >= Gem::Version.create('2.2')
25
24
  Arel::Nodes::Equality.new self, Arel.quoted(other, self)
26
25
  end
27
26
 
28
27
  def !=(other)
29
- if Gem::Version.create(ArelExtensions::VERSION) >= Gem::Version.create('2.2')
30
- warn("#{caller(1..1).first} arel_extensions: `!=` is now deprecated and will be removed soon. Use `.not_eq` instead.")
31
- end
28
+ deprecated 'Use `.not_eq` instead.' if Gem::Version.create(ArelExtensions::VERSION) >= Gem::Version.create('2.2')
32
29
  Arel::Nodes::NotEqual.new self, Arel.quoted(other, self)
33
30
  end
34
31
  end
@@ -4,8 +4,8 @@ module ArelExtensions
4
4
  attr_accessor :order, :group
5
5
 
6
6
  def initialize node, **opts
7
- @order = Array(opts[:order]).map{|e| convert_to_node(e)}
8
- @group = Array(opts[:group]).map{|e| convert_to_node(e)}
7
+ @order = Array.wrap(opts[:order]).map{|e| convert_to_node(e)}
8
+ @group = Array.wrap(opts[:group]).map{|e| convert_to_node(e)}
9
9
  super [node]
10
10
  end
11
11
  end
@@ -1,5 +1,11 @@
1
1
  require 'arel_extensions/predications'
2
2
 
3
+ # This is required for rails 6.1
4
+ # See https://github.com/thoughtbot/shoulda-matchers/issues/335
5
+ if !Array.respond_to?(:wrap)
6
+ require 'active_support/core_ext/array/wrap'
7
+ end
8
+
3
9
  module ArelExtensions
4
10
  module Nodes
5
11
  class Function < Arel::Nodes::Function
@@ -3,7 +3,7 @@
3
3
 
4
4
  begin
5
5
  Arel::Nodes.const_get('RollUp')
6
- rescue NameError => e
6
+ rescue NameError => _
7
7
  module Arel
8
8
  module Nodes
9
9
  class RollUp < Arel::Nodes::Unary
@@ -144,7 +144,7 @@ module ArelExtensions
144
144
  # concat elements of a group, separated by sep and ordered by a list of Ascending or Descending
145
145
  def group_concat(sep = nil, *orders, group: nil, order: nil)
146
146
  if orders.present?
147
- warn("Warning: ArelExtensions: group_concat: you should now use the kwarg 'order' to specify an order in the group_concat.")
147
+ deprecated 'Use the kwarg `order` instead.', what: 'orders'
148
148
  end
149
149
  order_tabs = [orders].flatten.map{ |o|
150
150
  if o.is_a?(Arel::Nodes::Ascending) || o.is_a?(Arel::Nodes::Descending)
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '2.2.2'.freeze
2
+ VERSION = '2.3.0'.freeze
3
3
  end
@@ -608,13 +608,13 @@ module ArelExtensions
608
608
  grouping_array_or_grouping_element o, collector
609
609
  end
610
610
 
611
- # TODO;
612
611
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
613
612
  collector << '(STRING_AGG('
614
613
  collector = visit o.left, collector
615
614
  collector << Arel::Visitors::Oracle::COMMA
615
+ sep = o.separator.is_a?(Arel::Nodes::Quoted) ? o.separator.expr : o.separator
616
616
  collector =
617
- if o.separator && o.separator != 'NULL'
617
+ if 'NULL' != sep
618
618
  visit o.separator, collector
619
619
  else
620
620
  visit Arel.quoted(','), collector
@@ -16,7 +16,7 @@ module ArelExtensions
16
16
 
17
17
  # This helper method did not exist in rails < 5.2
18
18
  if !Arel::Visitors::MySQL.method_defined?(:collect_nodes_for)
19
- def collect_nodes_for(nodes, collector, spacer, connector = ", ")
19
+ def collect_nodes_for(nodes, collector, spacer, connector = ', ')
20
20
  if nodes&.any?
21
21
  collector << spacer
22
22
  inject_join nodes, collector, connector
@@ -24,42 +24,45 @@ module ArelExtensions
24
24
  end
25
25
  end
26
26
 
27
- # The whole purpose of this override is to fix the behavior of RollUp.
28
- # All other databases treat RollUp sanely, execpt MySQL which requires
29
- # that it figures as the last element of a GROUP BY.
30
- def visit_Arel_Nodes_SelectCore(o, collector)
31
- collector << "SELECT"
27
+ if private_method_defined?(:visit_Arel_Nodes_SelectCore) || method_defined?(:visit_Arel_Nodes_SelectCore)
28
+ alias_method(:old_visit_Arel_Nodes_SelectCore, :visit_Arel_Nodes_SelectCore)
29
+ end
30
+ # The whole purpose of this override is to fix the behavior of RollUp.
31
+ # All other databases treat RollUp sanely, execpt MySQL which requires
32
+ # that it figures as the last element of a GROUP BY.
33
+ def visit_Arel_Nodes_SelectCore(o, collector)
34
+ collector << 'SELECT'
32
35
 
33
- collector = collect_optimizer_hints(o, collector) if self.respond_to?(:collect_optimizer_hinsts)
34
- collector = maybe_visit o.set_quantifier, collector
36
+ collector = collect_optimizer_hints(o, collector) if self.respond_to?(:collect_optimizer_hinsts)
37
+ collector = maybe_visit o.set_quantifier, collector
35
38
 
36
- collect_nodes_for o.projections, collector, " "
39
+ collect_nodes_for o.projections, collector, ' '
37
40
 
38
- if o.source && !o.source.empty?
39
- collector << " FROM "
40
- collector = visit o.source, collector
41
- end
41
+ if o.source && !o.source.empty?
42
+ collector << ' FROM '
43
+ collector = visit o.source, collector
44
+ end
42
45
 
43
- # The actual work
44
- groups = o.groups
45
- rollup = groups.select { |g| g.expr.class == Arel::Nodes::RollUp }.map { |r| r.expr.value }
46
- if rollup && !rollup.empty?
47
- groups = o.groups.reject { |g| g.expr.class == Arel::Nodes::RollUp }
48
- groups << Arel::Nodes::RollUp.new(rollup)
49
- end
50
- # FIN
46
+ # The actual work
47
+ groups = o.groups
48
+ rollup = groups.select { |g| g.expr.class == Arel::Nodes::RollUp }.map { |r| r.expr.value }
49
+ if rollup && !rollup.empty?
50
+ groups = o.groups.reject { |g| g.expr.class == Arel::Nodes::RollUp }
51
+ groups << Arel::Nodes::RollUp.new(rollup)
52
+ end
53
+ # FIN
51
54
 
52
- collect_nodes_for o.wheres, collector, " WHERE ", " AND "
53
- collect_nodes_for groups, collector, " GROUP BY " # Look ma, I'm viring a group
54
- collect_nodes_for o.havings, collector, " HAVING ", " AND "
55
- collect_nodes_for o.windows, collector, " WINDOW "
55
+ collect_nodes_for o.wheres, collector, ' WHERE ', ' AND '
56
+ collect_nodes_for groups, collector, ' GROUP BY '
57
+ collect_nodes_for o.havings, collector, ' HAVING ', ' AND '
58
+ collect_nodes_for o.windows, collector, ' WINDOW '
56
59
 
57
- if o.respond_to?(:comment)
58
- maybe_visit o.comment, collector
59
- else
60
- collector
61
- end
60
+ if o.respond_to?(:comment)
61
+ maybe_visit o.comment, collector
62
+ else
63
+ collector
62
64
  end
65
+ end
63
66
 
64
67
  # Math functions
65
68
  def visit_ArelExtensions_Nodes_Log10 o, collector
@@ -199,7 +202,8 @@ module ArelExtensions
199
202
  collector = visit order, collector
200
203
  end
201
204
  end
202
- if o.separator && o.separator != 'NULL'
205
+ sep = o.separator.is_a?(Arel::Nodes::Quoted) ? o.separator.expr : o.separator
206
+ if 'NULL' != sep
203
207
  collector << ' SEPARATOR '
204
208
  collector = visit o.separator, collector
205
209
  end
@@ -135,8 +135,9 @@ module ArelExtensions
135
135
  collector << '(LISTAGG('
136
136
  collector = visit o.left, collector
137
137
  collector << COMMA
138
+ sep = o.separator.is_a?(Arel::Nodes::Quoted) ? o.separator.expr : o.separator
138
139
  collector =
139
- if o.separator && o.separator != 'NULL'
140
+ if 'NULL' != sep
140
141
  visit o.separator, collector
141
142
  else
142
143
  visit Arel.quoted(','), collector
@@ -136,8 +136,9 @@ module ArelExtensions
136
136
  o.order = nil
137
137
  visit_Aggregate_For_AggregateFunction o, collector
138
138
  collector << COMMA
139
+ sep = o.separator.is_a?(Arel::Nodes::Quoted) ? o.separator.expr : o.separator
139
140
  collector =
140
- if o.separator && o.separator != 'NULL'
141
+ if 'NULL' != sep
141
142
  visit o.separator, collector
142
143
  else
143
144
  visit Arel.quoted(','), collector
@@ -112,7 +112,8 @@ module ArelExtensions
112
112
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
113
113
  collector << 'GROUP_CONCAT('
114
114
  collector = visit o.left, collector
115
- if o.separator && o.separator != 'NULL'
115
+ sep = o.separator.is_a?(Arel::Nodes::Quoted) ? o.separator.expr : o.separator
116
+ if 'NULL' != sep
116
117
  collector << COMMA
117
118
  collector = visit o.separator, collector
118
119
  end
@@ -0,0 +1,15 @@
1
+ module ArelExtensions
2
+ def self.deprecator
3
+ @deprecator ||= ActiveSupport::Deprecation.new(ArelExtensions::VERSION, "arel_extensions")
4
+ end
5
+
6
+ module Warning
7
+ def deprecated msg, what: nil
8
+ kaller = caller(2..2).first
9
+ return if kaller.include?('lib/arel_extensions') && ENV['AREL_EXTENSIONS_IN_TEST'] != '1'
10
+
11
+ what = caller_locations(1, 1).first.label if what.nil?
12
+ ArelExtensions.deprecator.warn "#{kaller}: `#{what}` is now deprecated. #{msg}"
13
+ end
14
+ end
15
+ end
@@ -52,6 +52,7 @@ if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('7.1.0')
52
52
  end
53
53
  end
54
54
 
55
+ require 'arel_extensions/warning'
55
56
  require 'arel_extensions/helpers'
56
57
  require 'arel_extensions/version'
57
58
  require 'arel_extensions/aliases'
@@ -256,6 +257,7 @@ class Arel::SelectManager
256
257
  include ArelExtensions::SetFunctions
257
258
  include ArelExtensions::Nodes
258
259
 
260
+ remove_method(:as) if method_defined?(:as)
259
261
  def as table_name
260
262
  Arel::Nodes::TableAlias.new(self, table_name)
261
263
  end
@@ -6,6 +6,8 @@ require 'active_record'
6
6
 
7
7
  require 'support/fake_record'
8
8
 
9
+ ENV['AREL_EXTENSIONS_IN_TEST'] = '1' # Useful for deprecation warnings.
10
+
9
11
  def colored(color, msg)
10
12
  /^xterm|-256color$/.match?(ENV['TERM']) ? "\x1b[#{color}m#{msg}\x1b[89m\x1b[0m" : "#{msg}"
11
13
  end
@@ -40,6 +42,22 @@ db_and_gem =
40
42
  }
41
43
  end
42
44
 
45
+ module Warning
46
+ ARELX_IGNORED = [
47
+ 'PG::Coder.new(hash)',
48
+ 'rb_check_safe_obj', # ruby 3.0
49
+ 'rb_tainted_str_new', # ruby 3.0
50
+ 'Using the last argument', # ruby < 3.0
51
+ ].freeze
52
+
53
+ def self.warn(message)
54
+ return if ARELX_IGNORED.any? { |msg| message.include?(msg) }
55
+
56
+ super
57
+ end
58
+ end
59
+
60
+
43
61
  def load_lib(gems)
44
62
  if gems && (RUBY_PLATFORM == 'java' || Arel::VERSION.to_i > 9)
45
63
  gems.each do |gem|
@@ -242,10 +242,10 @@ module ArelExtensions
242
242
  assert_equal 'Lucas,Sophie', t(User.where(name: %w[Lucas Sophie]), @name.group_concat)
243
243
 
244
244
  skip 'No order in group_concat in SqlLite' if $sqlite
245
- assert_equal 'Arthur,Lucas,Sophie', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', @name.asc))
246
- assert_equal 'Sophie,Lucas,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', @name.desc))
247
- assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', [@score.asc, @name.asc]))
248
- assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', @score.asc, @name.asc))
245
+ assert_equal 'Arthur,Lucas,Sophie', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', order: @name.asc))
246
+ assert_equal 'Sophie,Lucas,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', order: @name.desc))
247
+ assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', order: [@score.asc, @name.asc]))
248
+ assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', order: [@score.asc, @name.asc]))
249
249
  assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', order: [@score.asc, @name.asc]))
250
250
  end
251
251
 
data/version_v1.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '1.4.2'.freeze
2
+ VERSION = '1.5.0'.freeze
3
3
  end
data/version_v2.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '2.2.2'.freeze
2
+ VERSION = '2.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yann Azoury
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-11-27 00:00:00.000000000 Z
13
+ date: 2024-12-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -179,6 +179,7 @@ files:
179
179
  - lib/arel_extensions/visitors/postgresql.rb
180
180
  - lib/arel_extensions/visitors/sqlite.rb
181
181
  - lib/arel_extensions/visitors/to_sql.rb
182
+ - lib/arel_extensions/warning.rb
182
183
  - test/arelx_test_helper.rb
183
184
  - test/database.yml
184
185
  - test/real_db_test.rb