arel_extensions 2.0.8 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arel_extensions.rb +12 -1
- data/lib/arel_extensions/nodes/case.rb +7 -1
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/sqlite.rb +0 -10
- data/lib/arel_extensions/visitors/to_sql.rb +2 -2
- data/test/visitors/test_to_sql.rb +7 -0
- data/test/with_ar/all_agnostic_test.rb +1 -0
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72685b8ade2abd10db2d50ecc780270dc78719a3de6d6c3f8557327156fe547f
|
4
|
+
data.tar.gz: cc3b63b40337dadd04db2cd6e4db0499998a4ac0b2fd66e0b725436023727b78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b3deec07810ebb8d6b49da83b2c79066e1aeb298a868007ce8aba509767ca21fb9c9b4634407fa0dd5b97c58755096a208ffade5b3057847e89b61fbc68f94a
|
7
|
+
data.tar.gz: eb1908f418374e4cd5631e6d07116ec2f1bc8936dd7f113871985abe5e198ebc6b4955eb37b694e36c1c7991153444d7107b6a333c53fb1d1269ffa960dade91
|
data/lib/arel_extensions.rb
CHANGED
@@ -36,7 +36,7 @@ class Arel::Nodes::Function
|
|
36
36
|
include Arel::Expressions
|
37
37
|
end
|
38
38
|
|
39
|
-
if Arel::VERSION >= "7.1.0"
|
39
|
+
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("7.1.0")
|
40
40
|
class Arel::Nodes::Case
|
41
41
|
include Arel::Math
|
42
42
|
include Arel::Expressions
|
@@ -183,3 +183,14 @@ class Arel::Table
|
|
183
183
|
name.blank? ? self : Arel::Nodes::TableAlias.new(self,name)
|
184
184
|
end
|
185
185
|
end
|
186
|
+
|
187
|
+
class Arel::Nodes::TableAlias
|
188
|
+
def method_missing(*args)
|
189
|
+
met = args.shift.to_sym
|
190
|
+
if self.relation.respond_to?(met)
|
191
|
+
self.relation.send(met,args)
|
192
|
+
else
|
193
|
+
super
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
|
-
if Arel::VERSION < "7.1.0"
|
3
|
+
if Gem::Version.new(Arel::VERSION) < Gem::Version.new("7.1.0")
|
4
4
|
class Case < Arel::Nodes::Node
|
5
|
+
include Arel::Expressions
|
6
|
+
include Arel::Math
|
7
|
+
include Arel::Predications
|
8
|
+
include Arel::OrderPredications
|
5
9
|
attr_accessor :case, :conditions, :default
|
6
10
|
|
7
11
|
def initialize expression = nil, default = nil
|
@@ -28,6 +32,8 @@ module ArelExtensions
|
|
28
32
|
|
29
33
|
class ArelExtensions::Nodes::Case
|
30
34
|
include Arel::Expressions
|
35
|
+
include Arel::Math
|
36
|
+
include Arel::Predications
|
31
37
|
include Arel::OrderPredications
|
32
38
|
include ArelExtensions::Math
|
33
39
|
include ArelExtensions::Comparators
|
@@ -364,16 +364,6 @@ module ArelExtensions
|
|
364
364
|
collector
|
365
365
|
end
|
366
366
|
|
367
|
-
|
368
|
-
alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
|
369
|
-
def visit_Arel_Nodes_SelectStatement o, collector
|
370
|
-
if !collector.value.blank? && o.limit.blank?
|
371
|
-
o = o.dup
|
372
|
-
o.orders = []
|
373
|
-
end
|
374
|
-
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
375
|
-
end
|
376
|
-
|
377
367
|
alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
|
378
368
|
def visit_Arel_Nodes_As o, collector
|
379
369
|
if o.left.is_a?(Arel::Nodes::Binary)
|
@@ -624,7 +624,7 @@ module ArelExtensions
|
|
624
624
|
|
625
625
|
def visit_ArelExtensions_Nodes_JsonGroup o, collector
|
626
626
|
if o.as_array
|
627
|
-
res = Arel::Nodes.build_quoted('[') + (o.orders ? o.dict.group_concat(', ',o.orders) : o.dict.group_concat(', ')) + ']'
|
627
|
+
res = Arel::Nodes.build_quoted('[') + (o.orders ? o.dict.group_concat(', ', order: Array(o.orders)) : o.dict.group_concat(', ')).coalesce('') + ']'
|
628
628
|
collector = visit res, collector
|
629
629
|
else
|
630
630
|
res = Arel::Nodes.build_quoted('{')
|
@@ -639,7 +639,7 @@ module ArelExtensions
|
|
639
639
|
else
|
640
640
|
kv += v
|
641
641
|
end
|
642
|
-
res = res + kv.group_concat(', ',orders)
|
642
|
+
res = res + kv.group_concat(', ', order: Array(orders)).coalesce('')
|
643
643
|
end
|
644
644
|
res = res + '}'
|
645
645
|
collector = visit res, collector
|
@@ -463,6 +463,13 @@ module ArelExtensions
|
|
463
463
|
.must_be_like %{(LOCATE('test', "users"."name") + 1) ASC}
|
464
464
|
end
|
465
465
|
|
466
|
+
it "should be possible to call Table function on TableAlias" do
|
467
|
+
t = @table
|
468
|
+
a = t.alias("aliased_users")
|
469
|
+
_(compile(a.join(t).join_sources))
|
470
|
+
.must_be_like %{INNER JOIN \"users\"}
|
471
|
+
end
|
472
|
+
|
466
473
|
describe "logical functions" do
|
467
474
|
|
468
475
|
it "should know about truth" do
|
@@ -581,6 +581,7 @@ module ArelExtensions
|
|
581
581
|
# Case clause
|
582
582
|
def test_case
|
583
583
|
assert_equal 4, User.find_by_sql(@ut.project(@score.when(20.16).then(1).else(0).as('score_bin')).to_sql).sum(&:score_bin)
|
584
|
+
assert_equal 4, User.where(@score.when(20.16).then(1).else(0).eq(1)).count
|
584
585
|
assert_equal 2, t(@arthur, @score.when(65.62,1).else(0)+1)
|
585
586
|
assert_equal 0, t(@arthur, @score.when(65.62,1).else(0)-1)
|
586
587
|
assert_equal "11", t(@arthur, @score.when(65.62).then("1").else("0")+"1")
|
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.9
|
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: 2020-
|
13
|
+
date: 2020-08-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|