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
File without changes
File without changes
File without changes
@@ -7,11 +7,11 @@ module ArelExtensions
7
7
  tab = expr.map { |arg|
8
8
  convert_to_node(arg)
9
9
  }
10
- return super(tab)
10
+ super(tab)
11
11
  end
12
12
 
13
13
  def +(other)
14
- return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
14
+ ArelExtensions::Nodes::Concat.new(self.expressions + [other])
15
15
  end
16
16
  end
17
17
  end
@@ -8,7 +8,7 @@ module ArelExtensions
8
8
  @left = convert_to_node(left)
9
9
  @pattern = convert_to_node(pattern)
10
10
  @substitute = convert_to_node(substitute)
11
- super([@left,@pattern,@substitute])
11
+ super([@left, @pattern, @substitute])
12
12
  end
13
13
  end
14
14
 
@@ -20,7 +20,7 @@ module ArelExtensions
20
20
  @left = convert_to_node(left)
21
21
  @pattern = (pattern.is_a?(Regexp) ? pattern : %r[#{pattern}])
22
22
  @substitute = convert_to_node(substitute)
23
- super([@left,@pattern,@substitute])
23
+ super([@left, @pattern, @substitute])
24
24
  end
25
25
  end
26
26
  end
File without changes
@@ -7,11 +7,11 @@ module ArelExtensions
7
7
  RETURN_TYPE = :string
8
8
 
9
9
  def ==(other)
10
- Arel::Nodes::Equality.new self, Arel::Nodes.build_quoted(other, self)
10
+ Arel::Nodes::Equality.new self, Arel.quoted(other, self)
11
11
  end
12
12
 
13
13
  def !=(other)
14
- Arel::Nodes::NotEqual.new self, Arel::Nodes.build_quoted(other, self)
14
+ Arel::Nodes::NotEqual.new self, Arel.quoted(other, self)
15
15
  end
16
16
  end
17
17
  end
File without changes
@@ -8,7 +8,7 @@ module ArelExtensions
8
8
  if expr[2]
9
9
  tab << convert_to_node(expr[2])
10
10
  end
11
- return super(tab)
11
+ super(tab)
12
12
  end
13
13
  end
14
14
  end
File without changes
@@ -5,7 +5,7 @@ module ArelExtensions
5
5
  tab = expr.map { |arg|
6
6
  convert_to_node(arg)
7
7
  }
8
- return super(tab)
8
+ super(tab)
9
9
  end
10
10
  end
11
11
  end
@@ -7,11 +7,11 @@ module ArelExtensions
7
7
  tab = expr.map { |arg|
8
8
  convert_to_node(arg)
9
9
  }
10
- return super(tab)
10
+ super(tab)
11
11
  end
12
12
 
13
13
  def +(other)
14
- return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
14
+ ArelExtensions::Nodes::Concat.new(self.expressions + [other])
15
15
  end
16
16
  end
17
17
 
@@ -1,16 +1,16 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Union < Arel::Nodes::Union
4
- def initialize left,right
5
- return super(left,right)
4
+ def initialize left, right
5
+ super(left, right)
6
6
  end
7
7
 
8
8
  def +(other)
9
- return ArelExtensions::Nodes::Union.new(self,other)
9
+ ArelExtensions::Nodes::Union.new(self, other)
10
10
  end
11
11
 
12
12
  def union(other)
13
- return ArelExtensions::Nodes::UnionAll.new(self,other)
13
+ ArelExtensions::Nodes::UnionAll.new(self, other)
14
14
  end
15
15
 
16
16
  def as other
@@ -1,12 +1,12 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class UnionAll < Arel::Nodes::UnionAll
4
- def initialize left,right
5
- return super(left,right)
4
+ def initialize left, right
5
+ super(left, right)
6
6
  end
7
7
 
8
8
  def union_all(other)
9
- return ArelExtensions::Nodes::UnionAll.new(self,other)
9
+ ArelExtensions::Nodes::UnionAll.new(self, other)
10
10
  end
11
11
 
12
12
  def as other
File without changes
File without changes
File without changes
@@ -1,14 +1,14 @@
1
1
  module ArelExtensions
2
2
  module Predications
3
3
  def when right, expression = nil
4
- ArelExtensions::Nodes::Case.new(self).when(right,expression)
4
+ ArelExtensions::Nodes::Case.new(self).when(right, expression)
5
5
  end
6
6
 
7
- def matches(other, escape = nil,case_sensitive = nil)
7
+ def matches(other, escape = nil, case_sensitive = nil)
8
8
  if Arel::VERSION.to_i < 7
9
- Arel::Nodes::Matches.new(self, Arel::Nodes.build_quoted(other), escape)
9
+ Arel::Nodes::Matches.new(self, Arel.quoted(other), escape)
10
10
  else
11
- Arel::Nodes::Matches.new(self, Arel::Nodes.build_quoted(other), escape, case_sensitive)
11
+ Arel::Nodes::Matches.new(self, Arel.quoted(other), escape, case_sensitive)
12
12
  end
13
13
  end
14
14
 
@@ -17,7 +17,7 @@ module ArelExtensions
17
17
  end
18
18
 
19
19
  def cast right
20
- ArelExtensions::Nodes::Cast.new([self,right])
20
+ ArelExtensions::Nodes::Cast.new([self, right])
21
21
  end
22
22
 
23
23
  def in(*other) # In should handle nil element in the Array
@@ -72,7 +72,7 @@ module ArelExtensions
72
72
  when Arel::SelectManager
73
73
  Arel::Nodes::NotIn.new(self, other.ast)
74
74
  else
75
- Arel::Nodes::NotIn.new(self,quoted_node(other))
75
+ Arel::Nodes::NotIn.new(self, quoted_node(other))
76
76
  end
77
77
  end
78
78
 
@@ -81,13 +81,13 @@ module ArelExtensions
81
81
  when Arel::Attributes::Attribute, Arel::Nodes::Node, Integer
82
82
  object
83
83
  when DateTime
84
- Arel::Nodes.build_quoted(object, self)
84
+ Arel.quoted(object, self)
85
85
  when Time
86
- Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
86
+ Arel.quoted(object.strftime('%H:%M:%S'), self)
87
87
  when String
88
- Arel::Nodes.build_quoted(object)
88
+ Arel.quoted(object)
89
89
  when Date
90
- Arel::Nodes.build_quoted(object.to_s, self)
90
+ Arel.quoted(object.to_s, self)
91
91
  when NilClass
92
92
  Arel.sql('NULL')
93
93
  when ActiveSupport::Duration
@@ -3,7 +3,7 @@ require 'rails'
3
3
  module ArelExtensions
4
4
  class Railtie < Rails::Railtie
5
5
  rake_tasks do
6
- load 'arel_extensions/tasks.rb'
6
+ load 'arel_extensions/tasks.rb'
7
7
  end
8
8
  end
9
9
  end
@@ -4,15 +4,15 @@ require 'arel_extensions/nodes/union_all'
4
4
  module ArelExtensions
5
5
  module SetFunctions
6
6
  def +(other)
7
- ArelExtensions::Nodes::Union.new(self,other)
7
+ ArelExtensions::Nodes::Union.new(self, other)
8
8
  end
9
9
 
10
10
  def union(other)
11
- ArelExtensions::Nodes::Union.new(self,other)
11
+ ArelExtensions::Nodes::Union.new(self, other)
12
12
  end
13
13
 
14
14
  def union_all(other)
15
- ArelExtensions::Nodes::UnionAll.new(self,other)
15
+ ArelExtensions::Nodes::UnionAll.new(self, other)
16
16
  end
17
17
 
18
18
  def uniq
@@ -101,27 +101,27 @@ module ArelExtensions
101
101
  end
102
102
 
103
103
  def ai_matches other # accent insensitive & case sensitive
104
- ArelExtensions::Nodes::AiMatches.new(self,other)
104
+ ArelExtensions::Nodes::AiMatches.new(self, other)
105
105
  end
106
106
 
107
107
  def ai_imatches other # accent insensitive & case insensitive
108
- ArelExtensions::Nodes::AiIMatches.new(self,other)
108
+ ArelExtensions::Nodes::AiIMatches.new(self, other)
109
109
  end
110
110
 
111
111
  def smatches other # accent sensitive & case sensitive
112
- ArelExtensions::Nodes::SMatches.new(self,other)
112
+ ArelExtensions::Nodes::SMatches.new(self, other)
113
113
  end
114
114
 
115
115
  def ai_collate
116
- ArelExtensions::Nodes::Collate.new(self,nil,true,false)
116
+ ArelExtensions::Nodes::Collate.new(self, nil, true, false)
117
117
  end
118
118
 
119
119
  def ci_collate
120
- ArelExtensions::Nodes::Collate.new(self,nil,false,true)
120
+ ArelExtensions::Nodes::Collate.new(self, nil, false, true)
121
121
  end
122
122
 
123
- def collate ai = false,ci = false, option = nil
124
- ArelExtensions::Nodes::Collate.new(self,option,ai,ci)
123
+ def collate ai = false, ci = false, option = nil
124
+ ArelExtensions::Nodes::Collate.new(self, option, ai, ci)
125
125
  end
126
126
 
127
127
  # REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.
@@ -144,7 +144,7 @@ module ArelExtensions
144
144
  # concat elements of a group, separated by sep and ordered by a list of Ascending or Descending
145
145
  def group_concat(sep = nil, *orders, group: nil, order: nil)
146
146
  if orders.present?
147
- warn("Warning : ArelExtensions: group_concat: you should now use the kwarg 'order' to specify an order in the group_concat.")
147
+ warn("Warning: ArelExtensions: group_concat: you should now use the kwarg 'order' to specify an order in the group_concat.")
148
148
  end
149
149
  order_tabs = [orders].flatten.map{ |o|
150
150
  if o.is_a?(Arel::Nodes::Ascending) || o.is_a?(Arel::Nodes::Descending)
@@ -1,8 +1,8 @@
1
1
  namespace :arel_extensions do
2
2
  desc 'Install DB functions into current DB'
3
3
  task install_functions: :environment do
4
- @env_db = if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx") || (RUBY_PLATFORM == 'java')) # not supported
5
- (RUBY_PLATFORM == 'java' ? "jdbc-sqlite" : 'sqlite')
4
+ @env_db = if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx') || (RUBY_PLATFORM == 'java')) # not supported
5
+ (RUBY_PLATFORM == 'java' ? 'jdbc-sqlite' : 'sqlite')
6
6
  else
7
7
  ENV['DB'] || ActiveRecord::Base.connection.adapter_name
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "1.3.2".freeze
2
+ VERSION = '1.3.5'.freeze
3
3
  end
File without changes
@@ -2,45 +2,45 @@ module ArelExtensions
2
2
  module Visitors
3
3
  class Arel::Visitors::IBM_DB
4
4
  def visit_ArelExtensions_Nodes_Ceil o, collector
5
- collector << "CEILING("
5
+ collector << 'CEILING('
6
6
  collector = visit o.expr, collector
7
- collector << ")"
7
+ collector << ')'
8
8
  collector
9
9
  end
10
10
 
11
11
  def visit_ArelExtensions_Nodes_Trim o, collector
12
- collector << "LTRIM(RTRIM("
12
+ collector << 'LTRIM(RTRIM('
13
13
  o.expressions.each_with_index { |arg, i|
14
14
  collector << COMMA if i != 0
15
15
  collector = visit arg, collector
16
16
  }
17
- collector << "))"
17
+ collector << '))'
18
18
  collector
19
19
  end
20
20
 
21
21
  def visit_ArelExtensions_Nodes_DateDiff o, collector
22
- collector << "DAY("
22
+ collector << 'DAY('
23
23
  collector = visit o.left, collector
24
- collector << ","
24
+ collector << ','
25
25
  if o.right.is_a?(Arel::Attributes::Attribute)
26
26
  collector = visit o.right, collector
27
27
  else
28
28
  collector << "'#{o.right}'"
29
29
  end
30
- collector << ")"
30
+ collector << ')'
31
31
  collector
32
32
  end
33
33
 
34
34
  def visit_ArelExtensions_Nodes_Duration o, collector
35
35
  # visit left for period
36
- if o.left == "d"
37
- collector << "DAY("
38
- elsif o.left == "m"
39
- collector << "MONTH("
40
- elsif o.left == "w"
41
- collector << "WEEK"
42
- elsif o.left == "y"
43
- collector << "YEAR("
36
+ if o.left == 'd'
37
+ collector << 'DAY('
38
+ elsif o.left == 'm'
39
+ collector << 'MONTH('
40
+ elsif o.left == 'w'
41
+ collector << 'WEEK'
42
+ elsif o.left == 'y'
43
+ collector << 'YEAR('
44
44
  end
45
45
  # visit right
46
46
  if o.right.is_a?(Arel::Attributes::Attribute)
@@ -48,20 +48,20 @@ module ArelExtensions
48
48
  else
49
49
  collector << "'#{o.right}'"
50
50
  end
51
- collector << ")"
51
+ collector << ')'
52
52
  collector
53
53
  end
54
54
 
55
55
  def visit_ArelExtensions_Nodes_IsNull o, collector
56
- collector << "COALESCE("
56
+ collector << 'COALESCE('
57
57
  collector = visit o.left, collector
58
- collector << ","
59
- if (o.right.is_a?(Arel::Attributes::Attribute))
58
+ collector << ','
59
+ if o.right.is_a?(Arel::Attributes::Attribute)
60
60
  collector = visit o.right, collector
61
61
  else
62
62
  collector << "'#{o.right}'"
63
63
  end
64
- collector << ")"
64
+ collector << ')'
65
65
  collector
66
66
  end
67
67
  end