arel_extensions 1.2.17 → 1.2.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +102 -0
  3. data/Gemfile +10 -10
  4. data/Rakefile +4 -4
  5. data/arel_extensions.gemspec +1 -1
  6. data/gemfiles/rails3.gemfile +9 -9
  7. data/gemfiles/rails4.gemfile +13 -13
  8. data/gemfiles/rails5_0.gemfile +13 -13
  9. data/gemfiles/rails5_1_4.gemfile +13 -13
  10. data/gemfiles/rails5_2.gemfile +13 -13
  11. data/gemfiles/rails6.gemfile +13 -13
  12. data/gemfiles/rails6_1.gemfile +30 -0
  13. data/gemspecs/arel_extensions-v1.gemspec +28 -0
  14. data/{gemspec_v2 → gemspecs}/arel_extensions-v2.gemspec +0 -0
  15. data/generate_gems.sh +4 -3
  16. data/lib/arel_extensions.rb +23 -5
  17. data/lib/arel_extensions/attributes.rb +0 -0
  18. data/lib/arel_extensions/boolean_functions.rb +3 -7
  19. data/lib/arel_extensions/common_sql_functions.rb +0 -2
  20. data/lib/arel_extensions/comparators.rb +11 -14
  21. data/lib/arel_extensions/date_duration.rb +4 -5
  22. data/lib/arel_extensions/insert_manager.rb +16 -17
  23. data/lib/arel_extensions/math.rb +8 -9
  24. data/lib/arel_extensions/math_functions.rb +22 -20
  25. data/lib/arel_extensions/nodes/abs.rb +0 -1
  26. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -1
  27. data/lib/arel_extensions/nodes/blank.rb +0 -1
  28. data/lib/arel_extensions/nodes/case.rb +3 -4
  29. data/lib/arel_extensions/nodes/cast.rb +0 -1
  30. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  31. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  32. data/lib/arel_extensions/nodes/coalesce.rb +0 -1
  33. data/lib/arel_extensions/nodes/collate.rb +0 -1
  34. data/lib/arel_extensions/nodes/concat.rb +2 -4
  35. data/lib/arel_extensions/nodes/date_diff.rb +4 -5
  36. data/lib/arel_extensions/nodes/duration.rb +0 -1
  37. data/lib/arel_extensions/nodes/find_in_set.rb +0 -1
  38. data/lib/arel_extensions/nodes/floor.rb +1 -1
  39. data/lib/arel_extensions/nodes/format.rb +1 -0
  40. data/lib/arel_extensions/nodes/formatted_number.rb +0 -1
  41. data/lib/arel_extensions/nodes/function.rb +8 -5
  42. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  43. data/lib/arel_extensions/nodes/json.rb +0 -6
  44. data/lib/arel_extensions/nodes/length.rb +5 -0
  45. data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
  46. data/lib/arel_extensions/nodes/locate.rb +0 -1
  47. data/lib/arel_extensions/nodes/log10.rb +1 -2
  48. data/lib/arel_extensions/nodes/matches.rb +0 -2
  49. data/lib/arel_extensions/nodes/md5.rb +0 -1
  50. data/lib/arel_extensions/nodes/power.rb +0 -1
  51. data/lib/arel_extensions/nodes/rand.rb +0 -1
  52. data/lib/arel_extensions/nodes/repeat.rb +0 -2
  53. data/lib/arel_extensions/nodes/replace.rb +0 -2
  54. data/lib/arel_extensions/nodes/round.rb +0 -1
  55. data/lib/arel_extensions/nodes/soundex.rb +0 -1
  56. data/lib/arel_extensions/nodes/std.rb +4 -5
  57. data/lib/arel_extensions/nodes/substring.rb +0 -1
  58. data/lib/arel_extensions/nodes/sum.rb +0 -0
  59. data/lib/arel_extensions/nodes/then.rb +0 -0
  60. data/lib/arel_extensions/nodes/trim.rb +0 -2
  61. data/lib/arel_extensions/nodes/union.rb +0 -2
  62. data/lib/arel_extensions/nodes/union_all.rb +0 -2
  63. data/lib/arel_extensions/nodes/wday.rb +0 -4
  64. data/lib/arel_extensions/null_functions.rb +3 -5
  65. data/lib/arel_extensions/predications.rb +2 -3
  66. data/lib/arel_extensions/railtie.rb +5 -5
  67. data/lib/arel_extensions/set_functions.rb +0 -2
  68. data/lib/arel_extensions/string_functions.rb +30 -23
  69. data/lib/arel_extensions/tasks.rb +1 -1
  70. data/lib/arel_extensions/version.rb +1 -1
  71. data/lib/arel_extensions/visitors.rb +68 -60
  72. data/lib/arel_extensions/visitors/convert_format.rb +37 -0
  73. data/lib/arel_extensions/visitors/ibm_db.rb +4 -11
  74. data/lib/arel_extensions/visitors/mssql.rb +50 -45
  75. data/lib/arel_extensions/visitors/mysql.rb +63 -65
  76. data/lib/arel_extensions/visitors/oracle.rb +50 -57
  77. data/lib/arel_extensions/visitors/oracle12.rb +1 -14
  78. data/lib/arel_extensions/visitors/postgresql.rb +39 -34
  79. data/lib/arel_extensions/visitors/sqlite.rb +23 -18
  80. data/lib/arel_extensions/visitors/to_sql.rb +58 -48
  81. data/test/arelx_test_helper.rb +0 -2
  82. data/test/database.yml +2 -0
  83. data/test/real_db_test.rb +26 -41
  84. data/test/support/fake_record.rb +1 -1
  85. data/test/test_comparators.rb +0 -4
  86. data/test/visitors/test_bulk_insert_oracle.rb +0 -1
  87. data/test/visitors/test_bulk_insert_sqlite.rb +0 -2
  88. data/test/visitors/test_oracle.rb +1 -2
  89. data/test/visitors/test_to_sql.rb +16 -25
  90. data/test/with_ar/all_agnostic_test.rb +140 -139
  91. data/test/with_ar/insert_agnostic_test.rb +0 -2
  92. data/test/with_ar/test_bulk_sqlite.rb +0 -4
  93. data/test/with_ar/test_math_sqlite.rb +4 -8
  94. data/test/with_ar/test_string_mysql.rb +1 -5
  95. data/test/with_ar/test_string_sqlite.rb +1 -5
  96. data/version_v1.rb +1 -1
  97. data/version_v2.rb +1 -1
  98. metadata +8 -4
@@ -9,6 +9,5 @@ module ArelExtensions
9
9
  super [node]
10
10
  end
11
11
  end
12
-
13
12
  end
14
13
  end
@@ -19,6 +19,5 @@ module ArelExtensions
19
19
  super expr.first
20
20
  end
21
21
  end
22
-
23
22
  end
24
23
  end
@@ -19,7 +19,6 @@ module ArelExtensions
19
19
 
20
20
  class Else < Arel::Nodes::Unary # :nodoc:
21
21
  end
22
-
23
22
  end
24
23
  else
25
24
  class Case < Arel::Nodes::Case
@@ -96,9 +95,9 @@ module ArelExtensions
96
95
 
97
96
  def eql? other
98
97
  self.class == other.class &&
99
- self.case == other.case &&
100
- self.conditions == other.conditions &&
101
- self.default == other.default
98
+ self.case == other.case &&
99
+ self.conditions == other.conditions &&
100
+ self.default == other.default
102
101
  end
103
102
  alias :== :eql?
104
103
 
@@ -49,7 +49,6 @@ module ArelExtensions
49
49
  def return_type
50
50
  @return_type
51
51
  end
52
-
53
52
  end
54
53
  end
55
54
  end
@@ -1,7 +1,7 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Ceil < Function
4
- RETURN_TYPE = :number
4
+ RETURN_TYPE = :number
5
5
  end
6
6
  end
7
7
  end
File without changes
@@ -29,7 +29,6 @@ module ArelExtensions
29
29
  end
30
30
  return super(tab)
31
31
  end
32
-
33
32
  end
34
33
  end
35
34
  end
@@ -12,7 +12,6 @@ module ArelExtensions
12
12
  tab = [convert_to_node(left)]
13
13
  return super(tab)
14
14
  end
15
-
16
15
  end
17
16
  end
18
17
  end
@@ -11,7 +11,7 @@ module ArelExtensions::Nodes
11
11
  else
12
12
  node
13
13
  end
14
- }.flatten.reduce([]) { | res, b |
14
+ }.flatten.reduce([]) { |res, b|
15
15
  # concatenate successive literal strings.
16
16
  if b.is_a?(Arel::Nodes::Quoted) && b.expr == ""
17
17
  res
@@ -37,7 +37,6 @@ module ArelExtensions::Nodes
37
37
  def concat(other)
38
38
  Concat.new(self.expressions + [other])
39
39
  end
40
-
41
40
  end
42
41
 
43
42
  class GroupConcat < AggregateFunction
@@ -47,8 +46,7 @@ module ArelExtensions::Nodes
47
46
 
48
47
  def initialize node, separator = ', ', **opts
49
48
  @separator = convert_to_node(separator)
50
- super node, opts
49
+ super node, **opts
51
50
  end
52
-
53
51
  end
54
52
  end
@@ -2,7 +2,7 @@ require 'date'
2
2
 
3
3
  module ArelExtensions
4
4
  module Nodes
5
- class DateDiff < Function #difference entre colonne date et date string/date
5
+ class DateDiff < Function # difference entre colonne date et date string/date
6
6
  attr_accessor :left_node_type
7
7
  attr_accessor :right_node_type
8
8
 
@@ -97,7 +97,7 @@ module ArelExtensions
97
97
  v ||= self.expressions.last
98
98
  if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === v
99
99
  if @date_type == :ruby_date
100
- Arel.sql("(INTERVAL '1' DAY) * %s" % v.inspect.to_i )
100
+ Arel.sql("(INTERVAL '1' DAY) * %s" % v.inspect.to_i)
101
101
  else
102
102
  Arel.sql("(INTERVAL '1' SECOND) * %s" % v.to_i)
103
103
  end
@@ -150,6 +150,7 @@ module ArelExtensions
150
150
  end
151
151
 
152
152
  private
153
+
153
154
  def convert(object)
154
155
  case object
155
156
  when Arel::Attributes::Attribute, Arel::Nodes::Node, ActiveSupport::Duration
@@ -166,7 +167,7 @@ module ArelExtensions
166
167
  end
167
168
  end
168
169
 
169
- class DateSub < Function #difference entre colonne date et date string/date
170
+ class DateSub < Function # difference entre colonne date et date string/date
170
171
  RETURN_TYPE = :integer
171
172
 
172
173
  def initialize(expr)
@@ -187,8 +188,6 @@ module ArelExtensions
187
188
  end
188
189
  end
189
190
  end
190
-
191
191
  end
192
-
193
192
  end
194
193
  end
@@ -20,7 +20,6 @@ module ArelExtensions
20
20
  def right
21
21
  @expressions[1]
22
22
  end
23
-
24
23
  end
25
24
  end
26
25
  end
@@ -2,7 +2,6 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class FindInSet < Function
4
4
  RETURN_TYPE = :integer
5
-
6
5
  end
7
6
  end
8
7
  end
@@ -1,7 +1,7 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Floor < Function
4
- RETURN_TYPE = :number
4
+ RETURN_TYPE = :number
5
5
  end
6
6
  end
7
7
  end
@@ -6,6 +6,7 @@ module ArelExtensions
6
6
  RETURN_TYPE = :string
7
7
 
8
8
  attr_accessor :col_type, :iso_format
9
+
9
10
  def initialize expr
10
11
  col = expr.first
11
12
  @iso_format = convert_format(expr[1])
@@ -19,7 +19,6 @@ module ArelExtensions
19
19
  @original_string = expr[1][:original_string]
20
20
  super [col]
21
21
  end
22
-
23
22
  end
24
23
  end
25
24
  end
@@ -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
@@ -54,8 +58,8 @@ module ArelExtensions
54
58
  end
55
59
  when ArelExtensions::Nodes::Function
56
60
  att.return_type
57
- # else
58
- # nil
61
+ # else
62
+ # nil
59
63
  end
60
64
  end
61
65
 
@@ -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{|r| convert_to_node(e)})
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
@@ -161,7 +165,6 @@ module ArelExtensions
161
165
  raise(ArgumentError, "#{object.class} cannot be converted to NUMBER arg")
162
166
  end
163
167
  end
164
-
165
168
  end
166
169
  end
167
170
  end
File without changes
@@ -63,11 +63,9 @@ module ArelExtensions
63
63
  :string
64
64
  end
65
65
  end
66
-
67
66
  end
68
67
 
69
68
  class Json < JsonNode
70
-
71
69
  def initialize *expr
72
70
  @dict =
73
71
  if expr.length == 1
@@ -77,7 +75,6 @@ module ArelExtensions
77
75
  end
78
76
  super
79
77
  end
80
-
81
78
  end
82
79
 
83
80
  class JsonMerge < JsonNode
@@ -102,7 +99,6 @@ module ArelExtensions
102
99
  @dict = json
103
100
  @key = convert_to_node(key)
104
101
  end
105
-
106
102
  end
107
103
 
108
104
  class JsonSet < JsonNode
@@ -113,8 +109,6 @@ module ArelExtensions
113
109
  @key = convert_to_node(key)
114
110
  @value = Json.new(value)
115
111
  end
116
-
117
112
  end
118
-
119
113
  end
120
114
  end
@@ -2,7 +2,12 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class Length < Function
4
4
  RETURN_TYPE = :integer
5
+ attr_accessor :bytewise
5
6
 
7
+ def initialize(node, bytewise = true)
8
+ @bytewise = bytewise
9
+ super([node])
10
+ end
6
11
  end
7
12
  end
8
13
  end
File without changes
@@ -9,7 +9,6 @@ module ArelExtensions
9
9
  end
10
10
  return super(tab)
11
11
  end
12
-
13
12
  end
14
13
  end
15
14
  end
@@ -1,8 +1,7 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Log10 < Function
4
- RETURN_TYPE = :number
5
-
4
+ RETURN_TYPE = :number
6
5
  end
7
6
  end
8
7
  end
@@ -1,7 +1,6 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class IMatches < Arel::Nodes::Matches
4
-
5
4
  attr_accessor :case_sensitive if Arel::VERSION.to_i < 7
6
5
 
7
6
  def initialize(left, right, escape = nil)
@@ -26,6 +25,5 @@ module ArelExtensions
26
25
 
27
26
  class SMatches < IMatches
28
27
  end
29
-
30
28
  end
31
29
  end
@@ -2,7 +2,6 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class MD5 < Function
4
4
  RETURN_TYPE = :string
5
-
6
5
  end
7
6
  end
8
7
  end
@@ -6,7 +6,6 @@ module ArelExtensions
6
6
  def initialize expr
7
7
  super [convert_to_node(expr.first), convert_to_number(expr[1])]
8
8
  end
9
-
10
9
  end
11
10
  end
12
11
  end
@@ -10,7 +10,6 @@ module ArelExtensions
10
10
  super []
11
11
  end
12
12
  end
13
-
14
13
  end
15
14
  end
16
15
  end
@@ -13,8 +13,6 @@ module ArelExtensions
13
13
  def +(other)
14
14
  return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
15
15
  end
16
-
17
16
  end
18
-
19
17
  end
20
18
  end
@@ -14,7 +14,6 @@ module ArelExtensions
14
14
  def +(other)
15
15
  return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
16
16
  end
17
-
18
17
  end
19
18
 
20
19
  class RegexpReplace < Function
@@ -32,6 +31,5 @@ module ArelExtensions
32
31
  return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
33
32
  end
34
33
  end
35
-
36
34
  end
37
35
  end
@@ -10,7 +10,6 @@ module ArelExtensions
10
10
  super [convert_to_node(expr.first), convert_to_number(expr[1])]
11
11
  end
12
12
  end
13
-
14
13
  end
15
14
  end
16
15
  end
@@ -13,7 +13,6 @@ module ArelExtensions
13
13
  def !=(other)
14
14
  Arel::Nodes::NotEqual.new self, Arel::Nodes.build_quoted(other, self)
15
15
  end
16
-
17
16
  end
18
17
  end
19
18
  end
@@ -4,9 +4,9 @@ module ArelExtensions
4
4
  RETURN_TYPE = :number
5
5
  attr_accessor :unbiased_estimator
6
6
 
7
- def initialize node, opts = {}
7
+ def initialize node, **opts
8
8
  @unbiased_estimator = opts[:unbiased] ? true : false
9
- super node, opts
9
+ super node, **opts
10
10
  end
11
11
  end
12
12
 
@@ -14,11 +14,10 @@ module ArelExtensions
14
14
  RETURN_TYPE = :number
15
15
  attr_accessor :unbiased_estimator
16
16
 
17
- def initialize node, opts = {}
17
+ def initialize node, **opts
18
18
  @unbiased_estimator = opts[:unbiased] ? true : false
19
- super node, opts
19
+ super node, **opts
20
20
  end
21
21
  end
22
-
23
22
  end
24
23
  end
@@ -10,7 +10,6 @@ module ArelExtensions
10
10
  end
11
11
  return super(tab)
12
12
  end
13
-
14
13
  end
15
14
  end
16
15
  end
File without changes
File without changes
@@ -13,7 +13,6 @@ module ArelExtensions
13
13
  def +(other)
14
14
  return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
15
15
  end
16
-
17
16
  end
18
17
 
19
18
  class Ltrim < Trim
@@ -23,6 +22,5 @@ module ArelExtensions
23
22
  class Rtrim < Trim
24
23
  RETURN_TYPE = :string
25
24
  end
26
-
27
25
  end
28
26
  end