arel_extensions 1.5.1 → 1.5.3
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 +4 -4
- data/.github/workflows/publish.yml +2 -1
- data/.github/workflows/ruby.yml +11 -7
- data/NEWS.md +10 -0
- data/gemfiles/rails6.gemfile +1 -0
- data/gemfiles/rails6_1.gemfile +1 -0
- data/gemfiles/rails7.gemfile +1 -0
- data/gemfiles/rails7_1.gemfile +0 -1
- data/init/postgresql.sql +3 -4
- data/lib/arel_extensions/comparators.rb +2 -0
- data/lib/arel_extensions/string_functions.rb +23 -7
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/warning.rb +1 -1
- data/test/visitors/test_to_sql.rb +1 -1
- data/test/with_ar/all_agnostic_test.rb +11 -1
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63ac168e55da77eacb9edfa70f025558721346a4912f225a2b35be1b7bd4eb66
|
4
|
+
data.tar.gz: d24d852a75734d25306326ce3068ad541155f2643990e71eeedccbe823354d2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae560399c811449f49ad80139a244e2e8602b0e897b17ec2a58e0af3e99aa31e6e4c302fd78a32737817b03531bc86f4cfd3b929e149c2fa862af371a10b6b2a
|
7
|
+
data.tar.gz: 581b12e386fc04cc4fd0dd7e7ab975a40ec6f077203f9d8350b665e7f679c8bd942ab2b30c4f6225cc3bb85dc1213247743e497e059bae83fe56d541235a8eb8
|
data/.github/workflows/ruby.yml
CHANGED
@@ -2,6 +2,10 @@ name: Build and Test
|
|
2
2
|
|
3
3
|
# Ruby + Rails Compatibility Matrix from here:
|
4
4
|
# https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html
|
5
|
+
#
|
6
|
+
# Images are fixed to ubuntu 22.04 because jruby-9.2 is unavailable in
|
7
|
+
# ubuntu-24.04 (ubuntu-latest when I tested). Also, for rails < 6, sqlite3
|
8
|
+
# will not build because libsqlite3-dev is missing.
|
5
9
|
|
6
10
|
on:
|
7
11
|
push:
|
@@ -14,7 +18,7 @@ on:
|
|
14
18
|
jobs:
|
15
19
|
job_test_to_sql:
|
16
20
|
name: test to_sql
|
17
|
-
runs-on: ubuntu-
|
21
|
+
runs-on: ubuntu-22.04
|
18
22
|
strategy:
|
19
23
|
fail-fast: false
|
20
24
|
matrix:
|
@@ -78,7 +82,7 @@ jobs:
|
|
78
82
|
|
79
83
|
job_test_sqlite:
|
80
84
|
name: test sqlite
|
81
|
-
runs-on: ubuntu-
|
85
|
+
runs-on: ubuntu-22.04
|
82
86
|
strategy:
|
83
87
|
fail-fast: false
|
84
88
|
matrix:
|
@@ -143,7 +147,7 @@ jobs:
|
|
143
147
|
|
144
148
|
job_test_postgres:
|
145
149
|
name: test postgres
|
146
|
-
runs-on: ubuntu-
|
150
|
+
runs-on: ubuntu-22.04
|
147
151
|
strategy:
|
148
152
|
fail-fast: false
|
149
153
|
matrix:
|
@@ -232,7 +236,7 @@ jobs:
|
|
232
236
|
|
233
237
|
job_test_mysql:
|
234
238
|
name: test mysql
|
235
|
-
runs-on: ubuntu-
|
239
|
+
runs-on: ubuntu-22.04
|
236
240
|
strategy:
|
237
241
|
fail-fast: false
|
238
242
|
matrix:
|
@@ -316,7 +320,7 @@ jobs:
|
|
316
320
|
|
317
321
|
job_test_mssql:
|
318
322
|
name: test mssql on linux
|
319
|
-
runs-on: ubuntu-
|
323
|
+
runs-on: ubuntu-22.04
|
320
324
|
strategy:
|
321
325
|
fail-fast: false
|
322
326
|
matrix:
|
@@ -352,8 +356,8 @@ jobs:
|
|
352
356
|
# {ruby: jruby-9.3, rails: 6_1, arelx: 2},
|
353
357
|
# {ruby: jruby-9.3, rails: 6, arelx: 2},
|
354
358
|
# {ruby: jruby-9.3, rails: 5_2, arelx: 1},
|
355
|
-
{ ruby: jruby-9.4, rails: 7_1, arelx: 2 },
|
356
|
-
{ ruby: jruby-9.4, rails: 7, arelx: 2 },
|
359
|
+
{ ruby: jruby-9.4.10, rails: 7_1, arelx: 2 }, # The reason we pin to the patch level is https://github.com/ruby/psych/issues/700
|
360
|
+
{ ruby: jruby-9.4.10, rails: 7, arelx: 2 },
|
357
361
|
#
|
358
362
|
# 6 and 6.1 don't work because of a bug in the alt adapter
|
359
363
|
# https://github.com/JesseChavez/activerecord-jdbc-adapter/issues/16
|
data/NEWS.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
## [unreleased]
|
4
4
|
|
5
|
+
## Release v2.3.3/v1.5.3 (11-02-2025)
|
6
|
+
|
7
|
+
- Fix the `&` operator which does `find_in_set` for mysql and postgres, accepting strings and integers.
|
8
|
+
- Add `regex_matches`, an alias for `=~`.
|
9
|
+
|
10
|
+
## Release v2.3.2/v1.5.2 (02-01-2025)
|
11
|
+
|
12
|
+
- Fix a subtle bug on table access as in `table[:col]` in certain situations.
|
13
|
+
- `==` and `!=` deprecation warnings can stem from `arel` itself, so now we don't emit them because they're plain wrong.
|
14
|
+
|
5
15
|
## Release v2.3.1/v1.5.1 (20-12-2024)
|
6
16
|
|
7
17
|
- Fallback to Ruby's Warning module if ActiveSupport doesn't exist. Relevant for old Rails versions.
|
data/gemfiles/rails6.gemfile
CHANGED
@@ -5,6 +5,7 @@ gem 'rails', '~> 6.0.0'
|
|
5
5
|
group :development, :test do
|
6
6
|
gem 'ruby-lsp', platforms: %i[mri]
|
7
7
|
gem 'debug', platforms: %i[mri]
|
8
|
+
gem 'concurrent-ruby', '1.3.4' # Need to pin b/c of a known issue https://github.com/rails/rails/issues/54260
|
8
9
|
|
9
10
|
gem 'activesupport', '~> 6.0.0'
|
10
11
|
gem 'activemodel', '~> 6.0.0'
|
data/gemfiles/rails6_1.gemfile
CHANGED
@@ -5,6 +5,7 @@ gem 'rails', '~> 6.1.0'
|
|
5
5
|
group :development, :test do
|
6
6
|
gem 'ruby-lsp', platforms: %i[mri]
|
7
7
|
gem 'debug', platforms: %i[mri]
|
8
|
+
gem 'concurrent-ruby', '1.3.4' # Need to pin b/c of a known issue https://github.com/rails/rails/issues/54260
|
8
9
|
|
9
10
|
gem 'activesupport', '~> 6.1.0'
|
10
11
|
gem 'activemodel', '~> 6.1.0'
|
data/gemfiles/rails7.gemfile
CHANGED
@@ -5,6 +5,7 @@ gem 'rails', '~> 7.0.1'
|
|
5
5
|
group :development, :test do
|
6
6
|
gem 'ruby-lsp', platforms: %i[mri]
|
7
7
|
gem 'debug', platforms: %i[mri]
|
8
|
+
gem 'concurrent-ruby', '1.3.4' # Need to pin b/c of a known issue https://github.com/rails/rails/issues/54260
|
8
9
|
|
9
10
|
gem 'activesupport', '~> 7.0.1'
|
10
11
|
gem 'activemodel', '~> 7.0.1'
|
data/gemfiles/rails7_1.gemfile
CHANGED
@@ -22,7 +22,6 @@ 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
|
26
25
|
gem 'jdbc-mssql', platforms: :jruby, require: true
|
27
26
|
gem 'jdbc-sqlite3', platform: :jruby
|
28
27
|
gem 'activerecord-jdbc-alt-adapter', '~> 71.0.0.alpha1', platform: :jruby, require: true
|
data/init/postgresql.sql
CHANGED
@@ -1,18 +1,17 @@
|
|
1
|
-
CREATE OR REPLACE FUNCTION public.find_in_set(n
|
1
|
+
CREATE OR REPLACE FUNCTION public.find_in_set(n TEXT, s TEXT)
|
2
2
|
RETURNS INT4
|
3
3
|
LANGUAGE sql
|
4
4
|
AS $function$
|
5
5
|
SELECT * FROM (
|
6
6
|
select int4(z.row_number) from (
|
7
7
|
select row_number() over(), y.x
|
8
|
-
from (select unnest((
|
8
|
+
from (select unnest(regexp_split_to_array($2, ',')) as x) as y -- use string_to_array if on pg 14+.
|
9
9
|
) as z
|
10
10
|
where z.x = $1
|
11
11
|
UNION ALL
|
12
12
|
SELECT 0) z
|
13
13
|
LIMIT 1
|
14
|
-
$function
|
15
|
-
;
|
14
|
+
$function$;
|
16
15
|
|
17
16
|
CREATE OR REPLACE FUNCTION public.levenshtein_distance(s text, t text)
|
18
17
|
RETURNS integer AS $$
|
@@ -21,7 +21,10 @@ module ArelExtensions
|
|
21
21
|
module StringFunctions
|
22
22
|
# *FindInSet function .......
|
23
23
|
def &(other)
|
24
|
-
ArelExtensions::Nodes::FindInSet.new [
|
24
|
+
ArelExtensions::Nodes::FindInSet.new [
|
25
|
+
Arel.quoted(other.is_a?(Integer) ? other.to_s : other),
|
26
|
+
self,
|
27
|
+
]
|
25
28
|
end
|
26
29
|
|
27
30
|
# LENGTH function returns the length (bytewise) of the value in a text field.
|
@@ -47,14 +50,27 @@ module ArelExtensions
|
|
47
50
|
ArelExtensions::Nodes::Substring.new [self, start, len]
|
48
51
|
end
|
49
52
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
# Return a [ArelExtensions::Nodes::Substring] if `start` is a [Range] or an
|
54
|
+
# [Integer].
|
55
|
+
#
|
56
|
+
# Return the result to `self.send(start)` if it's a [String|Symbol]. The
|
57
|
+
# assumption is that you're trying to reach an [Arel::Table]'s
|
58
|
+
# [Arel::Attribute].
|
59
|
+
#
|
60
|
+
# @note `ind` should be an [Integer|NilClass] if `start` is an [Integer].
|
61
|
+
# It's ignored in all other cases.
|
62
|
+
def [](start, end_ = nil)
|
63
|
+
if start.is_a?(String) || start.is_a?(Symbol)
|
64
|
+
self.send(start)
|
65
|
+
elsif start.is_a?(Range)
|
53
66
|
ArelExtensions::Nodes::Substring.new [self, start.begin + 1, start.end - start.begin + 1]
|
54
|
-
elsif start.is_a?(Integer) && !
|
55
|
-
ArelExtensions::Nodes::Substring.new [self, start, 1]
|
67
|
+
elsif start.is_a?(Integer) && !end_
|
68
|
+
ArelExtensions::Nodes::Substring.new [self, start + 1, 1]
|
69
|
+
elsif start.is_a?(Integer)
|
70
|
+
start += 1
|
71
|
+
ArelExtensions::Nodes::Substring.new [self, start, end_ - start + 1]
|
56
72
|
else
|
57
|
-
|
73
|
+
raise ArgumentError, 'unrecognized argument types; can accept integers, ranges, or strings.'
|
58
74
|
end
|
59
75
|
end
|
60
76
|
|
@@ -33,7 +33,7 @@ module ArelExtensions
|
|
33
33
|
module Warning
|
34
34
|
def deprecated msg, what: nil
|
35
35
|
kaller = caller(2..2).first
|
36
|
-
return if
|
36
|
+
return if /lib\/(:?arel(?:_extensions)?|active_record)\// =~ kaller && ENV['AREL_EXTENSIONS_IN_TEST'] != '1'
|
37
37
|
|
38
38
|
what = caller_locations(1, 1).first.label if what.nil?
|
39
39
|
ArelExtensions.deprecator.warn "#{kaller}: `#{what}` is now deprecated. #{msg}"
|
@@ -115,7 +115,7 @@ module ArelExtensions
|
|
115
115
|
# puts (c.length.round + 42).inspect
|
116
116
|
_(compile(c.length.round + 42)).must_be_like %{(ROUND(LENGTH("users"."name")) + 42)}
|
117
117
|
_(compile(c.locate('test'))).must_be_like %{LOCATE('test', "users"."name")}
|
118
|
-
_(compile(c & 42)).must_be_like %{FIND_IN_SET(42, "users"."name")}
|
118
|
+
_(compile(c & 42)).must_be_like %{FIND_IN_SET('42', "users"."name")}
|
119
119
|
|
120
120
|
_(compile((c >= 'test').as('new_name'))).must_be_like %{("users"."name" >= 'test') AS new_name}
|
121
121
|
_(compile(c <= @table[:comments])).must_be_like %{"users"."name" <= "users"."comments"}
|
@@ -68,7 +68,7 @@ module ArelExtensions
|
|
68
68
|
@laure = User.where(id: u.id)
|
69
69
|
u = User.create age: nil, name: 'Test', created_at: d, score: 1.62, other: 'toto'
|
70
70
|
@test = User.where(id: u.id)
|
71
|
-
u = User.create age: -42, name: 'Negatif', comments: '1,22,3,42,2', created_at: d, updated_at: d.to_time, score: 0.17
|
71
|
+
u = User.create age: -42, name: 'Negatif', comments: '1,22,3,42,2', created_at: d, updated_at: d.to_time, score: 0.17, other: '2'
|
72
72
|
@neg = User.where(id: u.id)
|
73
73
|
u = User.create age: 15, name: 'Justin', created_at: d, score: 11.0
|
74
74
|
@justin = User.where(id: u.id)
|
@@ -297,6 +297,9 @@ module ArelExtensions
|
|
297
297
|
skip 'SQL Server does not know about FIND_IN_SET' if @env_db == 'mssql'
|
298
298
|
assert_equal 5, t(@neg, @comments & 2)
|
299
299
|
assert_equal 0, t(@neg, @comments & 6) # not found
|
300
|
+
assert_equal 5, t(@neg, @comments & '2')
|
301
|
+
assert_equal 0, t(@neg, @comments & '6') # not found
|
302
|
+
assert_equal 5, t(@neg, @comments & @other)
|
300
303
|
end
|
301
304
|
|
302
305
|
def test_string_comparators
|
@@ -343,6 +346,13 @@ module ArelExtensions
|
|
343
346
|
assert_equal 8, User.where(@name !~ /^L/).count
|
344
347
|
end
|
345
348
|
|
349
|
+
def test_regex_matches
|
350
|
+
skip "Sqlite version can't load extension for regexp" if $sqlite && $load_extension_disabled
|
351
|
+
skip 'SQL Server does not know about REGEXP without extensions' if @env_db == 'mssql'
|
352
|
+
assert_equal 1, User.where(@name.regex_matches '^M').count
|
353
|
+
assert_equal 1, User.where(@name.regex_matches /^M/).count
|
354
|
+
end
|
355
|
+
|
346
356
|
def test_imatches
|
347
357
|
# puts User.where(@name.imatches('m%')).to_sql
|
348
358
|
assert_equal 1, User.where(@name.imatches('m%')).count
|
data/version_v1.rb
CHANGED
data/version_v2.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yann Azoury
|
8
8
|
- Félix Bellanger
|
9
9
|
- Julien Delporte
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2025-02-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: arel
|
@@ -204,7 +204,7 @@ homepage: https://github.com/Faveod/arel-extensions
|
|
204
204
|
licenses:
|
205
205
|
- MIT
|
206
206
|
metadata: {}
|
207
|
-
post_install_message:
|
207
|
+
post_install_message:
|
208
208
|
rdoc_options:
|
209
209
|
- "--main"
|
210
210
|
- README.md
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
version: '0'
|
223
223
|
requirements: []
|
224
224
|
rubygems_version: 3.4.19
|
225
|
-
signing_key:
|
225
|
+
signing_key:
|
226
226
|
specification_version: 4
|
227
227
|
summary: Extending Arel
|
228
228
|
test_files: []
|