arel_extensions 1.3.2 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -2
  3. data/.github/workflows/ruby.yml +43 -91
  4. data/.gitignore +7 -6
  5. data/.rubocop.yml +62 -1
  6. data/Gemfile +11 -11
  7. data/README.md +1 -1
  8. data/Rakefile +4 -4
  9. data/TODO +0 -1
  10. data/appveyor.yml +73 -0
  11. data/arel_extensions.gemspec +12 -12
  12. data/gemfiles/rails3.gemfile +10 -10
  13. data/gemfiles/rails4.gemfile +14 -14
  14. data/gemfiles/rails5_0.gemfile +13 -13
  15. data/gemfiles/rails5_1_4.gemfile +13 -13
  16. data/gemfiles/rails5_2.gemfile +15 -14
  17. data/gemfiles/rails6.gemfile +13 -12
  18. data/gemfiles/rails6_1.gemfile +13 -12
  19. data/gemfiles/rails7.gemfile +9 -8
  20. data/gemspecs/arel_extensions-v1.gemspec +12 -12
  21. data/gemspecs/arel_extensions-v2.gemspec +11 -11
  22. data/init/mssql.sql +0 -0
  23. data/init/mysql.sql +0 -0
  24. data/init/oracle.sql +0 -0
  25. data/init/postgresql.sql +0 -0
  26. data/init/sqlite.sql +0 -0
  27. data/lib/arel_extensions/attributes.rb +2 -2
  28. data/lib/arel_extensions/boolean_functions.rb +2 -4
  29. data/lib/arel_extensions/common_sql_functions.rb +12 -12
  30. data/lib/arel_extensions/comparators.rb +14 -14
  31. data/lib/arel_extensions/date_duration.rb +7 -7
  32. data/lib/arel_extensions/helpers.rb +19 -16
  33. data/lib/arel_extensions/insert_manager.rb +1 -1
  34. data/lib/arel_extensions/math.rb +44 -31
  35. data/lib/arel_extensions/math_functions.rb +18 -18
  36. data/lib/arel_extensions/nodes/abs.rb +0 -0
  37. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -0
  38. data/lib/arel_extensions/nodes/blank.rb +1 -1
  39. data/lib/arel_extensions/nodes/case.rb +4 -6
  40. data/lib/arel_extensions/nodes/cast.rb +5 -5
  41. data/lib/arel_extensions/nodes/ceil.rb +0 -0
  42. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  43. data/lib/arel_extensions/nodes/coalesce.rb +1 -1
  44. data/lib/arel_extensions/nodes/collate.rb +9 -9
  45. data/lib/arel_extensions/nodes/concat.rb +2 -2
  46. data/lib/arel_extensions/nodes/date_diff.rb +10 -10
  47. data/lib/arel_extensions/nodes/duration.rb +0 -0
  48. data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
  49. data/lib/arel_extensions/nodes/floor.rb +0 -0
  50. data/lib/arel_extensions/nodes/format.rb +0 -0
  51. data/lib/arel_extensions/nodes/formatted_number.rb +2 -2
  52. data/lib/arel_extensions/nodes/function.rb +21 -21
  53. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  54. data/lib/arel_extensions/nodes/json.rb +7 -7
  55. data/lib/arel_extensions/nodes/length.rb +0 -0
  56. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  57. data/lib/arel_extensions/nodes/locate.rb +1 -1
  58. data/lib/arel_extensions/nodes/log10.rb +0 -0
  59. data/lib/arel_extensions/nodes/matches.rb +1 -1
  60. data/lib/arel_extensions/nodes/md5.rb +0 -0
  61. data/lib/arel_extensions/nodes/power.rb +0 -0
  62. data/lib/arel_extensions/nodes/rand.rb +0 -0
  63. data/lib/arel_extensions/nodes/repeat.rb +2 -2
  64. data/lib/arel_extensions/nodes/replace.rb +2 -2
  65. data/lib/arel_extensions/nodes/round.rb +0 -0
  66. data/lib/arel_extensions/nodes/soundex.rb +2 -2
  67. data/lib/arel_extensions/nodes/std.rb +0 -0
  68. data/lib/arel_extensions/nodes/substring.rb +1 -1
  69. data/lib/arel_extensions/nodes/sum.rb +0 -0
  70. data/lib/arel_extensions/nodes/then.rb +1 -1
  71. data/lib/arel_extensions/nodes/trim.rb +2 -2
  72. data/lib/arel_extensions/nodes/union.rb +4 -4
  73. data/lib/arel_extensions/nodes/union_all.rb +3 -3
  74. data/lib/arel_extensions/nodes/wday.rb +0 -0
  75. data/lib/arel_extensions/nodes.rb +0 -0
  76. data/lib/arel_extensions/null_functions.rb +0 -0
  77. data/lib/arel_extensions/predications.rb +10 -10
  78. data/lib/arel_extensions/railtie.rb +1 -1
  79. data/lib/arel_extensions/set_functions.rb +3 -3
  80. data/lib/arel_extensions/string_functions.rb +8 -8
  81. data/lib/arel_extensions/tasks.rb +2 -2
  82. data/lib/arel_extensions/version.rb +1 -1
  83. data/lib/arel_extensions/visitors/convert_format.rb +0 -0
  84. data/lib/arel_extensions/visitors/ibm_db.rb +20 -20
  85. data/lib/arel_extensions/visitors/mssql.rb +150 -130
  86. data/lib/arel_extensions/visitors/mysql.rb +147 -149
  87. data/lib/arel_extensions/visitors/oracle.rb +141 -135
  88. data/lib/arel_extensions/visitors/oracle12.rb +16 -16
  89. data/lib/arel_extensions/visitors/postgresql.rb +147 -139
  90. data/lib/arel_extensions/visitors/sqlite.rb +85 -87
  91. data/lib/arel_extensions/visitors/to_sql.rb +146 -148
  92. data/lib/arel_extensions/visitors.rb +7 -7
  93. data/lib/arel_extensions.rb +56 -32
  94. data/test/arelx_test_helper.rb +14 -13
  95. data/test/database.yml +5 -5
  96. data/test/real_db_test.rb +81 -81
  97. data/test/support/fake_record.rb +2 -2
  98. data/test/test_comparators.rb +5 -5
  99. data/test/visitors/test_bulk_insert_oracle.rb +5 -5
  100. data/test/visitors/test_bulk_insert_sqlite.rb +5 -5
  101. data/test/visitors/test_bulk_insert_to_sql.rb +5 -5
  102. data/test/visitors/test_oracle.rb +14 -14
  103. data/test/visitors/test_to_sql.rb +87 -87
  104. data/test/with_ar/all_agnostic_test.rb +411 -306
  105. data/test/with_ar/insert_agnostic_test.rb +19 -16
  106. data/test/with_ar/test_bulk_sqlite.rb +5 -5
  107. data/test/with_ar/test_math_sqlite.rb +12 -12
  108. data/test/with_ar/test_string_mysql.rb +20 -20
  109. data/test/with_ar/test_string_sqlite.rb +20 -20
  110. data/version_v1.rb +1 -1
  111. data/version_v2.rb +1 -1
  112. metadata +3 -9
  113. data/.travis/oracle/download.js +0 -152
  114. data/.travis/oracle/download.sh +0 -30
  115. data/.travis/oracle/download_ojdbc.js +0 -116
  116. data/.travis/oracle/install.sh +0 -34
  117. data/.travis/setup_accounts.sh +0 -9
  118. data/.travis/sqlite3/extension-functions.sh +0 -6
  119. data/.travis.yml +0 -193
@@ -8,7 +8,8 @@ module ArelExtensions
8
8
 
9
9
  DATE_FORMAT_DIRECTIVES = { # ISO C / POSIX
10
10
  '%Y' => '%Y', '%C' => '', '%y' => '%y', '%m' => '%m', '%B' => '%M', '%b' => '%b', '%^b' => '%b', # year, month
11
- '%d' => '%d', '%e' => '%e', '%j' => '%j', '%w' => '%w', '%A' => '%W', # day, weekday
11
+ '%V' => '%v', '%G' => '%x', # ISO week number and year of week
12
+ '%d' => '%d', '%e' => '%e', '%j' => '%j', '%w' => '%w', '%a' => '%a', '%A' => '%W', # day, weekday
12
13
  '%H' => '%H', '%k' => '%k', '%I' => '%I', '%l' => '%l', '%P' => '%p', '%p' => '%p', # hours
13
14
  '%M' => '%i', '%S' => '%S', '%L' => '', '%N' => '%f', '%z' => ''
14
15
  }.freeze
@@ -16,22 +17,22 @@ module ArelExtensions
16
17
 
17
18
  # Math functions
18
19
  def visit_ArelExtensions_Nodes_Log10 o, collector
19
- collector << "LOG10("
20
- o.expressions.each_with_index { |arg, i|
21
- collector << Arel::Visitors::ToSql::COMMA if i != 0
22
- collector = visit arg, collector
23
- }
24
- collector << ")"
25
- collector
20
+ collector << 'LOG10('
21
+ o.expressions.each_with_index { |arg, i|
22
+ collector << Arel::Visitors::ToSql::COMMA if i != 0
23
+ collector = visit arg, collector
24
+ }
25
+ collector << ')'
26
+ collector
26
27
  end
27
28
 
28
29
  def visit_ArelExtensions_Nodes_Power o, collector
29
- collector << "POW("
30
+ collector << 'POW('
30
31
  o.expressions.each_with_index { |arg, i|
31
32
  collector << Arel::Visitors::ToSql::COMMA if i != 0
32
33
  collector = visit arg, collector
33
34
  }
34
- collector << ")"
35
+ collector << ')'
35
36
  collector
36
37
  end
37
38
 
@@ -44,10 +45,9 @@ module ArelExtensions
44
45
  collector << ')'
45
46
  if o.escape
46
47
  collector << ' ESCAPE '
47
- visit o.escape, collector
48
- else
49
- collector
48
+ collector = visit o.escape, collector
50
49
  end
50
+ collector
51
51
  end
52
52
 
53
53
  def visit_ArelExtensions_Nodes_AiMatches o, collector
@@ -56,10 +56,9 @@ module ArelExtensions
56
56
  collector = visit o.right.ai_collate, collector
57
57
  if o.escape
58
58
  collector << ' ESCAPE '
59
- visit o.escape, collector
60
- else
61
- collector
59
+ collector = visit o.escape, collector
62
60
  end
61
+ collector
63
62
  end
64
63
 
65
64
  def visit_ArelExtensions_Nodes_AiIMatches o, collector
@@ -68,22 +67,20 @@ module ArelExtensions
68
67
  collector = visit o.right.ai_collate, collector
69
68
  if o.escape
70
69
  collector << ' ESCAPE '
71
- visit o.escape, collector
72
- else
73
- collector
70
+ collector = visit o.escape, collector
74
71
  end
72
+ collector
75
73
  end
76
74
 
77
75
  def visit_ArelExtensions_Nodes_SMatches o, collector
78
- collector = visit o.left.collate, collector
79
- collector << ' LIKE '
80
- collector = visit o.right.collate, collector
81
- if o.escape
82
- collector << ' ESCAPE '
83
- visit o.escape, collector
84
- else
85
- collector
86
- end
76
+ collector = visit o.left.collate, collector
77
+ collector << ' LIKE '
78
+ collector = visit o.right.collate, collector
79
+ if o.escape
80
+ collector << ' ESCAPE '
81
+ collector = visit o.escape, collector
82
+ end
83
+ collector
87
84
  end
88
85
 
89
86
  def visit_ArelExtensions_Nodes_IDoesNotMatch o, collector
@@ -94,10 +91,9 @@ module ArelExtensions
94
91
  collector << ')'
95
92
  if o.escape
96
93
  collector << ' ESCAPE '
97
- visit o.escape, collector
98
- else
99
- collector
94
+ collector = visit o.escape, collector
100
95
  end
96
+ collector
101
97
  end
102
98
 
103
99
  def visit_ArelExtensions_Nodes_Collate o, collector
@@ -105,7 +101,7 @@ module ArelExtensions
105
101
  case o.expressions.first
106
102
  when Arel::Attributes::Attribute
107
103
  case o.option
108
- when 'latin1','utf8'
104
+ when 'latin1', 'utf8'
109
105
  o.option
110
106
  else
111
107
  Arel::Table.engine.connection.charset || 'utf8'
@@ -127,27 +123,27 @@ module ArelExtensions
127
123
  end
128
124
 
129
125
  def visit_ArelExtensions_Nodes_Concat o, collector
130
- collector << "CONCAT("
126
+ collector << 'CONCAT('
131
127
  o.expressions.each_with_index { |arg, i|
132
128
  collector << COMMA if i != 0
133
- if (arg.is_a?(Numeric)) || (arg.is_a?(Arel::Attributes::Attribute))
134
- collector << "CAST("
129
+ if arg.is_a?(Numeric) || arg.is_a?(Arel::Attributes::Attribute)
130
+ collector << 'CAST('
135
131
  collector = visit arg, collector
136
- collector << " AS char)"
132
+ collector << ' AS char)'
137
133
  else
138
134
  collector = visit arg, collector
139
135
  end
140
136
  }
141
- collector << ")"
137
+ collector << ')'
142
138
  collector
143
139
  end
144
140
 
145
141
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
146
- collector << "GROUP_CONCAT("
142
+ collector << 'GROUP_CONCAT('
147
143
  collector = visit o.left, collector
148
144
  if !o.order.blank?
149
145
  collector << ' ORDER BY '
150
- o.order.each_with_index do |order,i|
146
+ o.order.each_with_index do |order, i|
151
147
  collector << Arel::Visitors::ToSql::COMMA if i != 0
152
148
  collector = visit order, collector
153
149
  end
@@ -156,85 +152,85 @@ module ArelExtensions
156
152
  collector << ' SEPARATOR '
157
153
  collector = visit o.separator, collector
158
154
  end
159
- collector << ")"
155
+ collector << ')'
160
156
  collector
161
157
  end
162
158
 
163
159
  def visit_ArelExtensions_Nodes_Trim o, collector
164
- collector << 'TRIM(' # BOTH
165
- collector = visit o.right, collector
166
- collector << " FROM "
167
- collector = visit o.left, collector
168
- collector << ")"
169
- collector
160
+ collector << 'TRIM(' # BOTH
161
+ collector = visit o.right, collector
162
+ collector << ' FROM '
163
+ collector = visit o.left, collector
164
+ collector << ')'
165
+ collector
170
166
  end
171
167
 
172
168
  def visit_ArelExtensions_Nodes_Ltrim o, collector
173
- collector << 'TRIM(LEADING '
174
- collector = visit o.right, collector
175
- collector << " FROM "
176
- collector = visit o.left, collector
177
- collector << ")"
178
- collector
169
+ collector << 'TRIM(LEADING '
170
+ collector = visit o.right, collector
171
+ collector << ' FROM '
172
+ collector = visit o.left, collector
173
+ collector << ')'
174
+ collector
179
175
  end
180
176
 
181
177
  def visit_ArelExtensions_Nodes_Rtrim o, collector
182
178
  collector << 'TRIM(TRAILING '
183
179
  collector = visit o.right, collector
184
- collector << " FROM "
180
+ collector << ' FROM '
185
181
  collector = visit o.left, collector
186
- collector << ")"
182
+ collector << ')'
187
183
  collector
188
184
  end
189
185
 
190
186
  def visit_ArelExtensions_Nodes_Repeat o, collector
191
- collector << "REPEAT("
187
+ collector << 'REPEAT('
192
188
  o.expressions.each_with_index { |arg, i|
193
189
  collector << Arel::Visitors::ToSql::COMMA if i != 0
194
190
  collector = visit arg, collector
195
191
  }
196
- collector << ")"
192
+ collector << ')'
197
193
  collector
198
194
  end
199
195
 
200
196
  def visit_ArelExtensions_Nodes_RegexpReplace o, collector
201
197
  if !regexp_replace_supported?
202
- warn("Warning : ArelExtensions: REGEXP_REPLACE does not seem to be available in the current version of the DBMS, it might crash")
198
+ warn('Warning: ArelExtensions: REGEXP_REPLACE does not seem to be available in the current version of the DBMS, it might crash')
203
199
  end
204
- super(o,collector)
200
+ super(o, collector)
205
201
  end
206
202
 
207
203
  def visit_ArelExtensions_Nodes_Format o, collector
208
204
  case o.col_type
209
205
  when :date, :datetime, :time
210
206
  fmt = ArelExtensions::Visitors::strftime_to_format(o.iso_format, DATE_FORMAT_DIRECTIVES)
211
- collector << "DATE_FORMAT("
212
- collector << "CONVERT_TZ(" if o.time_zone
207
+ collector << 'DATE_FORMAT('
208
+ collector << 'CONVERT_TZ(' if o.time_zone
213
209
  collector = visit o.left, collector
214
210
  case o.time_zone
215
211
  when Hash
216
212
  src_tz, dst_tz = o.time_zone.first
217
213
  collector << COMMA
218
- collector = visit Arel::Nodes.build_quoted(src_tz), collector
214
+ collector = visit Arel.quoted(src_tz), collector
219
215
  collector << COMMA
220
- collector = visit Arel::Nodes.build_quoted(dst_tz), collector
216
+ collector = visit Arel.quoted(dst_tz), collector
221
217
  collector << ')'
222
218
  when String
223
219
  collector << COMMA << "'UTC'" << COMMA
224
- collector = visit Arel::Nodes.build_quoted(o.time_zone), collector
220
+ collector = visit Arel.quoted(o.time_zone), collector
225
221
  collector << ')'
226
222
  end
227
223
  collector << COMMA
228
- collector = visit Arel::Nodes.build_quoted(fmt), collector
229
- collector << ")"
224
+ collector = visit Arel.quoted(fmt), collector
225
+ collector << ')'
230
226
  when :integer, :float, :decimal
231
- collector << "FORMAT("
227
+ collector << 'FORMAT('
232
228
  collector = visit o.left, collector
233
229
  collector << Arel::Visitors::ToSql::COMMA
234
230
  collector << '2'
235
231
  collector << Arel::Visitors::ToSql::COMMA
236
232
  collector = visit o.right, collector
237
- collector << ")"
233
+ collector << ')'
238
234
  else
239
235
  collector = visit o.left, collector
240
236
  end
@@ -252,7 +248,7 @@ module ArelExtensions
252
248
  collector = visit o.right, collector
253
249
  collector << COMMA
254
250
  collector = visit o.left, collector
255
- collector << ")"
251
+ collector << ')'
256
252
  else
257
253
  collector << '('
258
254
  collector = visit o.left, collector
@@ -272,81 +268,79 @@ module ArelExtensions
272
268
  end
273
269
 
274
270
  def visit_ArelExtensions_Nodes_DateAdd o, collector
275
- collector << "DATE_ADD("
271
+ collector << 'DATE_ADD('
276
272
  collector = visit o.left, collector
277
273
  collector << COMMA
278
274
  collector = visit o.mysql_value(o.right), collector
279
- collector << ")"
275
+ collector << ')'
280
276
  collector
281
277
  end
282
278
 
283
279
  def visit_ArelExtensions_Nodes_Duration o, collector
284
280
  if o.left == 'wd'
285
- collector << "(WEEKDAY("
281
+ collector << '(WEEKDAY('
286
282
  collector = visit o.right, collector
287
- collector << ") + 1) % 7"
283
+ collector << ') + 1) % 7'
288
284
  else
289
285
  if o.with_interval
290
- case o.left
291
- when 'd','m','y'
292
- interval = 'DAY'
293
- when 'h','mn','s'
294
- interval = 'SECOND'
295
- when /i\z/
296
- interval = DATE_MAPPING[o.left[0..-2]]
297
- else
298
- interval = nil
299
- end
286
+ interval =
287
+ case o.left
288
+ when 'd', 'm', 'y'
289
+ 'DAY'
290
+ when 'h', 'mn', 's'
291
+ 'SECOND'
292
+ when /i\z/
293
+ DATE_MAPPING[o.left[0..-2]]
294
+ end
300
295
  end
301
- collector << " INTERVAL " if o.with_interval && interval
296
+ collector << ' INTERVAL ' if o.with_interval && interval
302
297
  collector << "#{DATE_MAPPING[o.left]}("
303
298
  collector = visit o.right, collector
304
- collector << ")"
299
+ collector << ')'
305
300
  collector << " #{interval} " if o.with_interval && interval
306
301
  end
307
302
  collector
308
303
  end
309
304
 
310
305
  def visit_ArelExtensions_Nodes_IsNull o, collector
311
- collector << "ISNULL("
306
+ collector << 'ISNULL('
312
307
  collector = visit o.expr, collector
313
- collector << ")"
308
+ collector << ')'
314
309
  collector
315
310
  end
316
311
 
317
312
  def visit_ArelExtensions_Nodes_IsNotNull o, collector
318
- collector << "NOT ISNULL("
313
+ collector << 'NOT ISNULL('
319
314
  collector = visit o.expr, collector
320
- collector << ")"
315
+ collector << ')'
321
316
  collector
322
317
  end
323
318
 
324
319
  def visit_ArelExtensions_Nodes_Wday o, collector
325
- collector << "(WEEKDAY("
320
+ collector << '(WEEKDAY('
326
321
  collector = visit o.date, collector
327
- collector << ") + 1) % 7"
322
+ collector << ') + 1) % 7'
328
323
  collector
329
324
  end
330
325
 
331
326
  def visit_ArelExtensions_Nodes_Cast o, collector
332
- collector << "CAST("
333
- collector = visit o.left, collector
334
- collector << " AS "
335
327
  as_attr =
336
- Arel::Nodes::SqlLiteral.new(
337
- case o.as_attr
338
- when :string then 'char'
339
- when :time then 'time'
340
- when :int then 'signed'
341
- when :number, :decimal then 'decimal(20,6)'
342
- when :datetime then 'datetime'
343
- when :date then 'date'
344
- when :binary then 'binary'
345
- else o.as_attr.to_s
346
- end
347
- )
348
- collector = visit as_attr, collector
349
- collector << ")"
328
+ case o.as_attr
329
+ when :binary then 'binary'
330
+ when :date then 'date'
331
+ when :datetime then 'datetime'
332
+ when :int then 'signed'
333
+ when :number, :decimal then 'decimal(20,6)'
334
+ when :string then 'char'
335
+ when :time then 'time'
336
+ else o.as_attr.to_s
337
+ end
338
+
339
+ collector << 'CAST('
340
+ collector = visit o.left, collector
341
+ collector << ' AS '
342
+ collector = visit Arel::Nodes::SqlLiteral.new(as_attr), collector
343
+ collector << ')'
350
344
  collector
351
345
  end
352
346
 
@@ -356,7 +350,7 @@ module ArelExtensions
356
350
  o = o.dup
357
351
  o.orders = []
358
352
  end
359
- old_visit_Arel_Nodes_SelectStatement(o,collector)
353
+ old_visit_Arel_Nodes_SelectStatement(o, collector)
360
354
  end
361
355
 
362
356
  alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
@@ -368,7 +362,7 @@ module ArelExtensions
368
362
  else
369
363
  collector = visit o.left, collector
370
364
  end
371
- collector << " AS "
365
+ collector << ' AS '
372
366
 
373
367
  # sometimes these values are already quoted, if they are, don't double quote it
374
368
  quote = o.right.is_a?(Arel::Nodes::SqlLiteral) && o.right[0] != '`' && o.right[-1] != '`'
@@ -378,13 +372,12 @@ module ArelExtensions
378
372
  collector << '`' if quote
379
373
 
380
374
  collector
381
- collector
382
375
  end
383
376
 
384
377
  def visit_ArelExtensions_Nodes_FormattedNumber o, collector
385
378
  col = o.left.coalesce(0)
386
- params = o.locale ? [o.precision,Arel::Nodes.build_quoted(o.locale)] : [o.precision]
387
- sign = ArelExtensions::Nodes::Case.new.when(col<0).
379
+ params = o.locale ? [o.precision, Arel.quoted(o.locale)] : [o.precision]
380
+ sign = Arel.when(col < 0).
388
381
  then('-').
389
382
  else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
390
383
  sign_length = ArelExtensions::Nodes::Length.new([sign])
@@ -392,28 +385,33 @@ module ArelExtensions
392
385
  number =
393
386
  if o.scientific_notation
394
387
  ArelExtensions::Nodes::Concat.new([
395
- Arel::Nodes::NamedFunction.new('FORMAT',[
396
- col.abs/Arel::Nodes.build_quoted(10).pow(col.abs.log10.floor)
397
- ]+params),
388
+ Arel::Nodes::NamedFunction.new('FORMAT', [
389
+ col.abs / Arel.quoted(10).pow(col.abs.log10.floor)
390
+ ] + params),
398
391
  o.type,
399
- Arel::Nodes::NamedFunction.new('FORMAT',[
392
+ Arel::Nodes::NamedFunction.new('FORMAT', [
400
393
  col.abs.log10.floor,
401
394
  0
402
395
  ])
403
396
  ])
404
397
  else
405
- Arel::Nodes::NamedFunction.new('FORMAT',[col.abs]+params)
398
+ Arel::Nodes::NamedFunction.new('FORMAT', [col.abs] + params)
406
399
  end
407
400
 
408
- repeated_char = (o.width == 0) ? Arel::Nodes.build_quoted('') : ArelExtensions::Nodes::Case.new().
409
- when(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length)>0).
410
- then(Arel::Nodes.build_quoted(
411
- o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
412
- ).repeat(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length))
413
- ).
414
- else('')
415
- before = (!o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
416
- middle = (o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
401
+ repeated_char =
402
+ if o.width == 0
403
+ Arel.quoted('')
404
+ else
405
+ Arel
406
+ .when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0)
407
+ .then(Arel.quoted(
408
+ o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
409
+ ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
410
+ )
411
+ .else('')
412
+ end
413
+ before = !o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
414
+ middle = o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
417
415
  after = o.flags.include?('-') ? repeated_char : ''
418
416
  full_number = ArelExtensions::Nodes::Concat.new([
419
417
  before,
@@ -422,45 +420,45 @@ module ArelExtensions
422
420
  number,
423
421
  after
424
422
  ])
425
- collector = visit ArelExtensions::Nodes::Concat.new([Arel::Nodes.build_quoted(o.prefix),full_number,Arel::Nodes.build_quoted(o.suffix)]), collector
423
+ collector = visit ArelExtensions::Nodes::Concat.new([Arel.quoted(o.prefix), full_number, Arel.quoted(o.suffix)]), collector
426
424
  collector
427
425
  end
428
426
 
429
427
  def visit_Aggregate_For_AggregateFunction o, collector
430
428
  if !window_supported?
431
- warn("Warning : ArelExtensions: Window Functions are not available in the current version of the DBMS.")
432
- return collector
429
+ warn('Warning: ArelExtensions: Window Functions are not available in the current version of the DBMS.')
430
+ return collector
433
431
  end
434
432
 
435
433
  if !o.order.empty? || !o.group.empty?
436
- collector << " OVER ("
434
+ collector << ' OVER ('
437
435
  if !o.group.empty?
438
- collector << " PARTITION BY ("
436
+ collector << ' PARTITION BY ('
439
437
  visit o.group, collector
440
- collector << ")"
438
+ collector << ')'
441
439
  end
442
440
  if !o.order.empty?
443
- collector << " ORDER BY ("
441
+ collector << ' ORDER BY ('
444
442
  visit o.order, collector
445
- collector << ")"
443
+ collector << ')'
446
444
  end
447
- collector << ")"
445
+ collector << ')'
448
446
  end
449
447
  collector
450
448
  end
451
449
 
452
450
  def visit_ArelExtensions_Nodes_Std o, collector
453
- collector << (o.unbiased_estimator ? "STDDEV_SAMP(" : "STDDEV_POP(")
451
+ collector << (o.unbiased_estimator ? 'STDDEV_SAMP(' : 'STDDEV_POP(')
454
452
  visit o.left, collector
455
- collector << ")"
453
+ collector << ')'
456
454
  visit_Aggregate_For_AggregateFunction o, collector
457
455
  collector
458
456
  end
459
457
 
460
458
  def visit_ArelExtensions_Nodes_Variance o, collector
461
- collector << (o.unbiased_estimator ? "VAR_SAMP(" : "VAR_POP(")
459
+ collector << (o.unbiased_estimator ? 'VAR_SAMP(' : 'VAR_POP(')
462
460
  visit o.left, collector
463
- collector << ")"
461
+ collector << ')'
464
462
  visit_Aggregate_For_AggregateFunction o, collector
465
463
  collector
466
464
  end
@@ -492,13 +490,13 @@ module ArelExtensions
492
490
  # corresponding mysql version of the current mariadb version (which is not very helpful most of the time)
493
491
  end
494
492
 
495
- def visit_ArelExtensions_Nodes_Json o,collector
493
+ def visit_ArelExtensions_Nodes_Json o, collector
496
494
  return super if !json_supported?
497
495
 
498
496
  case o.dict
499
497
  when Array
500
498
  collector << 'JSON_ARRAY('
501
- o.dict.each.with_index do |v,i|
499
+ o.dict.each.with_index do |v, i|
502
500
  if i != 0
503
501
  collector << COMMA
504
502
  end
@@ -507,7 +505,7 @@ module ArelExtensions
507
505
  collector << ')'
508
506
  when Hash
509
507
  collector << 'JSON_OBJECT('
510
- o.dict.each.with_index do |(k,v),i|
508
+ o.dict.each.with_index do |(k, v), i|
511
509
  if i != 0
512
510
  collector << COMMA
513
511
  end
@@ -522,9 +520,9 @@ module ArelExtensions
522
520
  collector
523
521
  end
524
522
 
525
- def visit_ArelExtensions_Nodes_JsonMerge o,collector
523
+ def visit_ArelExtensions_Nodes_JsonMerge o, collector
526
524
  collector << 'JSON_MERGE_PATCH('
527
- o.expressions.each.with_index do |v,i|
525
+ o.expressions.each.with_index do |v, i|
528
526
  if i != 0
529
527
  collector << COMMA
530
528
  end
@@ -534,27 +532,27 @@ module ArelExtensions
534
532
  collector
535
533
  end
536
534
 
537
- def visit_ArelExtensions_Nodes_JsonGet o,collector
535
+ def visit_ArelExtensions_Nodes_JsonGet o, collector
538
536
  collector << 'JSON_EXTRACT('
539
537
  collector = visit o.dict, collector
540
538
  collector << COMMA
541
539
  if o.key.is_a?(Integer)
542
540
  collector << "\"$[#{o.key}]\""
543
541
  else
544
- collector = visit Arel::Nodes.build_quoted('$.')+o.key, collector
542
+ collector = visit Arel.quoted('$.') + o.key, collector
545
543
  end
546
544
  collector << ')'
547
545
  collector
548
546
  end
549
547
 
550
- def visit_ArelExtensions_Nodes_JsonSet o,collector
548
+ def visit_ArelExtensions_Nodes_JsonSet o, collector
551
549
  collector << 'JSON_SET('
552
550
  collector = visit o.dict, collector
553
551
  collector << COMMA
554
552
  if o.key.is_a?(Integer)
555
553
  collector << "\"$[#{o.key}]\""
556
554
  else
557
- collector = visit Arel::Nodes.build_quoted('$.')+o.key, collector
555
+ collector = visit Arel.quoted('$.') + o.key, collector
558
556
  end
559
557
  collector << COMMA
560
558
  collector = visit o.value, collector
@@ -573,7 +571,7 @@ module ArelExtensions
573
571
  case o.dict
574
572
  when Hash
575
573
  collector << 'JSON_MERGE_PATCH(' if o.dict.length > 1
576
- o.dict.each.with_index do |(k,v),i|
574
+ o.dict.each.with_index do |(k, v), i|
577
575
  if i != 0
578
576
  collector << COMMA
579
577
  end