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
@@ -1,5 +1,3 @@
1
- require 'arel_extensions/helpers'
2
-
3
1
  require 'arel_extensions/nodes'
4
2
  require 'arel_extensions/nodes/function'
5
3
  require 'arel_extensions/nodes/concat'
@@ -18,16 +16,16 @@ module ArelExtensions
18
16
  # Date and integer adds or subtracts a specified time interval from a date.
19
17
  def +(other)
20
18
  case self
21
- when Arel::Nodes::Quoted
22
- return self.concat(other)
23
- when Arel::Nodes::Grouping
24
- if self.expr.left.is_a?(String) || self.expr.right.is_a?(String)
25
- return self.concat(other)
26
- else
27
- return Arel.grouping(Arel::Nodes::Addition.new self, other)
28
- end
29
- when ArelExtensions::Nodes::Function,ArelExtensions::Nodes::Case
30
- return case self.return_type
19
+ when Arel::Nodes::Quoted
20
+ self.concat(other)
21
+ when Arel::Nodes::Grouping
22
+ if self.expr.left.is_a?(String) || self.expr.right.is_a?(String)
23
+ self.concat(other)
24
+ else
25
+ Arel.grouping(Arel::Nodes::Addition.new self, other)
26
+ end
27
+ when ArelExtensions::Nodes::Function, ArelExtensions::Nodes::Case
28
+ case self.return_type
31
29
  when :string, :text
32
30
  self.concat(other)
33
31
  when :integer, :decimal, :float, :number, :int
@@ -40,17 +38,22 @@ module ArelExtensions
40
38
  when Arel::Nodes::Function
41
39
  Arel.grouping(Arel::Nodes::Addition.new self, other)
42
40
  else
43
- col = self.respond_to?(:relation)? ArelExtensions::column_of(self.relation.table_name, self.name.to_s) : nil
44
- if (!col) # if the column doesn't exist in the database
45
- Arel.grouping(Arel::Nodes::Addition.new(self, Arel::Nodes.build_quoted(other)))
41
+ col =
42
+ if self.is_a?(Arel::Attribute) && self.respond_to?(:type_caster) && self.able_to_type_cast?
43
+ self.type_caster
44
+ else
45
+ Arel.column_of(self.relation.table_name, self.name.to_s) if self.respond_to?(:relation)
46
+ end
47
+ if !col # if the column doesn't exist in the database
48
+ Arel.grouping(Arel::Nodes::Addition.new(self, Arel.quoted(other)))
46
49
  else
47
50
  arg = col.type
48
- if arg == :integer || (!arg)
51
+ if arg == :integer || !arg
49
52
  other = other.to_i if other.is_a?(String)
50
- Arel.grouping(Arel::Nodes::Addition.new self, Arel::Nodes.build_quoted(other))
53
+ Arel.grouping(Arel::Nodes::Addition.new self, Arel.quoted(other))
51
54
  elsif arg == :decimal || arg == :float
52
55
  other = Arel.sql(other) if other.is_a?(String) # Arel should accept Float & BigDecimal!
53
- Arel.grouping(Arel::Nodes::Addition.new self, Arel::Nodes.build_quoted(other))
56
+ Arel.grouping(Arel::Nodes::Addition.new self, Arel.quoted(other))
54
57
  elsif arg == :datetime || arg == :date
55
58
  ArelExtensions::Nodes::DateAdd.new [self, other]
56
59
  elsif arg == :string || arg == :text
@@ -66,34 +69,44 @@ module ArelExtensions
66
69
  case self
67
70
  when Arel::Nodes::Grouping
68
71
  if self.expr.left.is_a?(Date) || self.expr.left.is_a?(DateTime)
69
- Arel.grouping(ArelExtensions::Nodes::DateSub.new [self, Arel::Nodes.build_quoted(other)])
72
+ Arel.grouping(ArelExtensions::Nodes::DateSub.new [self, Arel.quoted(other)])
70
73
  else
71
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel::Nodes.build_quoted(other)))
74
+ Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
72
75
  end
73
76
  when ArelExtensions::Nodes::Function, ArelExtensions::Nodes::Case
74
77
  case self.return_type
75
78
  when :string, :text # ???
76
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel::Nodes.build_quoted(other))) # ??
79
+ Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other))) # ??
77
80
  when :integer, :decimal, :float, :number
78
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel::Nodes.build_quoted(other)))
81
+ Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
79
82
  when :date, :datetime
80
- ArelExtensions::Nodes::DateSub.new [self, Arel::Nodes.build_quoted(other)]
83
+ ArelExtensions::Nodes::DateSub.new [self, Arel.quoted(other)]
81
84
  else
82
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel::Nodes.build_quoted(other)))
85
+ Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
83
86
  end
84
87
  when Arel::Nodes::Function
85
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel::Nodes.build_quoted(other)))
88
+ Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
86
89
  else
87
- col = ArelExtensions::column_of(self.relation.table_name, self.name.to_s)
88
- if (!col) # if the column doesn't exist in the database
89
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel::Nodes.build_quoted(other)))
90
+ col =
91
+ if self.is_a?(Arel::Attribute) && self.respond_to?(:type_caster) && self.able_to_type_cast?
92
+ self.type_caster
93
+ else
94
+ Arel.column_of(self.relation.table_name, self.name.to_s) if self.respond_to?(:relation)
95
+ end
96
+ if !col # if the column doesn't exist in the database
97
+ Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
90
98
  else
91
99
  arg = col.type
92
100
  if (arg == :date || arg == :datetime)
93
101
  case other
94
102
  when Arel::Attributes::Attribute
95
- col2 = ArelExtensions::column_of(other.relation.table_name, other.name.to_s)
96
- if (!col2) # if the column doesn't exist in the database
103
+ col2 =
104
+ if other.is_a?(Arel::Attribute) && other.respond_to?(:type_caster) && other.able_to_type_cast?
105
+ other.type_caster
106
+ else
107
+ Arel.column_of(other.relation.table_name, other.name.to_s) if other.respond_to?(:relation)
108
+ end
109
+ if !col2 # if the column doesn't exist in the database
97
110
  ArelExtensions::Nodes::DateSub.new [self, other]
98
111
  else
99
112
  arg2 = col2.type
@@ -117,7 +130,7 @@ module ArelExtensions
117
130
  when String
118
131
  Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.sql(other)))
119
132
  else
120
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel::Nodes.build_quoted(other)))
133
+ Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
121
134
  end
122
135
  end
123
136
  end
@@ -15,7 +15,7 @@ module ArelExtensions
15
15
  def * other
16
16
  case other
17
17
  when Float, BigDecimal
18
- super(Arel::Nodes.build_quoted(other))
18
+ super(Arel.quoted(other))
19
19
  else
20
20
  super(other)
21
21
  end
@@ -25,7 +25,7 @@ module ArelExtensions
25
25
  def / other
26
26
  case other
27
27
  when Float, BigDecimal
28
- super(Arel::Nodes.build_quoted(other))
28
+ super(Arel.quoted(other))
29
29
  else
30
30
  super(other)
31
31
  end
@@ -33,32 +33,32 @@ module ArelExtensions
33
33
 
34
34
  # Abs function returns the absolute value of a number passed as argument #
35
35
  def abs
36
- ArelExtensions::Nodes::Abs.new [self]
36
+ ArelExtensions::Nodes::Abs.new [self]
37
37
  end
38
38
 
39
39
  # will rounded up any positive or negative decimal value within the function upwards #
40
40
  def ceil
41
- ArelExtensions::Nodes::Ceil.new [self]
41
+ ArelExtensions::Nodes::Ceil.new [self]
42
42
  end
43
43
 
44
44
  # function rounded up any positive or negative decimal value down to the next least integer
45
45
  def floor
46
- ArelExtensions::Nodes::Floor.new [self]
46
+ ArelExtensions::Nodes::Floor.new [self]
47
47
  end
48
48
 
49
49
  # function gives the base 10 log
50
50
  def log10
51
- ArelExtensions::Nodes::Log10.new [self]
51
+ ArelExtensions::Nodes::Log10.new [self]
52
52
  end
53
53
 
54
54
  # function gives the power of a number
55
55
  def pow exposant = 0
56
- ArelExtensions::Nodes::Power.new [self,exposant]
56
+ ArelExtensions::Nodes::Power.new [self, exposant]
57
57
  end
58
58
 
59
59
  # function gives the power of a number
60
60
  def power exposant = 0
61
- ArelExtensions::Nodes::Power.new [self,exposant]
61
+ ArelExtensions::Nodes::Power.new [self, exposant]
62
62
  end
63
63
 
64
64
  # Aggregate Functions
@@ -71,7 +71,7 @@ module ArelExtensions
71
71
  end
72
72
 
73
73
  def sum opts = {unbiased: true}
74
- if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("9.0.0")
74
+ if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('9.0.0')
75
75
  Arel::Nodes::Sum.new [self]
76
76
  else
77
77
  ArelExtensions::Nodes::Sum.new self, **opts
@@ -86,17 +86,17 @@ module ArelExtensions
86
86
 
87
87
  # function is used to round a numeric field to the number of decimals specified
88
88
  def round precision = nil
89
- if precision
90
- ArelExtensions::Nodes::Round.new [self, precision]
91
- else
92
- ArelExtensions::Nodes::Round.new [self]
93
- end
89
+ if precision
90
+ ArelExtensions::Nodes::Round.new [self, precision]
91
+ else
92
+ ArelExtensions::Nodes::Round.new [self]
93
+ end
94
94
  end
95
95
 
96
96
  # function returning a number at a specific format
97
97
  def format_number format_string, locale = nil
98
98
  begin
99
- sprintf(format_string,0) # this line is to get the right error message if the format_string is not correct
99
+ sprintf(format_string, 0) # this line is to get the right error message if the format_string is not correct
100
100
  m = /^(.*)%([ #+\-0]*)([1-9][0-9]+|[1-9]?)[.]?([0-9]*)([a-zA-Z])(.*)$/.match(format_string)
101
101
  opts = {
102
102
  prefix: m[1],
@@ -108,10 +108,10 @@ module ArelExtensions
108
108
  locale: locale,
109
109
  original_string: format_string
110
110
  }
111
- # opts = {:locale => 'fr_FR', :type => "e"/"f"/"d", :prefix => "$ ", :suffix => " %", :flags => " +-#0", :width => 5, :precision => 6}
112
- ArelExtensions::Nodes::FormattedNumber.new [self,opts]
111
+ # opts = {locale: 'fr_FR', type: "e"/"f"/"d", prefix: "$ ", suffix: " %", flags: " +-#0", width: 5, precision: 6}
112
+ ArelExtensions::Nodes::FormattedNumber.new [self, opts]
113
113
  rescue Exception
114
- Arel::Nodes.build_quoted('Wrong Format')
114
+ Arel.quoted('Wrong Format')
115
115
  end
116
116
  end
117
117
  end
File without changes
File without changes
@@ -16,7 +16,7 @@ module ArelExtensions
16
16
  RETURN_TYPE = :boolean
17
17
 
18
18
  def initialize expr
19
- super expr.first
19
+ super expr.first
20
20
  end
21
21
  end
22
22
  end
@@ -1,8 +1,6 @@
1
- require 'arel_extensions/helpers'
2
-
3
1
  module ArelExtensions
4
2
  module Nodes
5
- if Gem::Version.new(Arel::VERSION) < Gem::Version.new("7.1.0")
3
+ if Gem::Version.new(Arel::VERSION) < Gem::Version.new('7.1.0')
6
4
  class Case < Arel::Nodes::Node
7
5
  include Arel::Expressions
8
6
  include Arel::Math
@@ -46,7 +44,7 @@ module ArelExtensions
46
44
 
47
45
  def return_type
48
46
  obj = if @conditions.length > 0
49
- @conditions.last.right
47
+ @conditions.last.right
50
48
  elsif @default
51
49
  @default.expr
52
50
  end
@@ -56,10 +54,10 @@ module ArelExtensions
56
54
  case obj
57
55
  when Integer, Float
58
56
  :number
59
- when Date, DateTime,Time
57
+ when Date, DateTime, Time
60
58
  :datetime
61
59
  when Arel::Attributes::Attribute
62
- ArelExtensions::column_of(obj.relation.table_name, obj.name.to_s)&.type || :string
60
+ Arel.column_of(obj.relation.table_name, obj.name.to_s)&.type || :string
63
61
  else
64
62
  :string
65
63
  end
@@ -19,11 +19,11 @@ module ArelExtensions
19
19
  when 'text', :text, 'ntext', :ntext
20
20
  @as_attr = expr[1].to_sym
21
21
  @return_type = :string
22
- when :datetime, 'datetime','smalldatetime'
22
+ when :datetime, 'datetime', 'smalldatetime'
23
23
  @return_type = :datetime
24
- when :time,'time'
24
+ when :time, 'time'
25
25
  @return_type = :time
26
- when :date,'date'
26
+ when :date, 'date'
27
27
  @return_type = :date
28
28
  when :binary, 'binary', 'varbinary', 'image'
29
29
  @return_type = :binary
@@ -32,13 +32,13 @@ module ArelExtensions
32
32
  @as_attr = :string
33
33
  end
34
34
  tab = [convert_to_node(expr.first)]
35
- return super(tab)
35
+ super(tab)
36
36
  end
37
37
 
38
38
  def +(other)
39
39
  case @return_type
40
40
  when :string
41
- return ArelExtensions::Nodes::Concat.new [self, other]
41
+ ArelExtensions::Nodes::Concat.new [self, other]
42
42
  when :ruby_time
43
43
  ArelExtensions::Nodes::DateAdd.new [self, other]
44
44
  else
File without changes
File without changes
@@ -27,7 +27,7 @@ module ArelExtensions
27
27
  when DateTime, Time
28
28
  @left_node_type = :ruby_time
29
29
  end
30
- return super(tab)
30
+ super(tab)
31
31
  end
32
32
  end
33
33
  end
@@ -1,17 +1,17 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Collate < Function
4
- RETURN_TYPE = :string
4
+ RETURN_TYPE = :string
5
5
 
6
- attr_accessor :ai, :ci, :option
6
+ attr_accessor :ai, :ci, :option
7
7
 
8
- def initialize left, option = nil, ai = false, ci = false
9
- @ai = ai
10
- @ci = ci
11
- @option = option
12
- tab = [convert_to_node(left)]
13
- return super(tab)
14
- end
8
+ def initialize left, option = nil, ai = false, ci = false
9
+ @ai = ai
10
+ @ci = ci
11
+ @option = option
12
+ tab = [convert_to_node(left)]
13
+ super(tab)
14
+ end
15
15
  end
16
16
  end
17
17
  end
@@ -13,10 +13,10 @@ module ArelExtensions::Nodes
13
13
  end
14
14
  }.flatten.reduce([]) { |res, b|
15
15
  # concatenate successive literal strings.
16
- if b.is_a?(Arel::Nodes::Quoted) && b.expr == ""
16
+ if b.is_a?(Arel::Nodes::Quoted) && b.expr == ''
17
17
  res
18
18
  elsif res.last && res.last.is_a?(Arel::Nodes::Quoted) && b.is_a?(Arel::Nodes::Quoted)
19
- res[-1] = Arel::Nodes.build_quoted(res.last.expr + b.expr)
19
+ res[-1] = Arel.quoted(res.last.expr + b.expr)
20
20
  else
21
21
  res << b
22
22
  end
@@ -19,7 +19,7 @@ module ArelExtensions
19
19
  when DateTime, Time
20
20
  @left_node_type = :ruby_time
21
21
  end
22
- res << ([:date, :ruby_date].include?(@left_node_type) ? convert_to_date_node(col) : convert_to_datetime_node(col))
22
+ res << (%i[date ruby_date].include?(@left_node_type) ? convert_to_date_node(col) : convert_to_datetime_node(col))
23
23
  case expr[1]
24
24
  when Arel::Nodes::Node, Arel::Attributes::Attribute
25
25
  @right_node_type = type_of_attribute(expr[1])
@@ -28,7 +28,7 @@ module ArelExtensions
28
28
  when DateTime, Time
29
29
  @right_node_type = :ruby_time
30
30
  end
31
- res << ([:date, :ruby_date].include?(@left_node_type) ? convert_to_date_node(expr[1]) : convert_to_datetime_node(expr[1]))
31
+ res << (%i[date ruby_date].include?(@left_node_type) ? convert_to_date_node(expr[1]) : convert_to_datetime_node(expr[1]))
32
32
  super res
33
33
  end
34
34
  end
@@ -43,19 +43,19 @@ module ArelExtensions
43
43
  tab = expr.map do |arg|
44
44
  convert(arg)
45
45
  end
46
- return super(tab)
46
+ super(tab)
47
47
  end
48
48
 
49
49
  def sqlite_value
50
50
  v = self.expressions.last
51
51
  if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === v
52
52
  if @date_type == :date
53
- return Arel::Nodes.build_quoted((v.value >= 0 ? '+' : '-') + v.inspect)
53
+ Arel.quoted((v.value >= 0 ? '+' : '-') + v.inspect)
54
54
  elsif @date_type == :datetime
55
- return Arel::Nodes.build_quoted((v.value >= 0 ? '+' : '-') + v.inspect)
55
+ Arel.quoted((v.value >= 0 ? '+' : '-') + v.inspect)
56
56
  end
57
57
  else
58
- return v
58
+ v
59
59
  end
60
60
  end
61
61
 
@@ -115,7 +115,7 @@ module ArelExtensions
115
115
  v ||= self.expressions.last
116
116
  if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === v
117
117
  if @date_type == :date
118
- v.to_i / (24*3600)
118
+ v.to_i / (24 * 3600)
119
119
  elsif @date_type == :datetime
120
120
  if v.parts.size == 1
121
121
  # first entry in the dict v.parts; one of [:years, :months, :weeks, :days, :hours, :minutes, :seconds]
@@ -155,9 +155,9 @@ module ArelExtensions
155
155
  if ArelExtensions::Nodes::Duration === v
156
156
  v.with_interval = true
157
157
  case v.left
158
- when 'd','m','y'
158
+ when 'd', 'm', 'y'
159
159
  Arel.sql('day')
160
- when 'h','mn','s'
160
+ when 'h', 'mn', 's'
161
161
  Arel.sql('second')
162
162
  when /i\z/
163
163
  Arel.sql(ArelExtensions::Visitors::MSSQL::LOADED_VISITOR::DATE_MAPPING[v.left[0..-2]])
@@ -179,7 +179,7 @@ module ArelExtensions
179
179
  when DateTime, Time, Date
180
180
  raise(ArgumentError, "#{object.class} cannot be converted to Integer")
181
181
  when String
182
- Arel::Nodes.build_quoted(object)
182
+ Arel.quoted(object)
183
183
  else
184
184
  raise(ArgumentError, "#{object.class} cannot be converted to Integer")
185
185
  end
File without changes
File without changes
File without changes
File without changes
@@ -3,10 +3,10 @@ module ArelExtensions
3
3
  class FormattedNumber < Function
4
4
  RETURN_TYPE = :string
5
5
 
6
- attr_accessor :locale, :prefix, :suffix, :flags, :scientific_notation, :width,:precision, :type, :original_string
6
+ attr_accessor :locale, :prefix, :suffix, :flags, :scientific_notation, :width, :precision, :type, :original_string
7
7
 
8
8
  def initialize expr
9
- # expr[1] = {:locale => 'fr_FR', :type => "e"/"f"/"d", :prefix => "$ ", :suffix => " %", :flags => " +-#0", :width => 5, :precision => 6}
9
+ # expr[1] = {locale: 'fr_FR', type: "e"/"f"/"d", prefix: "$ ", suffix: " %", flags: " +-#0", width: 5, precision: 6}
10
10
  col = expr.first
11
11
  @locale = expr[1][:locale]
12
12
  @prefix = expr[1][:prefix]
@@ -22,14 +22,14 @@ module ArelExtensions
22
22
 
23
23
  def as other
24
24
  res = Arel::Nodes::As.new(self.clone, Arel.sql(other))
25
- if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("9.0.0")
25
+ if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('9.0.0')
26
26
  self.alias = Arel.sql(other)
27
27
  end
28
28
  res
29
29
  end
30
30
 
31
31
  def expr
32
- @expressions.first
32
+ @expressions.first
33
33
  end
34
34
 
35
35
  def left
@@ -41,17 +41,17 @@ module ArelExtensions
41
41
  end
42
42
 
43
43
  def ==(other)
44
- Arel::Nodes::Equality.new self, Arel::Nodes.build_quoted(other, self)
44
+ Arel::Nodes::Equality.new self, Arel.quoted(other, self)
45
45
  end
46
46
 
47
47
  def !=(other)
48
- Arel::Nodes::NotEqual.new self, Arel::Nodes.build_quoted(other, self)
48
+ Arel::Nodes::NotEqual.new self, Arel.quoted(other, self)
49
49
  end
50
50
 
51
51
  def type_of_attribute(att)
52
52
  case att
53
53
  when Arel::Attributes::Attribute
54
- ArelExtensions::column_of(att.relation.table_name, att.name.to_s)&.type || att
54
+ Arel.column_of(att.relation.table_name, att.name.to_s)&.type || att
55
55
  when ArelExtensions::Nodes::Function
56
56
  att.return_type
57
57
  # else
@@ -64,13 +64,13 @@ module ArelExtensions
64
64
  when Arel::Attributes::Attribute, Arel::Nodes::Node, Integer
65
65
  object
66
66
  when DateTime
67
- Arel::Nodes.build_quoted(object, self)
67
+ Arel.quoted(object, self)
68
68
  when Time
69
- Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
69
+ Arel.quoted(object.strftime('%H:%M:%S'), self)
70
70
  when MBSTRING, String, Symbol
71
- Arel::Nodes.build_quoted(object.to_s)
71
+ Arel.quoted(object.to_s)
72
72
  when Date
73
- Arel::Nodes.build_quoted(object.to_s, self)
73
+ Arel.quoted(object.to_s, self)
74
74
  when NilClass
75
75
  Arel.sql('NULL')
76
76
  when ActiveSupport::Duration
@@ -87,7 +87,7 @@ module ArelExtensions
87
87
  when Arel::Nodes::Node
88
88
  object
89
89
  when Integer
90
- Arel::Nodes.build_quoted(object.to_s)
90
+ Arel.quoted(object.to_s)
91
91
  when Arel::Attributes::Attribute
92
92
  case self.type_of_attribute(object)
93
93
  when :date
@@ -98,17 +98,17 @@ module ArelExtensions
98
98
  object
99
99
  end
100
100
  when DateTime
101
- Arel::Nodes.build_quoted(object, self)
101
+ Arel.quoted(object, self)
102
102
  when Time
103
- Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
103
+ Arel.quoted(object.strftime('%H:%M:%S'), self)
104
104
  when MBSTRING, String
105
- Arel::Nodes.build_quoted(object.to_s)
105
+ Arel.quoted(object.to_s)
106
106
  when Date
107
- Arel::Nodes.build_quoted(object, self)
107
+ Arel.quoted(object, self)
108
108
  when NilClass
109
109
  Arel.sql(nil)
110
110
  when ActiveSupport::Duration
111
- Arel::Nodes.build_quoted(object.to_i.to_s)
111
+ Arel.quoted(object.to_i.to_s)
112
112
  else
113
113
  raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
114
114
  end
@@ -119,11 +119,11 @@ module ArelExtensions
119
119
  when Arel::Attributes::Attribute, Arel::Nodes::Node
120
120
  object
121
121
  when DateTime, Time
122
- Arel::Nodes.build_quoted(Date.new(object.year, object.month, object.day), self)
122
+ Arel.quoted(Date.new(object.year, object.month, object.day), self)
123
123
  when MBSTRING, String
124
- Arel::Nodes.build_quoted(Date.parse(object.to_s), self)
124
+ Arel.quoted(Date.parse(object.to_s), self)
125
125
  when Date
126
- Arel::Nodes.build_quoted(object, self)
126
+ Arel.quoted(object, self)
127
127
  else
128
128
  raise(ArgumentError, "#{object.class} cannot be converted to Date")
129
129
  end
@@ -134,11 +134,11 @@ module ArelExtensions
134
134
  when Arel::Attributes::Attribute, Arel::Nodes::Node
135
135
  object
136
136
  when DateTime, Time
137
- Arel::Nodes.build_quoted(object, self)
137
+ Arel.quoted(object, self)
138
138
  when MBSTRING, String
139
- Arel::Nodes.build_quoted(Time.parse(object.to_s), self)
139
+ Arel.quoted(Time.parse(object.to_s), self)
140
140
  when Date
141
- Arel::Nodes.build_quoted(Time.utc(object.year, object.month, object.day, 0, 0, 0), self)
141
+ Arel.quoted(Time.utc(object.year, object.month, object.day, 0, 0, 0), self)
142
142
  else
143
143
  raise(ArgumentError, "#{object.class} cannot be converted to Datetime")
144
144
  end
File without changes
@@ -11,15 +11,15 @@ module ArelExtensions
11
11
  end
12
12
 
13
13
  def get key
14
- JsonGet.new(self,key)
14
+ JsonGet.new(self, key)
15
15
  end
16
16
 
17
17
  def set key, value
18
- JsonSet.new(self,key,value)
18
+ JsonSet.new(self, key, value)
19
19
  end
20
20
 
21
21
  def group as_array = true, orders = nil
22
- JsonGroup.new(self,as_array, orders)
22
+ JsonGroup.new(self, as_array, orders)
23
23
  end
24
24
 
25
25
  def hash
@@ -32,19 +32,19 @@ module ArelExtensions
32
32
  n.dict
33
33
  when Array
34
34
  n.map{|e|
35
- (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_json_node(e)
35
+ (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_json_node(e)
36
36
  }
37
37
  when Hash
38
- n.reduce({}){|acc,v|
38
+ n.reduce({}){|acc, v|
39
39
  acc[convert_to_json_node(v[0])] = (v[1].is_a?(Array) || v[1].is_a?(Hash)) ? Json.new(v[1]) : convert_to_json_node(v[1])
40
40
  acc
41
41
  }
42
42
  when String, Numeric, TrueClass, FalseClass
43
43
  convert_to_node(n)
44
44
  when Date
45
- convert_to_node(n.strftime("%Y-%m-%d"))
45
+ convert_to_node(n.strftime('%Y-%m-%d'))
46
46
  when DateTime, Time
47
- convert_to_node(n.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
47
+ convert_to_node(n.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'))
48
48
  when NilClass
49
49
  Arel.null
50
50
  when Arel::SelectManager
File without changes
@@ -4,7 +4,7 @@ module ArelExtensions
4
4
  RETURN_TYPE = :number
5
5
 
6
6
  def initialize expr
7
- super [convert_to_node(expr.first), Arel::Nodes.build_quoted(expr[1])]
7
+ super [convert_to_node(expr.first), Arel.quoted(expr[1])]
8
8
  end
9
9
  end
10
10
  end
@@ -7,7 +7,7 @@ module ArelExtensions
7
7
  tab = expr.map do |arg|
8
8
  convert_to_node(arg)
9
9
  end
10
- return super(tab)
10
+ super(tab)
11
11
  end
12
12
  end
13
13
  end
File without changes
@@ -4,7 +4,7 @@ module ArelExtensions
4
4
  attr_accessor :case_sensitive if Arel::VERSION.to_i < 7
5
5
 
6
6
  def initialize(left, right, escape = nil)
7
- r = Arel::Nodes.build_quoted(right)
7
+ r = Arel.quoted(right)
8
8
  if Arel::VERSION.to_i < 7 # managed by default in version 7+ (rails 5), so useful for rails 3 & 4
9
9
  super(left, r, escape)
10
10
  @case_sensitive = false