arel_extensions 1.3.1 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -2
  3. data/.github/workflows/ruby.yml +4 -4
  4. data/.rubocop.yml +25 -1
  5. data/Gemfile +10 -10
  6. data/README.md +24 -4
  7. data/Rakefile +4 -4
  8. data/TODO +0 -1
  9. data/arel_extensions.gemspec +12 -12
  10. data/gemfiles/rails3.gemfile +10 -10
  11. data/gemfiles/rails4.gemfile +13 -13
  12. data/gemfiles/rails5_0.gemfile +12 -12
  13. data/gemfiles/rails5_1_4.gemfile +12 -12
  14. data/gemfiles/rails5_2.gemfile +13 -13
  15. data/gemfiles/rails6.gemfile +11 -11
  16. data/gemfiles/rails6_1.gemfile +11 -11
  17. data/gemfiles/rails7.gemfile +7 -7
  18. data/gemspecs/arel_extensions-v1.gemspec +12 -12
  19. data/gemspecs/arel_extensions-v2.gemspec +11 -11
  20. data/init/mssql.sql +0 -0
  21. data/init/mysql.sql +0 -0
  22. data/init/oracle.sql +0 -0
  23. data/init/postgresql.sql +0 -0
  24. data/init/sqlite.sql +0 -0
  25. data/lib/arel_extensions/attributes.rb +2 -2
  26. data/lib/arel_extensions/boolean_functions.rb +2 -4
  27. data/lib/arel_extensions/common_sql_functions.rb +10 -10
  28. data/lib/arel_extensions/comparators.rb +14 -14
  29. data/lib/arel_extensions/date_duration.rb +7 -7
  30. data/lib/arel_extensions/helpers.rb +16 -13
  31. data/lib/arel_extensions/insert_manager.rb +1 -1
  32. data/lib/arel_extensions/math.rb +16 -18
  33. data/lib/arel_extensions/math_functions.rb +18 -18
  34. data/lib/arel_extensions/nodes/abs.rb +0 -0
  35. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -0
  36. data/lib/arel_extensions/nodes/blank.rb +1 -1
  37. data/lib/arel_extensions/nodes/case.rb +4 -6
  38. data/lib/arel_extensions/nodes/cast.rb +3 -3
  39. data/lib/arel_extensions/nodes/ceil.rb +0 -0
  40. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  41. data/lib/arel_extensions/nodes/coalesce.rb +0 -0
  42. data/lib/arel_extensions/nodes/collate.rb +9 -9
  43. data/lib/arel_extensions/nodes/concat.rb +2 -2
  44. data/lib/arel_extensions/nodes/date_diff.rb +6 -6
  45. data/lib/arel_extensions/nodes/duration.rb +0 -0
  46. data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
  47. data/lib/arel_extensions/nodes/floor.rb +0 -0
  48. data/lib/arel_extensions/nodes/format.rb +1 -1
  49. data/lib/arel_extensions/nodes/formatted_number.rb +2 -2
  50. data/lib/arel_extensions/nodes/function.rb +21 -21
  51. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  52. data/lib/arel_extensions/nodes/json.rb +7 -7
  53. data/lib/arel_extensions/nodes/length.rb +0 -0
  54. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  55. data/lib/arel_extensions/nodes/locate.rb +0 -0
  56. data/lib/arel_extensions/nodes/log10.rb +0 -0
  57. data/lib/arel_extensions/nodes/matches.rb +1 -1
  58. data/lib/arel_extensions/nodes/md5.rb +0 -0
  59. data/lib/arel_extensions/nodes/power.rb +0 -0
  60. data/lib/arel_extensions/nodes/rand.rb +0 -0
  61. data/lib/arel_extensions/nodes/repeat.rb +0 -0
  62. data/lib/arel_extensions/nodes/replace.rb +2 -2
  63. data/lib/arel_extensions/nodes/round.rb +0 -0
  64. data/lib/arel_extensions/nodes/soundex.rb +2 -2
  65. data/lib/arel_extensions/nodes/std.rb +0 -0
  66. data/lib/arel_extensions/nodes/substring.rb +0 -0
  67. data/lib/arel_extensions/nodes/sum.rb +0 -0
  68. data/lib/arel_extensions/nodes/then.rb +0 -0
  69. data/lib/arel_extensions/nodes/trim.rb +0 -0
  70. data/lib/arel_extensions/nodes/union.rb +4 -4
  71. data/lib/arel_extensions/nodes/union_all.rb +3 -3
  72. data/lib/arel_extensions/nodes/wday.rb +0 -0
  73. data/lib/arel_extensions/nodes.rb +0 -0
  74. data/lib/arel_extensions/null_functions.rb +0 -0
  75. data/lib/arel_extensions/predications.rb +10 -10
  76. data/lib/arel_extensions/railtie.rb +1 -1
  77. data/lib/arel_extensions/set_functions.rb +3 -3
  78. data/lib/arel_extensions/string_functions.rb +8 -8
  79. data/lib/arel_extensions/tasks.rb +2 -2
  80. data/lib/arel_extensions/version.rb +1 -1
  81. data/lib/arel_extensions/visitors/convert_format.rb +0 -0
  82. data/lib/arel_extensions/visitors/ibm_db.rb +19 -19
  83. data/lib/arel_extensions/visitors/mssql.rb +139 -118
  84. data/lib/arel_extensions/visitors/mysql.rb +145 -144
  85. data/lib/arel_extensions/visitors/oracle.rb +136 -128
  86. data/lib/arel_extensions/visitors/oracle12.rb +16 -16
  87. data/lib/arel_extensions/visitors/postgresql.rb +147 -136
  88. data/lib/arel_extensions/visitors/sqlite.rb +83 -85
  89. data/lib/arel_extensions/visitors/to_sql.rb +143 -148
  90. data/lib/arel_extensions/visitors.rb +7 -7
  91. data/lib/arel_extensions.rb +46 -32
  92. data/test/arelx_test_helper.rb +14 -14
  93. data/test/database.yml +5 -5
  94. data/test/real_db_test.rb +78 -78
  95. data/test/support/fake_record.rb +1 -1
  96. data/test/test_comparators.rb +5 -5
  97. data/test/visitors/test_bulk_insert_oracle.rb +4 -4
  98. data/test/visitors/test_bulk_insert_sqlite.rb +4 -4
  99. data/test/visitors/test_bulk_insert_to_sql.rb +4 -4
  100. data/test/visitors/test_oracle.rb +14 -14
  101. data/test/visitors/test_to_sql.rb +82 -82
  102. data/test/with_ar/all_agnostic_test.rb +415 -313
  103. data/test/with_ar/insert_agnostic_test.rb +17 -14
  104. data/test/with_ar/test_bulk_sqlite.rb +4 -4
  105. data/test/with_ar/test_math_sqlite.rb +12 -12
  106. data/test/with_ar/test_string_mysql.rb +20 -20
  107. data/test/with_ar/test_string_sqlite.rb +20 -20
  108. data/version_v1.rb +1 -1
  109. data/version_v2.rb +1 -1
  110. metadata +2 -9
  111. data/.travis/oracle/download.js +0 -152
  112. data/.travis/oracle/download.sh +0 -30
  113. data/.travis/oracle/download_ojdbc.js +0 -116
  114. data/.travis/oracle/install.sh +0 -34
  115. data/.travis/setup_accounts.sh +0 -9
  116. data/.travis/sqlite3/extension-functions.sh +0 -6
  117. data/.travis.yml +0 -193
@@ -6,30 +6,31 @@ module ArelExtensions
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
8
  '%Y' => 'YYYY', '%C' => 'CC', '%y' => 'YY', '%m' => 'MM', '%B' => 'Month', '%^B' => 'MONTH', '%b' => 'Mon', '%^b' => 'MON',
9
- '%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%A' => 'Day', # day, weekday
9
+ '%V' => 'IW', '%G' => 'IYYY', # ISO week number and year of week
10
+ '%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%a' => 'Dy', '%A' => 'Day', # day, weekday
10
11
  '%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
11
12
  '%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz' # seconds, subseconds
12
13
  }
13
14
  NUMBER_COMMA_MAPPING = { 'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', ' }
14
15
 
15
16
  def visit_ArelExtensions_Nodes_Log10 o, collector
16
- collector << "LOG("
17
- o.expressions.each_with_index { |arg, i|
18
- collector << Arel::Visitors::ToSql::COMMA if i != 0
19
- collector = visit arg, collector
20
- }
21
- collector << ",10)"
22
- collector
17
+ collector << 'LOG('
18
+ o.expressions.each_with_index { |arg, i|
19
+ collector << Arel::Visitors::ToSql::COMMA if i != 0
20
+ collector = visit arg, collector
21
+ }
22
+ collector << ',10)'
23
+ collector
23
24
  end
24
25
 
25
26
  def visit_ArelExtensions_Nodes_Power o, collector
26
- collector << "POWER("
27
- o.expressions.each_with_index { |arg, i|
28
- collector << Arel::Visitors::ToSql::COMMA if i != 0
29
- collector = visit arg, collector
30
- }
31
- collector << ")"
32
- collector
27
+ collector << 'POWER('
28
+ o.expressions.each_with_index { |arg, i|
29
+ collector << Arel::Visitors::ToSql::COMMA if i != 0
30
+ collector = visit arg, collector
31
+ }
32
+ collector << ')'
33
+ collector
33
34
  end
34
35
 
35
36
  def visit_ArelExtensions_Nodes_Concat o, collector
@@ -107,54 +108,54 @@ module ArelExtensions
107
108
  end
108
109
 
109
110
  def visit_ArelExtensions_Nodes_Collate o, collector
110
- if o.ai
111
- collector << "NLSSORT("
112
- collector = visit o.expressions.first, collector
113
- collector << COMMA
114
- collector << "'NLS_SORT = BINARY_AI NLS_COMP = LINGUISTIC'"
115
- collector << ")"
116
- elsif o.ci
117
- collector << "NLSSORT("
118
- collector = visit o.expressions.first, collector
119
- collector << COMMA
120
- collector << "'NLS_SORT = BINARY_CI NLS_COMP = LINGUISTIC'"
121
- collector << ")"
122
- else
123
- collector = visit o.expressions.first, collector
124
- end
111
+ if o.ai
112
+ collector << 'NLSSORT('
113
+ collector = visit o.expressions.first, collector
114
+ collector << COMMA
115
+ collector << "'NLS_SORT = BINARY_AI NLS_COMP = LINGUISTIC'"
116
+ collector << ')'
117
+ elsif o.ci
118
+ collector << 'NLSSORT('
119
+ collector = visit o.expressions.first, collector
120
+ collector << COMMA
121
+ collector << "'NLS_SORT = BINARY_CI NLS_COMP = LINGUISTIC'"
122
+ collector << ')'
123
+ else
124
+ collector = visit o.expressions.first, collector
125
+ end
125
126
  collector
126
127
  end
127
128
 
128
129
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
129
- collector << "(LISTAGG("
130
+ collector << '(LISTAGG('
130
131
  collector = visit o.left, collector
131
132
  collector << COMMA
132
133
  collector =
133
134
  if o.separator && o.separator != 'NULL'
134
135
  visit o.separator, collector
135
136
  else
136
- visit Arel::Nodes.build_quoted(','), collector
137
+ visit Arel.quoted(','), collector
137
138
  end
138
- collector << ") WITHIN GROUP (ORDER BY "
139
+ collector << ') WITHIN GROUP (ORDER BY '
139
140
  if !o.order.blank?
140
- o.order.each_with_index do |order,i|
141
+ o.order.each_with_index do |order, i|
141
142
  collector << COMMA if i != 0
142
143
  collector = visit order, collector
143
144
  end
144
145
  else
145
146
  collector = visit o.left, collector
146
147
  end
147
- collector << "))"
148
+ collector << '))'
148
149
  collector
149
150
  end
150
151
 
151
152
  def visit_ArelExtensions_Nodes_Coalesce o, collector
152
- collector << "COALESCE("
153
+ collector << 'COALESCE('
153
154
  o.expressions.each_with_index { |arg, i|
154
155
  collector << COMMA if i != 0
155
156
  if i > 0 && o.left_node_type == :text
156
157
  if arg == '' || (arg.is_a?(Arel::Nodes::Quoted) && (arg.expr == ''))
157
- collector << "NULL"
158
+ collector << 'NULL'
158
159
  else
159
160
  collector << 'TO_CLOB('
160
161
  collector = visit arg, collector
@@ -164,12 +165,12 @@ module ArelExtensions
164
165
  collector = visit arg, collector
165
166
  end
166
167
  }
167
- collector << ")"
168
+ collector << ')'
168
169
  collector
169
170
  end
170
171
 
171
172
  def visit_ArelExtensions_Nodes_MD5 o, collector
172
- collector << "LOWER (RAWTOHEX (DBMS_OBFUSCATION_TOOLKIT.md5(input => UTL_I18N.STRING_TO_RAW("
173
+ collector << 'LOWER (RAWTOHEX (DBMS_OBFUSCATION_TOOLKIT.md5(input => UTL_I18N.STRING_TO_RAW('
173
174
  collector = visit o.left, collector
174
175
  collector << ", 'AL32UTF8'))))"
175
176
  collector
@@ -184,7 +185,7 @@ module ArelExtensions
184
185
  collector << 'TO_DATE(' if lc
185
186
  collector = visit o.left, collector
186
187
  collector << ')' if lc
187
- collector << " - "
188
+ collector << ' - '
188
189
  collector << 'TO_DATE(' if rc
189
190
  collector = visit o.right, collector
190
191
  collector << ')' if rc
@@ -218,16 +219,16 @@ module ArelExtensions
218
219
  def visit_ArelExtensions_Nodes_Duration o, collector
219
220
  case o.left
220
221
  when 'wd', 'w'
221
- collector << "TO_CHAR("
222
+ collector << 'TO_CHAR('
222
223
  collector = visit o.right, collector
223
224
  collector << COMMA
224
- collector = visit Arel::Nodes.build_quoted(DATE_MAPPING[o.left]), collector
225
+ collector = visit Arel.quoted(DATE_MAPPING[o.left]), collector
225
226
  else
226
227
  right = case o.left
227
- when 'd','m','y'
228
+ when 'd', 'm', 'y'
228
229
  interval = 'DAY'
229
230
  o.right.cast(:date)
230
- when 'h','mn','s'
231
+ when 'h', 'mn', 's'
231
232
  interval = 'SECOND'
232
233
  o.right.cast(:datetime)
233
234
  when /i\z/
@@ -243,7 +244,7 @@ module ArelExtensions
243
244
  collector << "EXTRACT(#{DATE_MAPPING[o.left]} FROM "
244
245
  collector = visit right, collector
245
246
  end
246
- collector << ")"
247
+ collector << ')'
247
248
  collector << " * (INTERVAL '1' #{interval})" if interval && o.with_interval
248
249
  collector
249
250
  end
@@ -251,45 +252,45 @@ module ArelExtensions
251
252
  def visit_ArelExtensions_Nodes_Cast o, collector
252
253
  case o.as_attr
253
254
  when :string
254
- collector << "TO_CHAR("
255
+ collector << 'TO_CHAR('
255
256
  collector = visit o.left, collector
256
- collector << ")"
257
+ collector << ')'
257
258
  return collector
258
259
  when :text
259
- collector << "TO_CLOB("
260
+ collector << 'TO_CLOB('
260
261
  collector = visit o.left, collector
261
- collector << ")"
262
+ collector << ')'
262
263
  return collector
263
264
  when :ntext
264
- collector << "TO_NCLOB("
265
+ collector << 'TO_NCLOB('
265
266
  collector = visit o.left, collector
266
- collector << ")"
267
+ collector << ')'
267
268
  return collector
268
269
  when :time
269
270
  if (o.left.respond_to?(:return_type) && o.left.return_type == :string) || o.left.is_a?(Arel::Nodes::Quoted)
270
- collector << "TO_DATE("
271
+ collector << 'TO_DATE('
271
272
  collector = visit o.left, collector
272
273
  collector << ",'HH24:MI:SS')"
273
274
  else
274
- collector << "TO_DATE(TO_CHAR("
275
+ collector << 'TO_DATE(TO_CHAR('
275
276
  collector = visit o.left, collector
276
277
  collector << ",'HH24:MI:SS'),'HH24:MI:SS')"
277
278
  end
278
279
  return collector
279
280
  when :number, :decimal
280
- collector << "TO_NUMBER("
281
+ collector << 'TO_NUMBER('
281
282
  collector = visit o.left, collector
282
- collector << ")"
283
+ collector << ')'
283
284
  return collector
284
285
  when :datetime
285
286
  as_attr = Arel::Nodes::SqlLiteral.new('timestamp')
286
287
  when :date
287
288
  if (o.left.respond_to?(:return_type) && o.left.return_type == :string) || o.left.is_a?(Arel::Nodes::Quoted)
288
- collector << "TO_DATE("
289
+ collector << 'TO_DATE('
289
290
  collector = visit o.left, collector
290
291
  collector << ",'YYYY-MM-DD')"
291
292
  else
292
- collector << "TO_DATE(TO_CHAR("
293
+ collector << 'TO_DATE(TO_CHAR('
293
294
  collector = visit o.left, collector
294
295
  collector << ",'YYYY-MM-DD'),'YYYY-MM-DD')"
295
296
  end
@@ -299,18 +300,18 @@ module ArelExtensions
299
300
  else
300
301
  as_attr = Arel::Nodes::SqlLiteral.new(o.as_attr.to_s)
301
302
  end
302
- collector << "CAST("
303
+ collector << 'CAST('
303
304
  collector = visit o.left, collector
304
- collector << " AS "
305
+ collector << ' AS '
305
306
  collector = visit as_attr, collector
306
- collector << ")"
307
+ collector << ')'
307
308
  collector
308
309
  end
309
310
 
310
311
  def visit_ArelExtensions_Nodes_Length o, collector
311
312
  collector << "LENGTH#{o.bytewise ? 'B' : ''}("
312
313
  collector = visit o.expr, collector
313
- collector << ")"
314
+ collector << ')'
314
315
  collector
315
316
  end
316
317
 
@@ -327,18 +328,18 @@ module ArelExtensions
327
328
  end
328
329
 
329
330
  def visit_ArelExtensions_Nodes_Rand o, collector
330
- collector << "DBMS_RANDOM.VALUE("
331
+ collector << 'DBMS_RANDOM.VALUE('
331
332
  if o.left && o.right
332
333
  collector = visit o.left, collector
333
334
  collector << COMMA
334
335
  collector = visit o.right, collector
335
336
  end
336
- collector << ")"
337
+ collector << ')'
337
338
  collector
338
339
  end
339
340
 
340
341
  def visit_Arel_Nodes_Regexp o, collector
341
- collector << " REGEXP_LIKE("
342
+ collector << ' REGEXP_LIKE('
342
343
  collector = visit o.left, collector
343
344
  collector << COMMA
344
345
  collector = visit o.right, collector
@@ -347,7 +348,7 @@ module ArelExtensions
347
348
  end
348
349
 
349
350
  def visit_Arel_Nodes_NotRegexp o, collector
350
- collector << " NOT REGEXP_LIKE("
351
+ collector << ' NOT REGEXP_LIKE('
351
352
  collector = visit o.left, collector
352
353
  collector << COMMA
353
354
  collector = visit o.right, collector
@@ -356,22 +357,22 @@ module ArelExtensions
356
357
  end
357
358
 
358
359
  def visit_ArelExtensions_Nodes_Locate o, collector
359
- collector << "INSTR("
360
+ collector << 'INSTR('
360
361
  o.expressions.each_with_index { |arg, i|
361
362
  collector << COMMA if i != 0
362
363
  collector = visit arg, collector
363
364
  }
364
- collector << ")"
365
+ collector << ')'
365
366
  collector
366
367
  end
367
368
 
368
369
  def visit_ArelExtensions_Nodes_Substring o, collector
369
- collector << "SUBSTR("
370
+ collector << 'SUBSTR('
370
371
  o.expressions.each_with_index { |arg, i|
371
372
  collector << COMMA if i != 0
372
373
  collector = visit arg, collector
373
374
  }
374
- collector << ")"
375
+ collector << ')'
375
376
  collector
376
377
  end
377
378
 
@@ -390,14 +391,14 @@ module ArelExtensions
390
391
  collector << COMMA
391
392
  collector << 'COALESCE(dbms_lob.GETLENGTH('
392
393
  collector = visit o.left, collector
393
- collector << "), 0)"
394
+ collector << '), 0)'
394
395
  collector << COMMA
395
396
  collector << '1)'
396
397
  else
397
398
  collector = visit o.left, collector
398
399
  end
399
400
  collector << ')' if o.left.is_a? ArelExtensions::Nodes::Trim
400
- collector << ")"
401
+ collector << ')'
401
402
  collector
402
403
  end
403
404
 
@@ -410,7 +411,7 @@ module ArelExtensions
410
411
  end
411
412
  collector << ' FROM '
412
413
  collector = visit o.left, collector
413
- collector << ")"
414
+ collector << ')'
414
415
  collector
415
416
  end
416
417
 
@@ -423,7 +424,7 @@ module ArelExtensions
423
424
  end
424
425
  collector << ' FROM '
425
426
  collector = visit o.left, collector
426
- collector << ")"
427
+ collector << ')'
427
428
  collector
428
429
  end
429
430
 
@@ -446,39 +447,46 @@ module ArelExtensions
446
447
 
447
448
  def visit_ArelExtensions_Nodes_Format o, collector
448
449
  fmt = ArelExtensions::Visitors::strftime_to_format(o.iso_format, DATE_FORMAT_DIRECTIVES)
449
- collector << "TO_CHAR("
450
- collector << "CAST(" if o.time_zone
450
+ collector << 'TO_CHAR('
451
+ collector << 'CAST(' if o.time_zone
451
452
  collector = visit o.left, collector
452
- if o.time_zone
453
- collector << " as timestamp) at time zone "
454
- collector = visit o.time_zone, collector
453
+ case o.time_zone
454
+ when Hash
455
+ src_tz, dst_tz = o.time_zone.first
456
+ collector << ' as timestamp) at time zone '
457
+ collector = visit Arel.quoted(src_tz), collector
458
+ collecto < ' at time zone '
459
+ collector = visit Arel.quoted(dst_tz), collector
460
+ when String
461
+ collector << ' as timestamp) at time zone '
462
+ collector = visit Arel.quoted(o.time_zone), collector
455
463
  end
456
464
  collector << COMMA
457
- collector = visit Arel::Nodes.build_quoted(fmt), collector
458
- collector << ")"
465
+ collector = visit Arel.quoted(fmt), collector
466
+ collector << ')'
459
467
  collector
460
468
  end
461
469
 
462
470
  def visit_ArelExtensions_Nodes_Repeat o, collector
463
- collector << "LPAD("
471
+ collector << 'LPAD('
464
472
  collector = visit o.expressions[0], collector # can't put empty string, otherwise it wouldn't work
465
473
  collector << Arel::Visitors::ToSql::COMMA
466
474
  collector = visit o.expressions[1], collector
467
475
  collector << Arel::Visitors::ToSql::COMMA
468
476
  collector = visit o.expressions[0], collector
469
- collector << ")"
477
+ collector << ')'
470
478
  collector
471
479
  end
472
480
 
473
481
  # add primary_key if not present, avoid zip
474
482
  if Arel::VERSION.to_i < 7
475
483
  def visit_ArelExtensions_InsertManager_BulkValues o, collector
476
- collector << "("
484
+ collector << '('
477
485
  o.left.each_with_index do |row, idx| # values
478
- collector << " UNION ALL " if idx != 0
479
- collector << "(SELECT "
480
- len = row.length - 1
481
- row.zip(o.cols).each_with_index { |(value, attr), i|
486
+ collector << ' UNION ALL ' if idx != 0
487
+ collector << '(SELECT '
488
+ len = row.length - 1
489
+ row.zip(o.cols).each_with_index { |(value, attr), i|
482
490
  case value
483
491
  when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
484
492
  collector = visit value, collector
@@ -486,18 +494,18 @@ module ArelExtensions
486
494
  collector << quote(value, attr && column_for(attr)).to_s
487
495
  end
488
496
  collector << COMMA unless i == len
489
- }
490
- collector << ' FROM DUAL)'
497
+ }
498
+ collector << ' FROM DUAL)'
491
499
  end
492
- collector << ")"
500
+ collector << ')'
493
501
  collector
494
502
  end
495
503
  else
496
504
  def visit_ArelExtensions_InsertManager_BulkValues o, collector
497
- collector << "("
505
+ collector << '('
498
506
  o.left.each_with_index do |row, idx|
499
- collector << " UNION ALL " if idx != 0
500
- collector << "(SELECT "
507
+ collector << ' UNION ALL ' if idx != 0
508
+ collector << '(SELECT '
501
509
  len = row.length - 1
502
510
  row.zip(o.cols).each_with_index { |(value, attr), i|
503
511
  case value
@@ -512,7 +520,7 @@ module ArelExtensions
512
520
  }
513
521
  collector << ' FROM DUAL)'
514
522
  end
515
- collector << ")"
523
+ collector << ')'
516
524
  collector
517
525
  end
518
526
  end
@@ -522,7 +530,7 @@ module ArelExtensions
522
530
  if element.is_a?(Time)
523
531
  ArelExtensions::Nodes::Format.new [element, '%H:%M:%S']
524
532
  elsif element.is_a?(Arel::Attributes::Attribute)
525
- col = ArelExtensions::column_of(element.relation.table_name, element.name.to_s)
533
+ col = Arel.column_of(element.relation.table_name, element.name.to_s)
526
534
  if col && (col.type == :time)
527
535
  ArelExtensions::Nodes::Format.new [element, '%H:%M:%S']
528
536
  else
@@ -537,7 +545,7 @@ module ArelExtensions
537
545
  remove_method(:visit_Arel_Nodes_GreaterThanOrEqual) rescue nil
538
546
  def visit_Arel_Nodes_GreaterThanOrEqual o, collector
539
547
  collector = visit get_time_converted(o.left), collector
540
- collector << " >= "
548
+ collector << ' >= '
541
549
  collector = visit get_time_converted(o.right), collector
542
550
  collector
543
551
  end
@@ -545,7 +553,7 @@ module ArelExtensions
545
553
  remove_method(:visit_Arel_Nodes_GreaterThan) rescue nil
546
554
  def visit_Arel_Nodes_GreaterThan o, collector
547
555
  collector = visit get_time_converted(o.left), collector
548
- collector << " > "
556
+ collector << ' > '
549
557
  collector = visit get_time_converted(o.right), collector
550
558
  collector
551
559
  end
@@ -553,7 +561,7 @@ module ArelExtensions
553
561
  remove_method(:visit_Arel_Nodes_LessThanOrEqual) rescue nil
554
562
  def visit_Arel_Nodes_LessThanOrEqual o, collector
555
563
  collector = visit get_time_converted(o.left), collector
556
- collector << " <= "
564
+ collector << ' <= '
557
565
  collector = visit get_time_converted(o.right), collector
558
566
  collector
559
567
  end
@@ -561,7 +569,7 @@ module ArelExtensions
561
569
  remove_method(:visit_Arel_Nodes_LessThan) rescue nil
562
570
  def visit_Arel_Nodes_LessThan o, collector
563
571
  collector = visit get_time_converted(o.left), collector
564
- collector << " < "
572
+ collector << ' < '
565
573
  collector = visit get_time_converted(o.right), collector
566
574
  collector
567
575
  end
@@ -573,7 +581,7 @@ module ArelExtensions
573
581
  o = o.dup
574
582
  o.orders = []
575
583
  end
576
- old_visit_Arel_Nodes_SelectStatement(o,collector)
584
+ old_visit_Arel_Nodes_SelectStatement(o, collector)
577
585
  end
578
586
 
579
587
  alias_method(:old_visit_Arel_Nodes_TableAlias, :visit_Arel_Nodes_TableAlias) rescue nil
@@ -581,7 +589,7 @@ module ArelExtensions
581
589
  if o.name.length > 30
582
590
  o = Arel::Table.new(o.table_name).alias(Base64.urlsafe_encode64(Digest::MD5.new.digest(o.name)).tr('=', '').tr('-', '_'))
583
591
  end
584
- old_visit_Arel_Nodes_TableAlias(o,collector)
592
+ old_visit_Arel_Nodes_TableAlias(o, collector)
585
593
  end
586
594
 
587
595
  alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
@@ -617,47 +625,47 @@ module ArelExtensions
617
625
  col = o.left.coalesce(0)
618
626
  comma = NUMBER_COMMA_MAPPING[o.locale] || '.,'
619
627
  comma_in_format = o.precision == 0 ? '' : 'D'
620
- nines_after = (1..o.precision-1).map{'9'}.join('')+'0'
628
+ nines_after = (1..o.precision - 1).map{'9'}.join('') + '0'
621
629
  if comma.length == 1
622
- options = Arel::Nodes.build_quoted("NLS_NUMERIC_CHARACTERS = '"+comma+" '")
623
- nines_before = ("999"*4+"990")
630
+ options = Arel.quoted("NLS_NUMERIC_CHARACTERS = '" + comma + " '")
631
+ nines_before = ('999' * 4 + '990')
624
632
  else
625
- options = Arel::Nodes.build_quoted("NLS_NUMERIC_CHARACTERS = '"+comma+"'")
626
- nines_before = ("999G"*4+"990")
633
+ options = Arel.quoted("NLS_NUMERIC_CHARACTERS = '" + comma + "'")
634
+ nines_before = ('999G' * 4 + '990')
627
635
  end
628
- sign = ArelExtensions::Nodes::Case.new.when(col<0).
636
+ sign = Arel.when(col < 0).
629
637
  then('-').
630
638
  else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
631
639
  sign_length = o.flags.include?('+') || o.flags.include?(' ') ?
632
- Arel::Nodes.build_quoted(1) :
633
- ArelExtensions::Nodes::Case.new.when(col<0).then(1).else(0)
640
+ Arel.quoted(1) :
641
+ Arel.when(col < 0).then(1).else(0)
634
642
 
635
643
  if o.scientific_notation
636
- number = Arel::Nodes::NamedFunction.new('TO_CHAR',[
637
- Arel::Nodes.build_quoted(col.abs),
638
- Arel::Nodes.build_quoted('FM'+nines_before+comma_in_format+nines_after+'EEEE'),
644
+ number = Arel::Nodes::NamedFunction.new('TO_CHAR', [
645
+ Arel.quoted(col.abs),
646
+ Arel.quoted('FM' + nines_before + comma_in_format + nines_after + 'EEEE'),
639
647
  options
640
648
  ])
641
649
  if o.type == 'e'
642
- number = number.replace('E','e')
650
+ number = number.replace('E', 'e')
643
651
  end
644
652
  else
645
- number = Arel::Nodes::NamedFunction.new('TO_CHAR',[
646
- Arel::Nodes.build_quoted(col.abs),
647
- Arel::Nodes.build_quoted('FM'+nines_before+comma_in_format+nines_after),
653
+ number = Arel::Nodes::NamedFunction.new('TO_CHAR', [
654
+ Arel.quoted(col.abs),
655
+ Arel.quoted('FM' + nines_before + comma_in_format + nines_after),
648
656
  options
649
657
  ])
650
658
  end
651
659
 
652
- repeated_char = (o.width == 0) ? Arel::Nodes.build_quoted('') : ArelExtensions::Nodes::Case.new().
653
- when(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length)>0).
654
- then(Arel::Nodes.build_quoted(
660
+ repeated_char = (o.width == 0) ? Arel.quoted('') : ArelExtensions::Nodes::Case.new.
661
+ when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0).
662
+ then(Arel.quoted(
655
663
  o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
656
- ).repeat(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length))
664
+ ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
657
665
  ).
658
666
  else('')
659
- before = (!o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
660
- middle = (o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
667
+ before = (!o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
668
+ middle = (o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
661
669
  after = o.flags.include?('-') ? repeated_char : ''
662
670
  full_number = ArelExtensions::Nodes::Concat.new([
663
671
  before,
@@ -666,26 +674,26 @@ module ArelExtensions
666
674
  number,
667
675
  after
668
676
  ])
669
- collector = visit ArelExtensions::Nodes::Concat.new([Arel::Nodes.build_quoted(o.prefix),full_number,Arel::Nodes.build_quoted(o.suffix)]), collector
677
+ collector = visit ArelExtensions::Nodes::Concat.new([Arel.quoted(o.prefix), full_number, Arel.quoted(o.suffix)]), collector
670
678
  collector
671
679
  end
672
680
 
673
681
  def visit_ArelExtensions_Nodes_Std o, collector
674
- collector << (o.unbiased_estimator ? "STDDEV_SAMP(" : "STDDEV_POP(")
682
+ collector << (o.unbiased_estimator ? 'STDDEV_SAMP(' : 'STDDEV_POP(')
675
683
  visit o.left, collector
676
- collector << ")"
684
+ collector << ')'
677
685
  collector
678
686
  end
679
687
 
680
688
  def visit_ArelExtensions_Nodes_Variance o, collector
681
- collector << (o.unbiased_estimator ? "VAR_SAMP(" : "VAR_POP(")
689
+ collector << (o.unbiased_estimator ? 'VAR_SAMP(' : 'VAR_POP(')
682
690
  visit o.left, collector
683
- collector << ")"
691
+ collector << ')'
684
692
  collector
685
693
  end
686
694
 
687
695
  def visit_ArelExtensions_Nodes_LevenshteinDistance o, collector
688
- collector << "UTL_MATCH.edit_distance("
696
+ collector << 'UTL_MATCH.edit_distance('
689
697
  collector = visit o.left, collector
690
698
  collector << Arel::Visitors::ToSql::COMMA
691
699
  collector = visit o.right, collector