arel_extensions 2.1.2 → 2.1.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 +11 -11
  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
@@ -6,246 +6,246 @@ module ArelExtensions
6
6
  # Escape properly the string expression expr.
7
7
  # Take care of escaping.
8
8
  def make_json_string expr
9
- Arel::Nodes.build_quoted('"') \
9
+ Arel.quoted('"') \
10
10
  + expr
11
11
  .coalesce('')
12
- .replace('\\','\\\\').replace('"','\"').replace("\n", '\n') \
12
+ .replace('\\', '\\\\').replace('"', '\"').replace("\n", '\n') \
13
13
  + '"'
14
14
  end
15
15
 
16
16
  def make_json_null
17
- Arel::Nodes.build_quoted("null")
17
+ Arel.quoted('null')
18
18
  end
19
19
 
20
20
  # Math Functions
21
21
  def visit_ArelExtensions_Nodes_Abs o, collector
22
- collector << "ABS("
22
+ collector << 'ABS('
23
23
  o.expressions.each_with_index { |arg, i|
24
24
  collector << COMMA if i != 0
25
25
  collector = visit arg, collector
26
26
  }
27
- collector << ")"
27
+ collector << ')'
28
28
  collector
29
29
  end
30
30
 
31
31
  def visit_ArelExtensions_Nodes_Ceil o, collector
32
- collector << "CEIL("
32
+ collector << 'CEIL('
33
33
  o.expressions.each_with_index { |arg, i|
34
34
  collector << COMMA if i != 0
35
35
  collector = visit arg, collector
36
36
  }
37
- collector << ")"
37
+ collector << ')'
38
38
  collector
39
39
  end
40
40
 
41
41
  def visit_ArelExtensions_Nodes_Floor o, collector
42
- collector << "FLOOR("
42
+ collector << 'FLOOR('
43
43
  o.expressions.each_with_index { |arg, i|
44
44
  collector << COMMA if i != 0
45
45
  collector = visit arg, collector
46
46
  }
47
- collector << ")"
47
+ collector << ')'
48
48
  collector
49
49
  end
50
50
 
51
51
  def visit_ArelExtensions_Nodes_Rand o, collector
52
- collector << "RAND("
52
+ collector << 'RAND('
53
53
  o.expressions.each_with_index { |arg, i|
54
54
  collector << COMMA if i != 0
55
55
  collector = visit arg, collector
56
56
  }
57
- collector << ")"
57
+ collector << ')'
58
58
  collector
59
59
  end
60
60
 
61
61
  def visit_ArelExtensions_Nodes_Round o, collector
62
- collector << "ROUND("
62
+ collector << 'ROUND('
63
63
  o.expressions.each_with_index { |arg, i|
64
64
  collector << COMMA if i != 0
65
65
  collector = visit arg, collector
66
66
  }
67
- collector << ")"
67
+ collector << ')'
68
68
  collector
69
69
  end
70
70
 
71
71
  def visit_ArelExtensions_Nodes_Log10 o, collector
72
- collector << "LOG10("
72
+ collector << 'LOG10('
73
73
  collector = visit o.left, collector
74
- collector << ")"
74
+ collector << ')'
75
75
  collector
76
76
  end
77
77
 
78
78
  def visit_ArelExtensions_Nodes_Power o, collector
79
- collector << "POW("
79
+ collector << 'POW('
80
80
  o.expressions.each_with_index { |arg, i|
81
81
  collector << COMMA if i != 0
82
82
  collector = visit arg, collector
83
83
  }
84
- collector << ")"
84
+ collector << ')'
85
85
  collector
86
86
  end
87
87
 
88
88
  def visit_ArelExtensions_Nodes_Sum o, collector
89
- collector << "SUM("
89
+ collector << 'SUM('
90
90
  collector = visit o.expr, collector
91
- collector << ")"
91
+ collector << ')'
92
92
  collector
93
93
  end
94
94
 
95
95
  # String functions
96
96
  def visit_ArelExtensions_Nodes_Concat o, collector
97
- collector << "CONCAT("
97
+ collector << 'CONCAT('
98
98
  o.expressions.each_with_index { |arg, i|
99
- collector << COMMA if i != 0
100
- collector = visit arg, collector
99
+ collector << COMMA if i != 0
100
+ collector = visit arg, collector
101
101
  }
102
- collector << ")"
102
+ collector << ')'
103
103
  collector
104
104
  end
105
105
 
106
106
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
107
- collector << "GROUP_CONCAT("
107
+ collector << 'GROUP_CONCAT('
108
108
  collector = visit o.left, collector
109
109
  if o.separator && o.separator != 'NULL'
110
110
  collector << COMMA
111
111
  collector = visit o.separator, collector
112
112
  end
113
- collector << ")"
113
+ collector << ')'
114
114
  collector
115
115
  end
116
116
 
117
117
  def visit_ArelExtensions_Nodes_MD5 o, collector
118
- collector << "MD5("
118
+ collector << 'MD5('
119
119
  collector = visit o.left, collector
120
- collector << ")"
120
+ collector << ')'
121
121
  collector
122
122
  end
123
123
 
124
124
  def visit_ArelExtensions_Nodes_Length o, collector
125
125
  collector << "#{o.bytewise ? '' : 'CHAR_'}LENGTH("
126
126
  collector = visit o.left, collector
127
- collector << ")"
127
+ collector << ')'
128
128
  collector
129
129
  end
130
130
 
131
131
  def visit_ArelExtensions_Nodes_Locate o, collector
132
- collector << "LOCATE("
132
+ collector << 'LOCATE('
133
133
  collector = visit o.right, collector
134
134
  collector << COMMA
135
135
  collector = visit o.left, collector
136
- collector << ")"
136
+ collector << ')'
137
137
  collector
138
138
  end
139
139
 
140
140
  def visit_ArelExtensions_Nodes_Substring o, collector
141
- collector << "SUBSTRING("
141
+ collector << 'SUBSTRING('
142
142
  o.expressions.each_with_index { |arg, i|
143
143
  collector << COMMA if i != 0
144
144
  collector = visit arg, collector
145
145
  }
146
- collector << ")"
146
+ collector << ')'
147
147
  collector
148
148
  end
149
149
 
150
150
  def visit_ArelExtensions_Nodes_Replace o, collector
151
- collector << "REPLACE("
151
+ collector << 'REPLACE('
152
152
  visit o.left, collector
153
153
  collector << COMMA
154
154
  visit o.pattern, collector
155
155
  collector << COMMA
156
156
  visit o.substitute, collector
157
- collector << ")"
157
+ collector << ')'
158
158
  collector
159
159
  end
160
160
 
161
161
  def visit_ArelExtensions_Nodes_RegexpReplace o, collector
162
- collector << "REGEXP_REPLACE("
162
+ collector << 'REGEXP_REPLACE('
163
163
  visit o.left, collector
164
164
  collector << COMMA
165
- visit Arel::Nodes.build_quoted(o.pattern.to_s), collector
165
+ visit Arel.quoted(o.pattern.to_s), collector
166
166
  collector << COMMA
167
167
  visit o.substitute, collector
168
- collector << ")"
168
+ collector << ')'
169
169
  collector
170
170
  end
171
171
 
172
172
  def visit_ArelExtensions_Nodes_Repeat o, collector
173
- collector << "REPEAT("
173
+ collector << 'REPEAT('
174
174
  o.expressions.each_with_index { |arg, i|
175
175
  collector << COMMA if i != 0
176
176
  collector = visit arg, collector
177
177
  }
178
- collector << ")"
178
+ collector << ')'
179
179
  collector
180
180
  end
181
181
 
182
182
  def visit_ArelExtensions_Nodes_FindInSet o, collector
183
- collector << "FIND_IN_SET("
183
+ collector << 'FIND_IN_SET('
184
184
  o.expressions.each_with_index { |arg, i|
185
185
  collector << COMMA if i != 0
186
186
  collector = visit arg, collector
187
187
  }
188
- collector << ")"
188
+ collector << ')'
189
189
  collector
190
190
  end
191
191
 
192
192
  def visit_ArelExtensions_Nodes_Soundex o, collector
193
- collector << "SOUNDEX("
193
+ collector << 'SOUNDEX('
194
194
  o.expressions.each_with_index { |arg, i|
195
195
  collector << COMMA if i != 0
196
196
  collector = visit arg, collector
197
197
  }
198
- collector << ")"
198
+ collector << ')'
199
199
  collector
200
200
  end
201
201
 
202
202
  def visit_ArelExtensions_Nodes_Downcase o, collector
203
- collector << "LOWER("
203
+ collector << 'LOWER('
204
204
  o.expressions.each_with_index { |arg, i|
205
205
  collector << COMMA if i != 0
206
206
  collector = visit arg, collector
207
207
  }
208
- collector << ")"
208
+ collector << ')'
209
209
  collector
210
210
  end
211
211
 
212
212
  def visit_ArelExtensions_Nodes_Upcase o, collector
213
- collector << "UPPER("
213
+ collector << 'UPPER('
214
214
  o.expressions.each_with_index { |arg, i|
215
215
  collector << COMMA if i != 0
216
216
  collector = visit arg, collector
217
217
  }
218
- collector << ")"
218
+ collector << ')'
219
219
  collector
220
220
  end
221
221
 
222
222
  def visit_ArelExtensions_Nodes_Trim o, collector
223
- collector << "TRIM("
223
+ collector << 'TRIM('
224
224
  o.expressions.each_with_index { |arg, i|
225
225
  collector << COMMA if i != 0
226
226
  collector = visit arg, collector
227
227
  }
228
- collector << ")"
228
+ collector << ')'
229
229
  collector
230
230
  end
231
231
 
232
232
  def visit_ArelExtensions_Nodes_Ltrim o, collector
233
- collector << "LTRIM("
233
+ collector << 'LTRIM('
234
234
  o.expressions.each_with_index { |arg, i|
235
235
  collector << COMMA if i != 0
236
236
  collector = visit arg, collector
237
237
  }
238
- collector << ")"
238
+ collector << ')'
239
239
  collector
240
240
  end
241
241
 
242
242
  def visit_ArelExtensions_Nodes_Rtrim o, collector
243
- collector << "RTRIM("
243
+ collector << 'RTRIM('
244
244
  o.expressions.each_with_index { |arg, i|
245
245
  collector << COMMA if i != 0
246
246
  collector = visit arg, collector
247
247
  }
248
- collector << ")"
248
+ collector << ')'
249
249
  collector
250
250
  end
251
251
 
@@ -254,8 +254,8 @@ module ArelExtensions
254
254
  collector << 'LENGTH(TRIM(COALESCE('
255
255
  collector = visit o.expr, collector
256
256
  collector << COMMA
257
- collector = visit Arel::Nodes.build_quoted(''), collector
258
- collector << "))) = 0"
257
+ collector = visit Arel.quoted(''), collector
258
+ collector << '))) = 0'
259
259
  collector
260
260
  end
261
261
 
@@ -264,25 +264,25 @@ module ArelExtensions
264
264
  collector << 'LENGTH(TRIM(COALESCE('
265
265
  collector = visit o.expr, collector
266
266
  collector << COMMA
267
- collector = visit Arel::Nodes.build_quoted(''), collector
268
- collector << "))) > 0"
267
+ collector = visit Arel.quoted(''), collector
268
+ collector << '))) > 0'
269
269
  collector
270
270
  end
271
271
 
272
272
  def visit_ArelExtensions_Nodes_Format o, collector
273
273
  case o.col_type
274
274
  when :date, :datetime, :time
275
- collector << "STRFTIME("
275
+ collector << 'STRFTIME('
276
276
  collector = visit o.right, collector
277
277
  collector << COMMA
278
278
  collector = visit o.left, collector
279
- collector << ")"
279
+ collector << ')'
280
280
  when :integer, :float, :decimal
281
- collector << "FORMAT("
281
+ collector << 'FORMAT('
282
282
  collector = visit o.left, collector
283
283
  collector << COMMA
284
284
  collector = visit o.right, collector
285
- collector << ")"
285
+ collector << ')'
286
286
  else
287
287
  collector = visit o.left, collector
288
288
  end
@@ -292,61 +292,56 @@ module ArelExtensions
292
292
  # comparators
293
293
 
294
294
  def visit_ArelExtensions_Nodes_Cast o, collector
295
- collector << "CAST("
295
+ as_attr =
296
+ case o.as_attr
297
+ when :binary then 'binary'
298
+ when :datetime then 'datetime'
299
+ when :decimal, :float, :number then 'float'
300
+ when :int then 'int'
301
+ when :string then 'char'
302
+ when :text, :ntext then 'text'
303
+ when :time then 'time'
304
+ else o.as_attr.to_s
305
+ end
306
+
307
+ collector << 'CAST('
296
308
  collector = visit o.left, collector
297
- collector << " AS "
298
- case o.as_attr
299
- when :string
300
- as_attr = Arel::Nodes::SqlLiteral.new('char')
301
- when :int
302
- as_attr = Arel::Nodes::SqlLiteral.new('int')
303
- when :decimal, :float, :number
304
- as_attr = Arel::Nodes::SqlLiteral.new('float')
305
- when :datetime
306
- as_attr = Arel::Nodes::SqlLiteral.new('datetime')
307
- when :time
308
- as_attr = Arel::Nodes::SqlLiteral.new('time')
309
- when :binary
310
- as_attr = Arel::Nodes::SqlLiteral.new('binary')
311
- when :text, :ntext
312
- as_attr = Arel::Nodes::SqlLiteral.new('text')
313
- else
314
- as_attr = Arel::Nodes::SqlLiteral.new(o.as_attr.to_s)
315
- end
316
- collector = visit as_attr, collector
317
- collector << ")"
309
+ collector << ' AS '
310
+ collector = visit Arel::Nodes::SqlLiteral.new(as_attr), collector
311
+ collector << ')'
318
312
  collector
319
313
  end
320
314
 
321
315
  def visit_ArelExtensions_Nodes_Coalesce o, collector
322
- collector << "COALESCE("
316
+ collector << 'COALESCE('
323
317
  o.expressions.each_with_index { |arg, i|
324
318
  collector << COMMA if i != 0
325
319
  collector = visit arg, collector
326
320
  }
327
- collector << ")"
321
+ collector << ')'
328
322
  collector
329
323
  end
330
324
 
331
325
  def visit_ArelExtensions_Nodes_DateDiff o, collector
332
- collector << if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time
333
- 'TIMEDIFF('
334
- else
335
- 'DATEDIFF('
336
- end
326
+ collector <<
327
+ if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time
328
+ 'TIMEDIFF('
329
+ else
330
+ 'DATEDIFF('
331
+ end
337
332
  collector = visit o.left, collector
338
333
  collector << COMMA
339
334
  collector = visit o.right, collector
340
- collector << ")"
335
+ collector << ')'
341
336
  collector
342
337
  end
343
338
 
344
339
  def visit_ArelExtensions_Nodes_DateSub o, collector
345
- collector << "DATE_SUB("
340
+ collector << 'DATE_SUB('
346
341
  collector = visit o.left, collector
347
342
  collector << COMMA
348
343
  collector = visit o.right, collector
349
- collector << ")"
344
+ collector << ')'
350
345
  collector
351
346
  end
352
347
 
@@ -363,7 +358,7 @@ module ArelExtensions
363
358
  else
364
359
  collector = visit o.left, collector
365
360
  end
366
- collector << " AS "
361
+ collector << ' AS '
367
362
  collector = visit o.right, collector
368
363
  collector
369
364
  end
@@ -371,7 +366,7 @@ module ArelExtensions
371
366
  remove_method(:visit_Arel_Nodes_Regexp) rescue nil # if Arel::Visitors::ToSql.method_defined?(:visit_Arel_Nodes_Regexp)
372
367
  def visit_Arel_Nodes_Regexp o, collector
373
368
  collector = visit o.left, collector
374
- collector << " REGEXP "
369
+ collector << ' REGEXP '
375
370
  collector = visit o.right, collector
376
371
  collector
377
372
  end
@@ -379,7 +374,7 @@ module ArelExtensions
379
374
  remove_method(:visit_Arel_Nodes_NotRegexp) rescue nil # if Arel::Visitors::ToSql.method_defined?(:visit_Arel_Nodes_NotRegexp)
380
375
  def visit_Arel_Nodes_NotRegexp o, collector
381
376
  collector = visit o.left, collector
382
- collector << " NOT REGEXP "
377
+ collector << ' NOT REGEXP '
383
378
  collector = visit o.right, collector
384
379
  collector
385
380
  end
@@ -404,35 +399,35 @@ module ArelExtensions
404
399
  end
405
400
 
406
401
  def visit_ArelExtensions_Nodes_IsNull o, collector
407
- collector << "ISNULL("
402
+ collector << 'ISNULL('
408
403
  collector = visit o.expr, collector
409
- collector << ")"
404
+ collector << ')'
410
405
  collector
411
406
  end
412
407
 
413
408
  def visit_ArelExtensions_Nodes_IsNotNull o, collector
414
- collector << "NOT ISNULL("
415
- collector = visit o.expr, collector
416
- collector << ")"
417
- collector
409
+ collector << 'NOT ISNULL('
410
+ collector = visit o.expr, collector
411
+ collector << ')'
412
+ collector
418
413
  end
419
414
 
420
415
  def visit_ArelExtensions_Nodes_Then o, collector
421
- collector << "CASE WHEN ("
416
+ collector << 'CASE WHEN ('
422
417
  collector = visit o.left, collector
423
- collector << ") THEN "
418
+ collector << ') THEN '
424
419
  collector = visit o.right, collector
425
420
  if o.expressions[2]
426
- collector << " ELSE "
421
+ collector << ' ELSE '
427
422
  collector = visit o.expressions[2], collector
428
423
  end
429
- collector << " END"
424
+ collector << ' END'
430
425
  collector
431
426
  end
432
427
 
433
428
  # Date operations
434
429
  def visit_ArelExtensions_Nodes_DateAdd o, collector
435
- collector << "DATE_ADD("
430
+ collector << 'DATE_ADD('
436
431
  collector = visit o.left, collector
437
432
  collector << COMMA
438
433
  collector = visit o.sqlite_value(o.right), collector
@@ -456,7 +451,7 @@ module ArelExtensions
456
451
  end
457
452
  collector << COMMA unless i == len
458
453
  }
459
- collector << (idx == row_nb-1 ? ')' : '), ')
454
+ collector << (idx == row_nb - 1 ? ')' : '), ')
460
455
  end
461
456
  collector
462
457
  end
@@ -478,7 +473,7 @@ module ArelExtensions
478
473
  end
479
474
  collector << COMMA unless i == len
480
475
  }
481
- collector << (idx == row_nb-1 ? ')' : '), ')
476
+ collector << (idx == row_nb - 1 ? ')' : '), ')
482
477
  end
483
478
  collector
484
479
  end
@@ -486,45 +481,45 @@ module ArelExtensions
486
481
 
487
482
  def visit_ArelExtensions_Nodes_Union o, collector
488
483
  collector = visit o.left, collector
489
- collector << " UNION "
484
+ collector << ' UNION '
490
485
  collector = visit o.right, collector
491
486
  collector
492
487
  end
493
488
 
494
489
  def visit_ArelExtensions_Nodes_UnionAll o, collector
495
490
  collector = visit o.left, collector
496
- collector << " UNION ALL "
491
+ collector << ' UNION ALL '
497
492
  collector = visit o.right, collector
498
493
  collector
499
494
  end
500
495
 
501
496
  def visit_ArelExtensions_Nodes_Case o, collector
502
- collector << "CASE "
497
+ collector << 'CASE '
503
498
  if o.case
504
499
  visit o.case, collector
505
- collector << " "
500
+ collector << ' '
506
501
  end
507
502
  o.conditions.each do |condition|
508
503
  visit condition, collector
509
- collector << " "
504
+ collector << ' '
510
505
  end
511
506
  if o.default
512
507
  visit o.default, collector
513
- collector << " "
508
+ collector << ' '
514
509
  end
515
- collector << "END"
510
+ collector << 'END'
516
511
  end
517
512
 
518
513
  def visit_ArelExtensions_Nodes_Case_When o, collector
519
- collector << "WHEN "
520
- visit Arel::Nodes.build_quoted(o.left), collector
521
- collector << " THEN "
522
- visit Arel::Nodes.build_quoted(o.right), collector
514
+ collector << 'WHEN '
515
+ visit Arel.quoted(o.left), collector
516
+ collector << ' THEN '
517
+ visit Arel.quoted(o.right), collector
523
518
  end
524
519
 
525
520
  def visit_ArelExtensions_Nodes_Case_Else o, collector
526
- collector << "ELSE "
527
- visit Arel::Nodes.build_quoted(o.expr), collector
521
+ collector << 'ELSE '
522
+ visit Arel.quoted(o.expr), collector
528
523
  end
529
524
 
530
525
  def visit_ArelExtensions_Nodes_FormattedNumber o, collector
@@ -534,26 +529,26 @@ module ArelExtensions
534
529
  remove_method(:visit_Arel_Nodes_LessThan) rescue nil
535
530
  def visit_Arel_Nodes_LessThan o, collector
536
531
  collector = visit o.left, collector
537
- collector << " < "
532
+ collector << ' < '
538
533
  visit o.right, collector
539
534
  end
540
535
 
541
536
  def visit_ArelExtensions_Nodes_Std o, collector
542
- collector << "STD("
537
+ collector << 'STD('
543
538
  visit o.left, collector
544
- collector << ")"
539
+ collector << ')'
545
540
  collector
546
541
  end
547
542
 
548
543
  def visit_ArelExtensions_Nodes_Variance o, collector
549
- collector << "VARIANCE("
544
+ collector << 'VARIANCE('
550
545
  visit o.left, collector
551
- collector << ")"
546
+ collector << ')'
552
547
  collector
553
548
  end
554
549
 
555
550
  def visit_ArelExtensions_Nodes_LevenshteinDistance o, collector
556
- collector << "LEVENSHTEIN_DISTANCE("
551
+ collector << 'LEVENSHTEIN_DISTANCE('
557
552
  collector = visit o.left, collector
558
553
  collector << COMMA
559
554
  collector = visit o.right, collector
@@ -591,19 +586,19 @@ module ArelExtensions
591
586
  when 1
592
587
  collector = visit o.children[0], collector
593
588
  else
594
- collector << '('
595
- o.children.each_with_index { |arg, i|
596
- if i != 0
597
- collector << ') OR ('
598
- end
599
- collector = visit arg, collector
600
- }
601
- collector << ')'
589
+ collector << '('
590
+ o.children.each_with_index { |arg, i|
591
+ if i != 0
592
+ collector << ') OR ('
593
+ end
594
+ collector = visit arg, collector
595
+ }
596
+ collector << ')'
602
597
  end
603
598
  collector
604
599
  end
605
600
 
606
- def json_value(o,v)
601
+ def json_value(o, v)
607
602
  case o.type_of_node(v)
608
603
  when :string
609
604
  Arel.when(v.is_null).then(make_json_null).else(make_json_string(v))
@@ -623,26 +618,26 @@ module ArelExtensions
623
618
  end
624
619
  end
625
620
 
626
- def visit_ArelExtensions_Nodes_Json o,collector
621
+ def visit_ArelExtensions_Nodes_Json o, collector
627
622
  case o.dict
628
623
  when Array
629
- res = Arel::Nodes.build_quoted('[')
630
- o.dict.each.with_index do |v,i|
624
+ res = Arel.quoted('[')
625
+ o.dict.each.with_index do |v, i|
631
626
  if i != 0
632
627
  res += ', '
633
628
  end
634
- res += json_value(o,v)
629
+ res += json_value(o, v)
635
630
  end
636
631
  res += ']'
637
632
  collector = visit res, collector
638
633
  when Hash
639
- res = Arel::Nodes.build_quoted('{')
640
- o.dict.each.with_index do |(k,v),i|
634
+ res = Arel.quoted('{')
635
+ o.dict.each.with_index do |(k, v), i|
641
636
  if i != 0
642
637
  res += ', '
643
638
  end
644
639
  res += make_json_string(ArelExtensions::Nodes::Cast.new([k, :string])) + ': '
645
- res += json_value(o,v)
640
+ res += json_value(o, v)
646
641
  end
647
642
  res += '}'
648
643
  collector = visit res, collector
@@ -654,17 +649,20 @@ module ArelExtensions
654
649
 
655
650
  def visit_ArelExtensions_Nodes_JsonGroup o, collector
656
651
  if o.as_array
657
- res = Arel::Nodes.build_quoted('[') + (o.orders ? o.dict.group_concat(', ', order: Array(o.orders)) : o.dict.group_concat(', ')).coalesce('') + ']'
652
+ res =
653
+ Arel.quoted('[') \
654
+ + (o.orders ? o.dict.group_concat(', ', order: Array(o.orders)) : o.dict.group_concat(', ')).coalesce('') \
655
+ + ']'
658
656
  collector = visit res, collector
659
657
  else
660
- res = Arel::Nodes.build_quoted('{')
658
+ res = Arel.quoted('{')
661
659
  orders = o.orders || o.dict.keys
662
- o.dict.each.with_index do |(k,v),i|
660
+ o.dict.each.with_index do |(k, v), i|
663
661
  if i != 0
664
662
  res = res + ', '
665
663
  end
666
664
  kv = make_json_string(ArelExtensions::Nodes::Cast.new([k, :string])) + ': '
667
- kv += json_value(o,v)
665
+ kv += json_value(o, v)
668
666
  res = res + kv.group_concat(', ', order: Array(orders)).coalesce('')
669
667
  end
670
668
  res = res + '}'