arel_extensions 1.4.2 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -1
  3. data/.gitignore +6 -7
  4. data/.rubocop.yml +3 -67
  5. data/.travis/oracle/download.js +152 -0
  6. data/.travis/oracle/download.sh +30 -0
  7. data/.travis/oracle/download_ojdbc.js +116 -0
  8. data/.travis/oracle/install.sh +34 -0
  9. data/.travis/setup_accounts.sh +9 -0
  10. data/.travis/sqlite3/extension-functions.sh +6 -0
  11. data/.travis.yml +223 -0
  12. data/Gemfile +28 -2
  13. data/README.md +90 -239
  14. data/Rakefile +30 -48
  15. data/TODO +1 -0
  16. data/appveyor.yml +22 -60
  17. data/arel_extensions.gemspec +14 -13
  18. data/functions.html +3 -3
  19. data/gemfiles/rails3.gemfile +10 -10
  20. data/gemfiles/rails4.gemfile +29 -0
  21. data/gemfiles/rails5_0.gemfile +29 -0
  22. data/gemfiles/rails5_1_4.gemfile +14 -14
  23. data/gemfiles/rails5_2.gemfile +14 -16
  24. data/init/mssql.sql +4 -4
  25. data/init/mysql.sql +38 -38
  26. data/init/oracle.sql +0 -0
  27. data/init/postgresql.sql +21 -21
  28. data/init/sqlite.sql +0 -0
  29. data/lib/arel_extensions/attributes.rb +3 -10
  30. data/lib/arel_extensions/boolean_functions.rb +14 -53
  31. data/lib/arel_extensions/common_sql_functions.rb +17 -16
  32. data/lib/arel_extensions/comparators.rb +28 -27
  33. data/lib/arel_extensions/date_duration.rb +13 -17
  34. data/lib/arel_extensions/insert_manager.rb +15 -18
  35. data/lib/arel_extensions/math.rb +53 -55
  36. data/lib/arel_extensions/math_functions.rb +39 -46
  37. data/lib/arel_extensions/nodes/abs.rb +1 -0
  38. data/lib/arel_extensions/nodes/blank.rb +2 -1
  39. data/lib/arel_extensions/nodes/case.rb +19 -20
  40. data/lib/arel_extensions/nodes/cast.rb +8 -10
  41. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  42. data/lib/arel_extensions/nodes/coalesce.rb +4 -3
  43. data/lib/arel_extensions/nodes/collate.rb +10 -9
  44. data/lib/arel_extensions/nodes/concat.rb +18 -9
  45. data/lib/arel_extensions/nodes/date_diff.rb +26 -42
  46. data/lib/arel_extensions/nodes/duration.rb +3 -0
  47. data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
  48. data/lib/arel_extensions/nodes/floor.rb +1 -1
  49. data/lib/arel_extensions/nodes/format.rb +8 -35
  50. data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
  51. data/lib/arel_extensions/nodes/function.rb +37 -42
  52. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  53. data/lib/arel_extensions/nodes/json.rb +39 -52
  54. data/lib/arel_extensions/nodes/length.rb +0 -5
  55. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  56. data/lib/arel_extensions/nodes/locate.rb +2 -1
  57. data/lib/arel_extensions/nodes/log10.rb +2 -1
  58. data/lib/arel_extensions/nodes/matches.rb +7 -5
  59. data/lib/arel_extensions/nodes/md5.rb +1 -0
  60. data/lib/arel_extensions/nodes/power.rb +5 -5
  61. data/lib/arel_extensions/nodes/rand.rb +1 -0
  62. data/lib/arel_extensions/nodes/repeat.rb +5 -3
  63. data/lib/arel_extensions/nodes/replace.rb +8 -16
  64. data/lib/arel_extensions/nodes/round.rb +6 -5
  65. data/lib/arel_extensions/nodes/soundex.rb +15 -15
  66. data/lib/arel_extensions/nodes/std.rb +21 -18
  67. data/lib/arel_extensions/nodes/substring.rb +16 -8
  68. data/lib/arel_extensions/nodes/then.rb +1 -1
  69. data/lib/arel_extensions/nodes/trim.rb +6 -4
  70. data/lib/arel_extensions/nodes/union.rb +8 -5
  71. data/lib/arel_extensions/nodes/union_all.rb +7 -4
  72. data/lib/arel_extensions/nodes/wday.rb +4 -0
  73. data/lib/arel_extensions/nodes.rb +1 -1
  74. data/lib/arel_extensions/null_functions.rb +5 -19
  75. data/lib/arel_extensions/predications.rb +43 -44
  76. data/lib/arel_extensions/railtie.rb +5 -5
  77. data/lib/arel_extensions/set_functions.rb +7 -5
  78. data/lib/arel_extensions/string_functions.rb +29 -59
  79. data/lib/arel_extensions/tasks.rb +6 -6
  80. data/lib/arel_extensions/version.rb +1 -1
  81. data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
  82. data/lib/arel_extensions/visitors/mssql.rb +191 -422
  83. data/lib/arel_extensions/visitors/mysql.rb +212 -350
  84. data/lib/arel_extensions/visitors/oracle.rb +178 -220
  85. data/lib/arel_extensions/visitors/oracle12.rb +31 -18
  86. data/lib/arel_extensions/visitors/postgresql.rb +173 -256
  87. data/lib/arel_extensions/visitors/sqlite.rb +126 -140
  88. data/lib/arel_extensions/visitors/to_sql.rb +237 -298
  89. data/lib/arel_extensions/visitors.rb +62 -83
  90. data/lib/arel_extensions.rb +31 -224
  91. data/test/database.yml +7 -15
  92. data/test/helper.rb +18 -0
  93. data/test/real_db_test.rb +117 -120
  94. data/test/support/fake_record.rb +3 -9
  95. data/test/test_comparators.rb +17 -14
  96. data/test/visitors/test_bulk_insert_oracle.rb +11 -11
  97. data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
  98. data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
  99. data/test/visitors/test_oracle.rb +55 -55
  100. data/test/visitors/test_to_sql.rb +226 -419
  101. data/test/with_ar/all_agnostic_test.rb +366 -711
  102. data/test/with_ar/insert_agnostic_test.rb +21 -27
  103. data/test/with_ar/test_bulk_sqlite.rb +16 -17
  104. data/test/with_ar/test_math_sqlite.rb +26 -26
  105. data/test/with_ar/test_string_mysql.rb +33 -31
  106. data/test/with_ar/test_string_sqlite.rb +34 -30
  107. metadata +34 -43
  108. data/.github/workflows/publish.yml +0 -29
  109. data/.github/workflows/release.yml +0 -30
  110. data/.github/workflows/ruby.yml +0 -399
  111. data/CONTRIBUTING.md +0 -102
  112. data/NEWS.md +0 -89
  113. data/bin/build +0 -15
  114. data/bin/compose +0 -6
  115. data/bin/publish +0 -8
  116. data/dev/arelx.dockerfile +0 -44
  117. data/dev/compose.yaml +0 -71
  118. data/dev/postgres.dockerfile +0 -5
  119. data/dev/rbenv +0 -189
  120. data/gemfiles/rails4_2.gemfile +0 -38
  121. data/gemfiles/rails5.gemfile +0 -29
  122. data/gemfiles/rails6.gemfile +0 -33
  123. data/gemfiles/rails6_1.gemfile +0 -33
  124. data/gemfiles/rails7.gemfile +0 -33
  125. data/gemfiles/rails7_1.gemfile +0 -33
  126. data/gemfiles/rails7_2.gemfile +0 -33
  127. data/gemspecs/arel_extensions-v1.gemspec +0 -27
  128. data/gemspecs/arel_extensions-v2.gemspec +0 -27
  129. data/generate_gems.sh +0 -15
  130. data/lib/arel_extensions/aliases.rb +0 -14
  131. data/lib/arel_extensions/helpers.rb +0 -62
  132. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
  133. data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
  134. data/lib/arel_extensions/nodes/rollup.rb +0 -36
  135. data/lib/arel_extensions/nodes/select.rb +0 -10
  136. data/lib/arel_extensions/nodes/sum.rb +0 -7
  137. data/lib/arel_extensions/visitors/convert_format.rb +0 -37
  138. data/test/arelx_test_helper.rb +0 -74
  139. data/version_v1.rb +0 -3
  140. data/version_v2.rb +0 -3
@@ -1,24 +1,25 @@
1
1
  module ArelExtensions
2
- module Nodes
3
- class FormattedNumber < Function
4
- RETURN_TYPE = :string
5
-
6
- attr_accessor :locale, :prefix, :suffix, :flags, :scientific_notation, :width, :precision, :type, :original_string
7
-
8
- def initialize expr
9
- # expr[1] = {locale: 'fr_FR', type: "e"/"f"/"d", prefix: "$ ", suffix: " %", flags: " +-#0", width: 5, precision: 6}
10
- col = expr.first
11
- @locale = expr[1][:locale]
12
- @prefix = expr[1][:prefix]
13
- @suffix = expr[1][:suffix]
14
- @width = expr[1][:width]
15
- @precision = expr[1][:precision]
16
- @type = expr[1][:type]
17
- @flags = expr[1][:flags]
18
- @scientific_notation = /[eE]/.match(expr[1][:type]) || false
19
- @original_string = expr[1][:original_string]
20
- super [col]
21
- end
22
- end
23
- end
2
+ module Nodes
3
+ class FormattedNumber < Function
4
+ RETURN_TYPE = :string
5
+
6
+ attr_accessor :locale, :prefix, :suffix, :flags, :scientific_notation, :width,:precision, :type, :original_string
7
+
8
+ def initialize expr
9
+ # expr[1] = {:locale => 'fr_FR', :type => "e"/"f"/"d", :prefix => "$ ", :suffix => " %", :flags => " +-#0", :width => 5, :precision => 6}
10
+ col = expr.first
11
+ @locale = expr[1][:locale]
12
+ @prefix = expr[1][:prefix]
13
+ @suffix = expr[1][:suffix]
14
+ @width = expr[1][:width]
15
+ @precision = expr[1][:precision]
16
+ @type = expr[1][:type]
17
+ @flags = expr[1][:flags]
18
+ @scientific_notation = /[eE]/.match(expr[1][:type]) || false
19
+ @original_string = expr[1][:original_string]
20
+ super [col]
21
+ end
22
+
23
+ end
24
+ end
24
25
  end
@@ -10,10 +10,6 @@ module ArelExtensions
10
10
 
11
11
  RETURN_TYPE = :string # by default...
12
12
 
13
- # Support multibyte string if they are available.
14
- MBSTRING =
15
- defined?(ActiveSupport::Multibyte::Chars) ? ActiveSupport::Multibyte::Chars : String
16
-
17
13
  # overrides as to make new Node like AliasPredication
18
14
 
19
15
  def return_type
@@ -21,15 +17,11 @@ module ArelExtensions
21
17
  end
22
18
 
23
19
  def as 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
20
+ Arel::Nodes::As.new(self, Arel.sql(other))
29
21
  end
30
22
 
31
23
  def expr
32
- @expressions.first
24
+ @expressions.first
33
25
  end
34
26
 
35
27
  def left
@@ -41,21 +33,25 @@ module ArelExtensions
41
33
  end
42
34
 
43
35
  def ==(other)
44
- Arel::Nodes::Equality.new self, Arel.quoted(other, self)
36
+ Arel::Nodes::Equality.new self, Arel::Nodes.build_quoted(other, self)
45
37
  end
46
38
 
47
39
  def !=(other)
48
- Arel::Nodes::NotEqual.new self, Arel.quoted(other, self)
40
+ Arel::Nodes::NotEqual.new self, Arel::Nodes.build_quoted(other, self)
49
41
  end
50
42
 
51
43
  def type_of_attribute(att)
52
44
  case att
53
45
  when Arel::Attributes::Attribute
54
- Arel.column_of(att.relation.table_name, att.name.to_s)&.type || att
46
+ begin
47
+ Arel::Table.engine.connection.schema_cache.columns_hash(att.relation.table_name)[att.name.to_s].type
48
+ rescue
49
+ att
50
+ end
55
51
  when ArelExtensions::Nodes::Function
56
52
  att.return_type
57
- # else
58
- # nil
53
+ # else
54
+ # nil
59
55
  end
60
56
  end
61
57
 
@@ -64,21 +60,19 @@ module ArelExtensions
64
60
  when Arel::Attributes::Attribute, Arel::Nodes::Node, Integer
65
61
  object
66
62
  when DateTime
67
- Arel.quoted(object, self)
63
+ Arel::Nodes.build_quoted(object, self)
68
64
  when Time
69
- Arel.quoted(object.strftime('%H:%M:%S'), self)
70
- when MBSTRING, String, Symbol
71
- Arel.quoted(object.to_s)
65
+ Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
66
+ when String, Symbol
67
+ Arel::Nodes.build_quoted(object.to_s)
72
68
  when Date
73
- Arel.quoted(object.to_s, self)
69
+ Arel::Nodes.build_quoted(object.to_s, self)
74
70
  when NilClass
75
71
  Arel.sql('NULL')
76
72
  when ActiveSupport::Duration
77
73
  Arel.sql(object.to_i)
78
- when Array
79
- Arel.grouping(object.map{|e| convert_to_node(e)})
80
74
  else
81
- raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
75
+ raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
82
76
  end
83
77
  end
84
78
 
@@ -87,7 +81,7 @@ module ArelExtensions
87
81
  when Arel::Nodes::Node
88
82
  object
89
83
  when Integer
90
- Arel.quoted(object.to_s)
84
+ Arel::Nodes.build_quoted(object.to_s)
91
85
  when Arel::Attributes::Attribute
92
86
  case self.type_of_attribute(object)
93
87
  when :date
@@ -98,19 +92,19 @@ module ArelExtensions
98
92
  object
99
93
  end
100
94
  when DateTime
101
- Arel.quoted(object, self)
95
+ Arel::Nodes.build_quoted(object, self)
102
96
  when Time
103
- Arel.quoted(object.strftime('%H:%M:%S'), self)
104
- when MBSTRING, String
105
- Arel.quoted(object.to_s)
97
+ Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
98
+ when String
99
+ Arel::Nodes.build_quoted(object)
106
100
  when Date
107
- Arel.quoted(object, self)
101
+ Arel::Nodes.build_quoted(object, self)
108
102
  when NilClass
109
103
  Arel.sql(nil)
110
104
  when ActiveSupport::Duration
111
- Arel.quoted(object.to_i.to_s)
105
+ Arel::Nodes.build_quoted(object.to_i.to_s)
112
106
  else
113
- raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
107
+ raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
114
108
  end
115
109
  end
116
110
 
@@ -119,13 +113,13 @@ module ArelExtensions
119
113
  when Arel::Attributes::Attribute, Arel::Nodes::Node
120
114
  object
121
115
  when DateTime, Time
122
- Arel.quoted(Date.new(object.year, object.month, object.day), self)
123
- when MBSTRING, String
124
- Arel.quoted(Date.parse(object.to_s), self)
116
+ Arel::Nodes.build_quoted(Date.new(object.year, object.month, object.day), self)
117
+ when String
118
+ Arel::Nodes.build_quoted(Date.parse(object), self)
125
119
  when Date
126
- Arel.quoted(object, self)
120
+ Arel::Nodes.build_quoted(object, self)
127
121
  else
128
- raise(ArgumentError, "#{object.class} cannot be converted to Date")
122
+ raise(ArgumentError, "#{object.class} can not be converted to Date")
129
123
  end
130
124
  end
131
125
 
@@ -134,13 +128,13 @@ module ArelExtensions
134
128
  when Arel::Attributes::Attribute, Arel::Nodes::Node
135
129
  object
136
130
  when DateTime, Time
137
- Arel.quoted(object, self)
138
- when MBSTRING, String
139
- Arel.quoted(Time.parse(object.to_s), self)
131
+ Arel::Nodes.build_quoted(object, self)
132
+ when String
133
+ Arel::Nodes.build_quoted(Time.parse(object), self)
140
134
  when Date
141
- Arel.quoted(Time.utc(object.year, object.month, object.day, 0, 0, 0), self)
135
+ Arel::Nodes.build_quoted(Time.utc(object.year, object.month, object.day, 0, 0, 0), self)
142
136
  else
143
- raise(ArgumentError, "#{object.class} cannot be converted to Datetime")
137
+ raise(ArgumentError, "#{object.class} can not be converted to Datetime")
144
138
  end
145
139
  end
146
140
 
@@ -158,9 +152,10 @@ module ArelExtensions
158
152
  when NilClass
159
153
  0
160
154
  else
161
- raise(ArgumentError, "#{object.class} cannot be converted to NUMBER arg")
155
+ raise(ArgumentError, "#{object.class} can not be converted to NUMBER arg")
162
156
  end
163
157
  end
158
+
164
159
  end
165
160
  end
166
161
  end
File without changes
@@ -11,76 +11,56 @@ module ArelExtensions
11
11
  end
12
12
 
13
13
  def get key
14
- JsonGet.new(self, key)
14
+ JsonGet.new(self,key)
15
15
  end
16
16
 
17
17
  def set key, value
18
- JsonSet.new(self, key, value)
18
+ JsonSet.new(self,key,value)
19
19
  end
20
20
 
21
- def group as_array = true, orders = nil, distinct: false
22
- if distinct
23
- JsonGroup.new(Arel::Nodes::NamedFunction.new('DISTINCT', [self]), as_array, orders)
24
- else
25
- JsonGroup.new(self, as_array, orders)
26
- end
21
+ def group as_array = true, orders= nil
22
+ JsonGroup.new(self,as_array, orders)
27
23
  end
28
24
 
29
25
  def hash
30
26
  [@dict].hash
31
27
  end
32
28
 
33
- def convert_to_json_node(n)
34
- case n
35
- when JsonNode
36
- n.dict
37
- when Array
38
- n.map{|e|
39
- (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_json_node(e)
40
- }
41
- when Hash
42
- n.reduce({}){|acc, v|
43
- acc[convert_to_json_node(v[0])] = (v[1].is_a?(Array) || v[1].is_a?(Hash)) ? Json.new(v[1]) : convert_to_json_node(v[1])
44
- acc
45
- }
46
- when String, Numeric, TrueClass, FalseClass
47
- convert_to_node(n)
48
- when Date
49
- convert_to_node(n.strftime('%Y-%m-%d'))
50
- when DateTime, Time
51
- convert_to_node(n.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'))
52
- when NilClass
53
- Arel.null
54
- when Arel::SelectManager
55
- Arel.grouping(n)
56
- else
57
- convert_to_node(n)
58
- end
59
- end
60
-
61
- def type_of_node(v)
62
- if v.is_a?(Arel::Attributes::Attribute)
63
- self.type_of_attribute(v)
64
- elsif v.respond_to?(:return_type)
65
- v.return_type
66
- elsif v.nil?
67
- :nil
68
- else
69
- :string
70
- end
71
- end
72
29
  end
73
30
 
74
31
  class Json < JsonNode
32
+
75
33
  def initialize *expr
76
- @dict =
77
- if expr.length == 1
78
- convert_to_json_node(expr.first)
34
+ if expr.length == 1
35
+ case expr.first
36
+ when JsonNode
37
+ @dict = expr.first.dict
38
+ when Array
39
+ @dict = expr.first.map{|e|
40
+ (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_node(e)
41
+ }
42
+ when Hash
43
+ @dict = expr.first.inject({}){|acc,v|
44
+ acc[convert_to_node(v[0])] = (v[1].is_a?(Array) || v[1].is_a?(Hash)) ? Json.new(v[1]) : convert_to_node(v[1])
45
+ acc
46
+ }
47
+ when String, Numeric, TrueClass, FalseClass
48
+ @dict = convert_to_node(expr.first)
49
+ when NilClass
50
+ @dict = Arel.sql('null')
79
51
  else
80
- expr.map{|e| convert_to_json_node(e) }
52
+ if expr.first.is_a?(String) || (expr.first.is_a?(Arel::Attributes::Attribute) && type_of_attribute(expr.first) == :string) || (expr.first.return_type == :string)
53
+ @dict = convert_to_node(expr.first)
54
+ else
55
+ @dict = [convert_to_node(expr.first)]
56
+ end
81
57
  end
58
+ else
59
+ @dict = expr.map{|e| (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_node(e) }
60
+ end
82
61
  super
83
62
  end
63
+
84
64
  end
85
65
 
86
66
  class JsonMerge < JsonNode
@@ -93,7 +73,11 @@ module ArelExtensions
93
73
  @dict = as_array ? json : json.dict
94
74
  @as_array = as_array
95
75
  if orders
96
- @orders = Array(orders)
76
+ if orders.is_a?(Array)
77
+ @orders = orders
78
+ else
79
+ @orders = [orders]
80
+ end
97
81
  end
98
82
  end
99
83
  end
@@ -105,6 +89,7 @@ module ArelExtensions
105
89
  @dict = json
106
90
  @key = convert_to_node(key)
107
91
  end
92
+
108
93
  end
109
94
 
110
95
  class JsonSet < JsonNode
@@ -115,6 +100,8 @@ module ArelExtensions
115
100
  @key = convert_to_node(key)
116
101
  @value = Json.new(value)
117
102
  end
103
+
118
104
  end
105
+
119
106
  end
120
107
  end
@@ -2,12 +2,7 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class Length < Function
4
4
  RETURN_TYPE = :integer
5
- attr_accessor :bytewise
6
5
 
7
- def initialize(node, bytewise = true)
8
- @bytewise = bytewise
9
- super([node])
10
- end
11
6
  end
12
7
  end
13
8
  end
@@ -4,7 +4,7 @@ module ArelExtensions
4
4
  RETURN_TYPE = :number
5
5
 
6
6
  def initialize expr
7
- super [convert_to_node(expr.first), Arel.quoted(expr[1])]
7
+ super [convert_to_node(expr.first), Arel::Nodes.build_quoted(expr[1])]
8
8
  end
9
9
  end
10
10
  end
@@ -7,8 +7,9 @@ module ArelExtensions
7
7
  tab = expr.map do |arg|
8
8
  convert_to_node(arg)
9
9
  end
10
- super(tab)
10
+ return super(tab)
11
11
  end
12
+
12
13
  end
13
14
  end
14
15
  end
@@ -1,7 +1,8 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Log10 < Function
4
- RETURN_TYPE = :number
4
+ RETURN_TYPE = :number
5
+
5
6
  end
6
7
  end
7
8
  end
@@ -1,10 +1,11 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class IMatches < Arel::Nodes::Matches
4
- attr_accessor :case_sensitive if Arel::VERSION.to_i < 7
5
4
 
5
+ attr_accessor :case_sensitive if Arel::VERSION.to_i < 7
6
+
6
7
  def initialize(left, right, escape = nil)
7
- r = Arel.quoted(right)
8
+ r = Arel::Nodes.build_quoted(right)
8
9
  if Arel::VERSION.to_i < 7 # managed by default in version 7+ (rails 5), so useful for rails 3 & 4
9
10
  super(left, r, escape)
10
11
  @case_sensitive = false
@@ -16,14 +17,15 @@ module ArelExtensions
16
17
 
17
18
  class IDoesNotMatch < IMatches
18
19
  end
19
-
20
+
20
21
  class AiMatches < IMatches
21
22
  end
22
-
23
+
23
24
  class AiIMatches < IMatches
24
25
  end
25
-
26
+
26
27
  class SMatches < IMatches
27
28
  end
29
+
28
30
  end
29
31
  end
@@ -2,6 +2,7 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class MD5 < Function
4
4
  RETURN_TYPE = :string
5
+
5
6
  end
6
7
  end
7
8
  end
@@ -1,11 +1,11 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Power < Function
4
- RETURN_TYPE = :number
5
-
6
- def initialize expr
7
- super [convert_to_node(expr.first), convert_to_number(expr[1])]
8
- end
4
+ RETURN_TYPE = :number
5
+
6
+ def initialize expr
7
+ super [convert_to_node(expr.first), convert_to_number(expr[1])]
8
+ end
9
9
  end
10
10
  end
11
11
  end
@@ -10,6 +10,7 @@ module ArelExtensions
10
10
  super []
11
11
  end
12
12
  end
13
+
13
14
  end
14
15
  end
15
16
  end
@@ -2,17 +2,19 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class Repeat < Function
4
4
  RETURN_TYPE = :string
5
-
5
+
6
6
  def initialize expr
7
7
  tab = expr.map { |arg|
8
8
  convert_to_node(arg)
9
9
  }
10
- super(tab)
10
+ return super(tab)
11
11
  end
12
12
 
13
13
  def +(other)
14
- ArelExtensions::Nodes::Concat.new(self.expressions + [other])
14
+ return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
15
15
  end
16
+
16
17
  end
18
+
17
19
  end
18
20
  end
@@ -2,26 +2,18 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class Replace < Function
4
4
  RETURN_TYPE = :string
5
- attr_accessor :left, :pattern, :substitute
6
5
 
7
- def initialize left, pattern, substitute
8
- @left = convert_to_node(left)
9
- @pattern = convert_to_node(pattern)
10
- @substitute = convert_to_node(substitute)
11
- super([@left, @pattern, @substitute])
6
+ def initialize expr
7
+ tab = expr.map { |arg|
8
+ convert_to_node(arg)
9
+ }
10
+ return super(tab)
12
11
  end
13
- end
14
-
15
- class RegexpReplace < Function
16
- RETURN_TYPE = :string
17
- attr_accessor :left, :pattern, :substitute
18
12
 
19
- def initialize left, pattern, substitute
20
- @left = convert_to_node(left)
21
- @pattern = (pattern.is_a?(Regexp) ? pattern : %r[#{pattern}])
22
- @substitute = convert_to_node(substitute)
23
- super([@left, @pattern, @substitute])
13
+ def +(other)
14
+ return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
24
15
  end
16
+
25
17
  end
26
18
  end
27
19
  end
@@ -4,12 +4,13 @@ module ArelExtensions
4
4
  RETURN_TYPE = :number
5
5
 
6
6
  def initialize expr
7
- if expr && expr.length == 1
8
- super [convert_to_node(expr.first)]
9
- else
10
- super [convert_to_node(expr.first), convert_to_number(expr[1])]
11
- end
7
+ if expr && expr.length == 1
8
+ super [convert_to_node(expr.first)]
9
+ else
10
+ super [convert_to_node(expr.first), convert_to_number(expr[1])]
11
+ end
12
12
  end
13
+
13
14
  end
14
15
  end
15
16
  end
@@ -1,18 +1,18 @@
1
1
  module ArelExtensions
2
- module Nodes
3
- class Soundex < Function
4
- include Arel::Expressions
5
- include ArelExtensions::Comparators
2
+ module Nodes
3
+ class Soundex < Function
4
+ include Arel::Expressions
5
+ include ArelExtensions::Comparators
6
+
7
+ RETURN_TYPE = :string
8
+
9
+ def ==(other)
10
+ Arel::Nodes::Equality.new self, Arel::Nodes.build_quoted(other, self)
11
+ end
6
12
 
7
- RETURN_TYPE = :string
8
-
9
- def ==(other)
10
- Arel::Nodes::Equality.new self, Arel.quoted(other, self)
11
- end
12
-
13
- def !=(other)
14
- Arel::Nodes::NotEqual.new self, Arel.quoted(other, self)
15
- end
16
- end
17
- end
13
+ def !=(other)
14
+ Arel::Nodes::NotEqual.new self, Arel::Nodes.build_quoted(other, self)
15
+ end
16
+ end
17
+ end
18
18
  end
@@ -1,23 +1,26 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
- class Std < AggregateFunction
4
- RETURN_TYPE = :number
5
- attr_accessor :unbiased_estimator
6
-
7
- def initialize node, **opts
8
- @unbiased_estimator = opts[:unbiased] ? true : false
9
- super node, **opts
10
- end
11
- end
12
-
13
- class Variance < AggregateFunction
14
- RETURN_TYPE = :number
15
- attr_accessor :unbiased_estimator
16
-
17
- def initialize node, **opts
18
- @unbiased_estimator = opts[:unbiased] ? true : false
19
- super node, **opts
20
- end
3
+ class Std < Function
4
+ RETURN_TYPE = :number
5
+
6
+ attr_accessor :unbiased_estimator
7
+ def initialize expr
8
+ col = expr.first
9
+ @unbiased_estimator = expr[1]
10
+ super [col]
11
+ end
21
12
  end
13
+
14
+ class Variance < Function
15
+ RETURN_TYPE = :number
16
+
17
+ attr_accessor :unbiased_estimator
18
+ def initialize expr
19
+ col = expr.first
20
+ @unbiased_estimator = expr[1]
21
+ super [col]
22
+ end
23
+ end
24
+
22
25
  end
23
26
  end
@@ -1,15 +1,23 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Substring < Function
4
- RETURN_TYPE = :string
4
+ RETURN_TYPE = :string
5
+
6
+ def initialize expr
7
+ tab = [convert_to_node(expr[0]), convert_to_node(expr[1])]
8
+ if expr[2]
9
+ tab << convert_to_node(expr[2])
10
+ # else
11
+ # tab << expr[0].length
12
+ end
13
+ return super(tab)
14
+ end
15
+
16
+ # def +(other)
17
+ # puts "[Substring] : #{other.inspect} (#{self.expressions.inspect})"
18
+ # return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
19
+ # end
5
20
 
6
- def initialize expr
7
- tab = [convert_to_node(expr[0]), convert_to_node(expr[1])]
8
- if expr[2]
9
- tab << convert_to_node(expr[2])
10
- end
11
- super(tab)
12
- end
13
21
  end
14
22
  end
15
23
  end
@@ -5,7 +5,7 @@ module ArelExtensions
5
5
  tab = expr.map { |arg|
6
6
  convert_to_node(arg)
7
7
  }
8
- super(tab)
8
+ return super(tab)
9
9
  end
10
10
  end
11
11
  end