arel_extensions 2.1.3 → 2.1.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 +1 -2
  7. data/Rakefile +4 -4
  8. data/TODO +0 -1
  9. data/arel_extensions.gemspec +11 -11
  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 +0 -0
  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 +127 -121
  84. data/lib/arel_extensions/visitors/mysql.rb +137 -145
  85. data/lib/arel_extensions/visitors/oracle.rb +128 -128
  86. data/lib/arel_extensions/visitors/oracle12.rb +16 -16
  87. data/lib/arel_extensions/visitors/postgresql.rb +139 -137
  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 -13
  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 +364 -299
  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
@@ -7,30 +7,30 @@ module ArelExtensions
7
7
  DATE_FORMAT_DIRECTIVES = {
8
8
  '%Y' => 'YYYY', '%C' => 'CC', '%y' => 'YY', '%m' => 'MM', '%B' => 'Month', '%^B' => 'MONTH', '%b' => 'Mon', '%^b' => 'MON',
9
9
  '%V' => 'IW', '%G' => 'IYYY', # ISO week number and year of week
10
- '%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%A' => 'Day', # day, weekday
10
+ '%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%a' => 'Dy', '%A' => 'Day', # day, weekday
11
11
  '%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
12
12
  '%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz' # seconds, subseconds
13
13
  }
14
14
  NUMBER_COMMA_MAPPING = { 'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', ' }
15
15
 
16
16
  def visit_ArelExtensions_Nodes_Log10 o, 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
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
24
24
  end
25
25
 
26
26
  def visit_ArelExtensions_Nodes_Power o, 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
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
34
34
  end
35
35
 
36
36
  def visit_ArelExtensions_Nodes_Concat o, collector
@@ -108,54 +108,54 @@ module ArelExtensions
108
108
  end
109
109
 
110
110
  def visit_ArelExtensions_Nodes_Collate o, collector
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
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
126
126
  collector
127
127
  end
128
128
 
129
129
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
130
- collector << "(LISTAGG("
130
+ collector << '(LISTAGG('
131
131
  collector = visit o.left, collector
132
132
  collector << COMMA
133
133
  collector =
134
134
  if o.separator && o.separator != 'NULL'
135
135
  visit o.separator, collector
136
136
  else
137
- visit Arel::Nodes.build_quoted(','), collector
137
+ visit Arel.quoted(','), collector
138
138
  end
139
- collector << ") WITHIN GROUP (ORDER BY "
139
+ collector << ') WITHIN GROUP (ORDER BY '
140
140
  if !o.order.blank?
141
- o.order.each_with_index do |order,i|
141
+ o.order.each_with_index do |order, i|
142
142
  collector << COMMA if i != 0
143
143
  collector = visit order, collector
144
144
  end
145
145
  else
146
146
  collector = visit o.left, collector
147
147
  end
148
- collector << "))"
148
+ collector << '))'
149
149
  collector
150
150
  end
151
151
 
152
152
  def visit_ArelExtensions_Nodes_Coalesce o, collector
153
- collector << "COALESCE("
153
+ collector << 'COALESCE('
154
154
  o.expressions.each_with_index { |arg, i|
155
155
  collector << COMMA if i != 0
156
156
  if i > 0 && o.left_node_type == :text
157
157
  if arg == '' || (arg.is_a?(Arel::Nodes::Quoted) && (arg.expr == ''))
158
- collector << "NULL"
158
+ collector << 'NULL'
159
159
  else
160
160
  collector << 'TO_CLOB('
161
161
  collector = visit arg, collector
@@ -165,12 +165,12 @@ module ArelExtensions
165
165
  collector = visit arg, collector
166
166
  end
167
167
  }
168
- collector << ")"
168
+ collector << ')'
169
169
  collector
170
170
  end
171
171
 
172
172
  def visit_ArelExtensions_Nodes_MD5 o, collector
173
- 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('
174
174
  collector = visit o.left, collector
175
175
  collector << ", 'AL32UTF8'))))"
176
176
  collector
@@ -185,7 +185,7 @@ module ArelExtensions
185
185
  collector << 'TO_DATE(' if lc
186
186
  collector = visit o.left, collector
187
187
  collector << ')' if lc
188
- collector << " - "
188
+ collector << ' - '
189
189
  collector << 'TO_DATE(' if rc
190
190
  collector = visit o.right, collector
191
191
  collector << ')' if rc
@@ -219,16 +219,16 @@ module ArelExtensions
219
219
  def visit_ArelExtensions_Nodes_Duration o, collector
220
220
  case o.left
221
221
  when 'wd', 'w'
222
- collector << "TO_CHAR("
222
+ collector << 'TO_CHAR('
223
223
  collector = visit o.right, collector
224
224
  collector << COMMA
225
- collector = visit Arel::Nodes.build_quoted(DATE_MAPPING[o.left]), collector
225
+ collector = visit Arel.quoted(DATE_MAPPING[o.left]), collector
226
226
  else
227
227
  right = case o.left
228
- when 'd','m','y'
228
+ when 'd', 'm', 'y'
229
229
  interval = 'DAY'
230
230
  o.right.cast(:date)
231
- when 'h','mn','s'
231
+ when 'h', 'mn', 's'
232
232
  interval = 'SECOND'
233
233
  o.right.cast(:datetime)
234
234
  when /i\z/
@@ -244,7 +244,7 @@ module ArelExtensions
244
244
  collector << "EXTRACT(#{DATE_MAPPING[o.left]} FROM "
245
245
  collector = visit right, collector
246
246
  end
247
- collector << ")"
247
+ collector << ')'
248
248
  collector << " * (INTERVAL '1' #{interval})" if interval && o.with_interval
249
249
  collector
250
250
  end
@@ -252,45 +252,45 @@ module ArelExtensions
252
252
  def visit_ArelExtensions_Nodes_Cast o, collector
253
253
  case o.as_attr
254
254
  when :string
255
- collector << "TO_CHAR("
255
+ collector << 'TO_CHAR('
256
256
  collector = visit o.left, collector
257
- collector << ")"
257
+ collector << ')'
258
258
  return collector
259
259
  when :text
260
- collector << "TO_CLOB("
260
+ collector << 'TO_CLOB('
261
261
  collector = visit o.left, collector
262
- collector << ")"
262
+ collector << ')'
263
263
  return collector
264
264
  when :ntext
265
- collector << "TO_NCLOB("
265
+ collector << 'TO_NCLOB('
266
266
  collector = visit o.left, collector
267
- collector << ")"
267
+ collector << ')'
268
268
  return collector
269
269
  when :time
270
270
  if (o.left.respond_to?(:return_type) && o.left.return_type == :string) || o.left.is_a?(Arel::Nodes::Quoted)
271
- collector << "TO_DATE("
271
+ collector << 'TO_DATE('
272
272
  collector = visit o.left, collector
273
273
  collector << ",'HH24:MI:SS')"
274
274
  else
275
- collector << "TO_DATE(TO_CHAR("
275
+ collector << 'TO_DATE(TO_CHAR('
276
276
  collector = visit o.left, collector
277
277
  collector << ",'HH24:MI:SS'),'HH24:MI:SS')"
278
278
  end
279
279
  return collector
280
280
  when :number, :decimal
281
- collector << "TO_NUMBER("
281
+ collector << 'TO_NUMBER('
282
282
  collector = visit o.left, collector
283
- collector << ")"
283
+ collector << ')'
284
284
  return collector
285
285
  when :datetime
286
286
  as_attr = Arel::Nodes::SqlLiteral.new('timestamp')
287
287
  when :date
288
288
  if (o.left.respond_to?(:return_type) && o.left.return_type == :string) || o.left.is_a?(Arel::Nodes::Quoted)
289
- collector << "TO_DATE("
289
+ collector << 'TO_DATE('
290
290
  collector = visit o.left, collector
291
291
  collector << ",'YYYY-MM-DD')"
292
292
  else
293
- collector << "TO_DATE(TO_CHAR("
293
+ collector << 'TO_DATE(TO_CHAR('
294
294
  collector = visit o.left, collector
295
295
  collector << ",'YYYY-MM-DD'),'YYYY-MM-DD')"
296
296
  end
@@ -300,18 +300,18 @@ module ArelExtensions
300
300
  else
301
301
  as_attr = Arel::Nodes::SqlLiteral.new(o.as_attr.to_s)
302
302
  end
303
- collector << "CAST("
303
+ collector << 'CAST('
304
304
  collector = visit o.left, collector
305
- collector << " AS "
305
+ collector << ' AS '
306
306
  collector = visit as_attr, collector
307
- collector << ")"
307
+ collector << ')'
308
308
  collector
309
309
  end
310
310
 
311
311
  def visit_ArelExtensions_Nodes_Length o, collector
312
312
  collector << "LENGTH#{o.bytewise ? 'B' : ''}("
313
313
  collector = visit o.expr, collector
314
- collector << ")"
314
+ collector << ')'
315
315
  collector
316
316
  end
317
317
 
@@ -328,18 +328,18 @@ module ArelExtensions
328
328
  end
329
329
 
330
330
  def visit_ArelExtensions_Nodes_Rand o, collector
331
- collector << "DBMS_RANDOM.VALUE("
331
+ collector << 'DBMS_RANDOM.VALUE('
332
332
  if o.left && o.right
333
333
  collector = visit o.left, collector
334
334
  collector << COMMA
335
335
  collector = visit o.right, collector
336
336
  end
337
- collector << ")"
337
+ collector << ')'
338
338
  collector
339
339
  end
340
340
 
341
341
  def visit_Arel_Nodes_Regexp o, collector
342
- collector << " REGEXP_LIKE("
342
+ collector << ' REGEXP_LIKE('
343
343
  collector = visit o.left, collector
344
344
  collector << COMMA
345
345
  collector = visit o.right, collector
@@ -348,7 +348,7 @@ module ArelExtensions
348
348
  end
349
349
 
350
350
  def visit_Arel_Nodes_NotRegexp o, collector
351
- collector << " NOT REGEXP_LIKE("
351
+ collector << ' NOT REGEXP_LIKE('
352
352
  collector = visit o.left, collector
353
353
  collector << COMMA
354
354
  collector = visit o.right, collector
@@ -357,22 +357,22 @@ module ArelExtensions
357
357
  end
358
358
 
359
359
  def visit_ArelExtensions_Nodes_Locate o, collector
360
- collector << "INSTR("
360
+ collector << 'INSTR('
361
361
  o.expressions.each_with_index { |arg, i|
362
362
  collector << COMMA if i != 0
363
363
  collector = visit arg, collector
364
364
  }
365
- collector << ")"
365
+ collector << ')'
366
366
  collector
367
367
  end
368
368
 
369
369
  def visit_ArelExtensions_Nodes_Substring o, collector
370
- collector << "SUBSTR("
370
+ collector << 'SUBSTR('
371
371
  o.expressions.each_with_index { |arg, i|
372
372
  collector << COMMA if i != 0
373
373
  collector = visit arg, collector
374
374
  }
375
- collector << ")"
375
+ collector << ')'
376
376
  collector
377
377
  end
378
378
 
@@ -391,14 +391,14 @@ module ArelExtensions
391
391
  collector << COMMA
392
392
  collector << 'COALESCE(dbms_lob.GETLENGTH('
393
393
  collector = visit o.left, collector
394
- collector << "), 0)"
394
+ collector << '), 0)'
395
395
  collector << COMMA
396
396
  collector << '1)'
397
397
  else
398
398
  collector = visit o.left, collector
399
399
  end
400
400
  collector << ')' if o.left.is_a? ArelExtensions::Nodes::Trim
401
- collector << ")"
401
+ collector << ')'
402
402
  collector
403
403
  end
404
404
 
@@ -411,7 +411,7 @@ module ArelExtensions
411
411
  end
412
412
  collector << ' FROM '
413
413
  collector = visit o.left, collector
414
- collector << ")"
414
+ collector << ')'
415
415
  collector
416
416
  end
417
417
 
@@ -424,7 +424,7 @@ module ArelExtensions
424
424
  end
425
425
  collector << ' FROM '
426
426
  collector = visit o.left, collector
427
- collector << ")"
427
+ collector << ')'
428
428
  collector
429
429
  end
430
430
 
@@ -447,46 +447,46 @@ module ArelExtensions
447
447
 
448
448
  def visit_ArelExtensions_Nodes_Format o, collector
449
449
  fmt = ArelExtensions::Visitors::strftime_to_format(o.iso_format, DATE_FORMAT_DIRECTIVES)
450
- collector << "TO_CHAR("
451
- collector << "CAST(" if o.time_zone
450
+ collector << 'TO_CHAR('
451
+ collector << 'CAST(' if o.time_zone
452
452
  collector = visit o.left, collector
453
453
  case o.time_zone
454
454
  when Hash
455
455
  src_tz, dst_tz = o.time_zone.first
456
456
  collector << ' as timestamp) at time zone '
457
- collector = visit Arel::Nodes.build_quoted(src_tz), collector
457
+ collector = visit Arel.quoted(src_tz), collector
458
458
  collecto < ' at time zone '
459
- collector = visit Arel::Nodes.build_quoted(dst_tz), collector
459
+ collector = visit Arel.quoted(dst_tz), collector
460
460
  when String
461
461
  collector << ' as timestamp) at time zone '
462
- collector = visit Arel::Nodes.build_quoted(o.time_zone), collector
462
+ collector = visit Arel.quoted(o.time_zone), collector
463
463
  end
464
464
  collector << COMMA
465
- collector = visit Arel::Nodes.build_quoted(fmt), collector
466
- collector << ")"
465
+ collector = visit Arel.quoted(fmt), collector
466
+ collector << ')'
467
467
  collector
468
468
  end
469
469
 
470
470
  def visit_ArelExtensions_Nodes_Repeat o, collector
471
- collector << "LPAD("
471
+ collector << 'LPAD('
472
472
  collector = visit o.expressions[0], collector # can't put empty string, otherwise it wouldn't work
473
473
  collector << Arel::Visitors::ToSql::COMMA
474
474
  collector = visit o.expressions[1], collector
475
475
  collector << Arel::Visitors::ToSql::COMMA
476
476
  collector = visit o.expressions[0], collector
477
- collector << ")"
477
+ collector << ')'
478
478
  collector
479
479
  end
480
480
 
481
481
  # add primary_key if not present, avoid zip
482
482
  if Arel::VERSION.to_i < 7
483
483
  def visit_ArelExtensions_InsertManager_BulkValues o, collector
484
- collector << "("
484
+ collector << '('
485
485
  o.left.each_with_index do |row, idx| # values
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|
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|
490
490
  case value
491
491
  when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
492
492
  collector = visit value, collector
@@ -494,18 +494,18 @@ module ArelExtensions
494
494
  collector << quote(value, attr && column_for(attr)).to_s
495
495
  end
496
496
  collector << COMMA unless i == len
497
- }
498
- collector << ' FROM DUAL)'
497
+ }
498
+ collector << ' FROM DUAL)'
499
499
  end
500
- collector << ")"
500
+ collector << ')'
501
501
  collector
502
502
  end
503
503
  else
504
504
  def visit_ArelExtensions_InsertManager_BulkValues o, collector
505
- collector << "("
505
+ collector << '('
506
506
  o.left.each_with_index do |row, idx|
507
- collector << " UNION ALL " if idx != 0
508
- collector << "(SELECT "
507
+ collector << ' UNION ALL ' if idx != 0
508
+ collector << '(SELECT '
509
509
  len = row.length - 1
510
510
  row.zip(o.cols).each_with_index { |(value, attr), i|
511
511
  case value
@@ -520,7 +520,7 @@ module ArelExtensions
520
520
  }
521
521
  collector << ' FROM DUAL)'
522
522
  end
523
- collector << ")"
523
+ collector << ')'
524
524
  collector
525
525
  end
526
526
  end
@@ -530,7 +530,7 @@ module ArelExtensions
530
530
  if element.is_a?(Time)
531
531
  ArelExtensions::Nodes::Format.new [element, '%H:%M:%S']
532
532
  elsif element.is_a?(Arel::Attributes::Attribute)
533
- 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)
534
534
  if col && (col.type == :time)
535
535
  ArelExtensions::Nodes::Format.new [element, '%H:%M:%S']
536
536
  else
@@ -545,7 +545,7 @@ module ArelExtensions
545
545
  remove_method(:visit_Arel_Nodes_GreaterThanOrEqual) rescue nil
546
546
  def visit_Arel_Nodes_GreaterThanOrEqual o, collector
547
547
  collector = visit get_time_converted(o.left), collector
548
- collector << " >= "
548
+ collector << ' >= '
549
549
  collector = visit get_time_converted(o.right), collector
550
550
  collector
551
551
  end
@@ -553,7 +553,7 @@ module ArelExtensions
553
553
  remove_method(:visit_Arel_Nodes_GreaterThan) rescue nil
554
554
  def visit_Arel_Nodes_GreaterThan o, collector
555
555
  collector = visit get_time_converted(o.left), collector
556
- collector << " > "
556
+ collector << ' > '
557
557
  collector = visit get_time_converted(o.right), collector
558
558
  collector
559
559
  end
@@ -561,7 +561,7 @@ module ArelExtensions
561
561
  remove_method(:visit_Arel_Nodes_LessThanOrEqual) rescue nil
562
562
  def visit_Arel_Nodes_LessThanOrEqual o, collector
563
563
  collector = visit get_time_converted(o.left), collector
564
- collector << " <= "
564
+ collector << ' <= '
565
565
  collector = visit get_time_converted(o.right), collector
566
566
  collector
567
567
  end
@@ -569,7 +569,7 @@ module ArelExtensions
569
569
  remove_method(:visit_Arel_Nodes_LessThan) rescue nil
570
570
  def visit_Arel_Nodes_LessThan o, collector
571
571
  collector = visit get_time_converted(o.left), collector
572
- collector << " < "
572
+ collector << ' < '
573
573
  collector = visit get_time_converted(o.right), collector
574
574
  collector
575
575
  end
@@ -581,7 +581,7 @@ module ArelExtensions
581
581
  o = o.dup
582
582
  o.orders = []
583
583
  end
584
- old_visit_Arel_Nodes_SelectStatement(o,collector)
584
+ old_visit_Arel_Nodes_SelectStatement(o, collector)
585
585
  end
586
586
 
587
587
  alias_method(:old_visit_Arel_Nodes_TableAlias, :visit_Arel_Nodes_TableAlias) rescue nil
@@ -589,7 +589,7 @@ module ArelExtensions
589
589
  if o.name.length > 30
590
590
  o = Arel::Table.new(o.table_name).alias(Base64.urlsafe_encode64(Digest::MD5.new.digest(o.name)).tr('=', '').tr('-', '_'))
591
591
  end
592
- old_visit_Arel_Nodes_TableAlias(o,collector)
592
+ old_visit_Arel_Nodes_TableAlias(o, collector)
593
593
  end
594
594
 
595
595
  alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
@@ -625,47 +625,47 @@ module ArelExtensions
625
625
  col = o.left.coalesce(0)
626
626
  comma = NUMBER_COMMA_MAPPING[o.locale] || '.,'
627
627
  comma_in_format = o.precision == 0 ? '' : 'D'
628
- nines_after = (1..o.precision-1).map{'9'}.join('')+'0'
628
+ nines_after = (1..o.precision - 1).map{'9'}.join('') + '0'
629
629
  if comma.length == 1
630
- options = Arel::Nodes.build_quoted("NLS_NUMERIC_CHARACTERS = '"+comma+" '")
631
- nines_before = ("999"*4+"990")
630
+ options = Arel.quoted("NLS_NUMERIC_CHARACTERS = '" + comma + " '")
631
+ nines_before = ('999' * 4 + '990')
632
632
  else
633
- options = Arel::Nodes.build_quoted("NLS_NUMERIC_CHARACTERS = '"+comma+"'")
634
- nines_before = ("999G"*4+"990")
633
+ options = Arel.quoted("NLS_NUMERIC_CHARACTERS = '" + comma + "'")
634
+ nines_before = ('999G' * 4 + '990')
635
635
  end
636
- sign = ArelExtensions::Nodes::Case.new.when(col<0).
636
+ sign = Arel.when(col < 0).
637
637
  then('-').
638
638
  else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
639
639
  sign_length = o.flags.include?('+') || o.flags.include?(' ') ?
640
- Arel::Nodes.build_quoted(1) :
641
- ArelExtensions::Nodes::Case.new.when(col<0).then(1).else(0)
640
+ Arel.quoted(1) :
641
+ Arel.when(col < 0).then(1).else(0)
642
642
 
643
643
  if o.scientific_notation
644
- number = Arel::Nodes::NamedFunction.new('TO_CHAR',[
645
- Arel::Nodes.build_quoted(col.abs),
646
- 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'),
647
647
  options
648
648
  ])
649
649
  if o.type == 'e'
650
- number = number.replace('E','e')
650
+ number = number.replace('E', 'e')
651
651
  end
652
652
  else
653
- number = Arel::Nodes::NamedFunction.new('TO_CHAR',[
654
- Arel::Nodes.build_quoted(col.abs),
655
- 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),
656
656
  options
657
657
  ])
658
658
  end
659
659
 
660
- repeated_char = (o.width == 0) ? Arel::Nodes.build_quoted('') : ArelExtensions::Nodes::Case.new().
661
- when(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length)>0).
662
- 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(
663
663
  o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
664
- ).repeat(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length))
664
+ ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
665
665
  ).
666
666
  else('')
667
- before = (!o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
668
- 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 : ''
669
669
  after = o.flags.include?('-') ? repeated_char : ''
670
670
  full_number = ArelExtensions::Nodes::Concat.new([
671
671
  before,
@@ -674,26 +674,26 @@ module ArelExtensions
674
674
  number,
675
675
  after
676
676
  ])
677
- 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
678
678
  collector
679
679
  end
680
680
 
681
681
  def visit_ArelExtensions_Nodes_Std o, collector
682
- collector << (o.unbiased_estimator ? "STDDEV_SAMP(" : "STDDEV_POP(")
682
+ collector << (o.unbiased_estimator ? 'STDDEV_SAMP(' : 'STDDEV_POP(')
683
683
  visit o.left, collector
684
- collector << ")"
684
+ collector << ')'
685
685
  collector
686
686
  end
687
687
 
688
688
  def visit_ArelExtensions_Nodes_Variance o, collector
689
- collector << (o.unbiased_estimator ? "VAR_SAMP(" : "VAR_POP(")
689
+ collector << (o.unbiased_estimator ? 'VAR_SAMP(' : 'VAR_POP(')
690
690
  visit o.left, collector
691
- collector << ")"
691
+ collector << ')'
692
692
  collector
693
693
  end
694
694
 
695
695
  def visit_ArelExtensions_Nodes_LevenshteinDistance o, collector
696
- collector << "UTL_MATCH.edit_distance("
696
+ collector << 'UTL_MATCH.edit_distance('
697
697
  collector = visit o.left, collector
698
698
  collector << Arel::Visitors::ToSql::COMMA
699
699
  collector = visit o.right, collector