arel_extensions 2.0.16 → 2.0.22
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/lib/arel_extensions.rb +17 -1
- data/lib/arel_extensions/math_functions.rb +5 -1
- data/lib/arel_extensions/nodes/function.rb +6 -2
- data/lib/arel_extensions/nodes/length.rb +6 -0
- data/lib/arel_extensions/string_functions.rb +10 -2
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/mssql.rb +1 -1
- data/lib/arel_extensions/visitors/oracle.rb +2 -2
- data/lib/arel_extensions/visitors/oracle12.rb +0 -12
- data/lib/arel_extensions/visitors/postgresql.rb +1 -1
- data/lib/arel_extensions/visitors/to_sql.rb +4 -1
- data/test/with_ar/all_agnostic_test.rb +6 -0
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57188b98a348ea5dd72994ef0edb94cb386104cbd50d863b3cc465bb81499f8f
|
4
|
+
data.tar.gz: 7235c655967c8058e24f85f96b1a3ea93803dc759906ea24aff360edf28ee6fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c60be09bdf31efe2b4a953c0b097bbc461d01a4d7005c1dc190af20efb12e659d2331e16d8ca47527b9757b89a2528069fa1a8a94cfd52bc80000633995b229f
|
7
|
+
data.tar.gz: b028042975ab07e0d28e919278c36f2652fae79dbced3776e16519f4fdfaaf45de32a0a375cb7e77d5157775d2a3ef8555f9096299b2c71f366367e6452a93a6
|
data/lib/arel_extensions.rb
CHANGED
@@ -33,6 +33,12 @@ class Arel::Nodes::Grouping
|
|
33
33
|
include Arel::OrderPredications
|
34
34
|
end
|
35
35
|
|
36
|
+
class Arel::Nodes::Ordering
|
37
|
+
def eql? other
|
38
|
+
self.hash.eql? other.hash
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
36
42
|
class Arel::Nodes::Function
|
37
43
|
include Arel::Math
|
38
44
|
include Arel::Expressions
|
@@ -128,7 +134,11 @@ class Arel::Nodes::Function
|
|
128
134
|
|
129
135
|
alias_method(:old_as, :as) rescue nil
|
130
136
|
def as other
|
131
|
-
Arel::Nodes::As.new(self, Arel.sql(other))
|
137
|
+
res = Arel::Nodes::As.new(self.clone, Arel.sql(other))
|
138
|
+
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("9.0.0")
|
139
|
+
self.alias = Arel.sql(other)
|
140
|
+
end
|
141
|
+
res
|
132
142
|
end
|
133
143
|
end
|
134
144
|
|
@@ -148,6 +158,9 @@ class Arel::Nodes::Unary
|
|
148
158
|
include ArelExtensions::MathFunctions
|
149
159
|
include ArelExtensions::Comparators
|
150
160
|
include ArelExtensions::Predications
|
161
|
+
def eql? other
|
162
|
+
hash == other.hash
|
163
|
+
end
|
151
164
|
end
|
152
165
|
|
153
166
|
class Arel::Nodes::Binary
|
@@ -157,6 +170,9 @@ class Arel::Nodes::Binary
|
|
157
170
|
include ArelExtensions::Comparators
|
158
171
|
include ArelExtensions::BooleanFunctions
|
159
172
|
include ArelExtensions::Predications
|
173
|
+
def eql? other
|
174
|
+
hash == other.hash
|
175
|
+
end
|
160
176
|
end
|
161
177
|
|
162
178
|
class Arel::Nodes::Equality
|
@@ -71,7 +71,11 @@ module ArelExtensions
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def sum opts = {unbiased: true}
|
74
|
-
|
74
|
+
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("9.0.0")
|
75
|
+
Arel::Nodes::Sum.new [self]
|
76
|
+
else
|
77
|
+
ArelExtensions::Nodes::Sum.new self, **opts
|
78
|
+
end
|
75
79
|
end
|
76
80
|
|
77
81
|
# function that can be invoked to produce random numbers between 0 and 1
|
@@ -21,7 +21,11 @@ module ArelExtensions
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def as other
|
24
|
-
Arel::Nodes::As.new(self, Arel.sql(other))
|
24
|
+
res = Arel::Nodes::As.new(self.clone, Arel.sql(other))
|
25
|
+
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("9.0.0")
|
26
|
+
self.alias = Arel.sql(other)
|
27
|
+
end
|
28
|
+
res
|
25
29
|
end
|
26
30
|
|
27
31
|
def expr
|
@@ -76,7 +80,7 @@ module ArelExtensions
|
|
76
80
|
when ActiveSupport::Duration
|
77
81
|
Arel.sql(object.to_i)
|
78
82
|
when Array
|
79
|
-
Arel::Nodes::Grouping.new(object.map{|
|
83
|
+
Arel::Nodes::Grouping.new(object.map{|e| convert_to_node(e)})
|
80
84
|
else
|
81
85
|
raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
|
82
86
|
end
|
@@ -24,9 +24,17 @@ module ArelExtensions
|
|
24
24
|
ArelExtensions::Nodes::FindInSet.new [other, self]
|
25
25
|
end
|
26
26
|
|
27
|
-
# LENGTH function returns the length of the value in a text field.
|
27
|
+
# LENGTH function returns the length (bytewise) of the value in a text field.
|
28
28
|
def length
|
29
|
-
ArelExtensions::Nodes::Length.new
|
29
|
+
ArelExtensions::Nodes::Length.new self, true
|
30
|
+
end
|
31
|
+
|
32
|
+
def byte_length
|
33
|
+
ArelExtensions::Nodes::Length.new self, true
|
34
|
+
end
|
35
|
+
|
36
|
+
def char_length
|
37
|
+
ArelExtensions::Nodes::Length.new self, false
|
30
38
|
end
|
31
39
|
|
32
40
|
# LOCATE function returns the first starting position of a string in another string.
|
@@ -5,7 +5,7 @@ module ArelExtensions
|
|
5
5
|
SPECIAL_CHARS = {"\t" => 'CHR(9)', "\n" => 'CHR(10)', "\r" => 'CHR(13)'}
|
6
6
|
DATE_MAPPING = {'d' => 'DAY', 'm' => 'MONTH', 'w' => 'IW', 'y' => 'YEAR', 'wd' => 'D', 'h' => 'HOUR', 'mn' => 'MINUTE', 's' => 'SECOND'}
|
7
7
|
DATE_FORMAT_DIRECTIVES = {
|
8
|
-
'%Y' => '
|
8
|
+
'%Y' => 'YYYY', '%C' => 'CC', '%y' => 'YY', '%m' => 'MM', '%B' => 'Month', '%^B' => 'MONTH', '%b' => 'Mon', '%^b' => 'MON',
|
9
9
|
'%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%A' => 'Day', # day, weekday
|
10
10
|
'%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
|
11
11
|
'%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz' # seconds, subseconds
|
@@ -308,7 +308,7 @@ module ArelExtensions
|
|
308
308
|
end
|
309
309
|
|
310
310
|
def visit_ArelExtensions_Nodes_Length o, collector
|
311
|
-
collector << "LENGTH("
|
311
|
+
collector << "LENGTH#{o.bytewise ? 'B' : ''}("
|
312
312
|
collector = visit o.expr, collector
|
313
313
|
collector << ")"
|
314
314
|
collector
|
@@ -2,18 +2,6 @@ module ArelExtensions
|
|
2
2
|
module Visitors
|
3
3
|
Arel::Visitors.send(:remove_const,'Oracle12') if Arel::Visitors.const_defined?('Oracle12')
|
4
4
|
Arel::Visitors.const_set('Oracle12',Class.new(Arel::Visitors::Oracle)).class_eval do
|
5
|
-
def visit_Arel_Nodes_SelectStatement(o, collector)
|
6
|
-
# Oracle does not allow LIMIT clause with select for update
|
7
|
-
if o.limit && o.lock
|
8
|
-
raise ArgumentError, <<-MSG
|
9
|
-
'Combination of limit and lock is not supported.
|
10
|
-
because generated SQL statements
|
11
|
-
`SELECT FOR UPDATE and FETCH FIRST n ROWS` generates ORA-02014.`
|
12
|
-
MSG
|
13
|
-
end
|
14
|
-
|
15
|
-
super
|
16
|
-
end
|
17
5
|
|
18
6
|
def visit_Arel_Nodes_SelectOptions(o, collector)
|
19
7
|
collector = maybe_visit o.offset, collector
|
@@ -7,7 +7,7 @@ module ArelExtensions
|
|
7
7
|
}.freeze
|
8
8
|
|
9
9
|
DATE_FORMAT_DIRECTIVES = {
|
10
|
-
'%Y' => '
|
10
|
+
'%Y' => 'YYYY', '%C' => 'CC', '%y' => 'YY',
|
11
11
|
'%m' => 'MM', '%B' => 'Month', '%^B' => 'MONTH', '%b' => 'Mon', '%^b' => 'MON',
|
12
12
|
'%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%A' => 'Day', # day, weekday
|
13
13
|
'%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
|
@@ -117,7 +117,7 @@ module ArelExtensions
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def visit_ArelExtensions_Nodes_Length o, collector
|
120
|
-
collector << "LENGTH("
|
120
|
+
collector << "#{o.bytewise ? '' : 'CHAR_'}LENGTH("
|
121
121
|
collector = visit o.left, collector
|
122
122
|
collector << ")"
|
123
123
|
collector
|
@@ -348,6 +348,9 @@ module ArelExtensions
|
|
348
348
|
# override
|
349
349
|
remove_method(:visit_Arel_Nodes_As) rescue nil # if Arel::Visitors::ToSql.method_defined?(:visit_Arel_Nodes_As)
|
350
350
|
def visit_Arel_Nodes_As o, collector
|
351
|
+
if o.left.respond_to?(:alias)
|
352
|
+
o.left.alias = nil
|
353
|
+
end
|
351
354
|
if o.left.is_a?(Arel::Nodes::Binary)
|
352
355
|
collector << '('
|
353
356
|
collector = visit o.left, collector
|
@@ -162,6 +162,12 @@ module ArelExtensions
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
+
def test_aggregation_with_ar_calculation
|
166
|
+
# Since Arel10 (Rails6.1), some unwanted behaviors on aggregated calculation were present.
|
167
|
+
# This should works no matter which version of rails is used
|
168
|
+
assert User.group(:score).average(:id).values.all?{|e| !e.nil?}
|
169
|
+
end
|
170
|
+
|
165
171
|
# String Functions
|
166
172
|
def test_concat
|
167
173
|
assert_equal 'Camille Camille', t(@camille, @name + ' ' + @name)
|
data/version_v1.rb
CHANGED
data/version_v2.rb
CHANGED
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.0.
|
4
|
+
version: 2.0.22
|
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: 2021-
|
13
|
+
date: 2021-04-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
- !ruby/object:Gem::Version
|
223
223
|
version: '0'
|
224
224
|
requirements: []
|
225
|
-
rubygems_version: 3.
|
225
|
+
rubygems_version: 3.1.2
|
226
226
|
signing_key:
|
227
227
|
specification_version: 4
|
228
228
|
summary: Extending Arel
|