arel_extensions 1.3.5 → 2.0.0.rc3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -1
  3. data/.gitignore +6 -7
  4. data/.rubocop.yml +3 -67
  5. data/.travis/oracle/download.js +152 -0
  6. data/.travis/oracle/download.sh +30 -0
  7. data/.travis/oracle/download_ojdbc.js +116 -0
  8. data/.travis/oracle/install.sh +34 -0
  9. data/.travis/setup_accounts.sh +9 -0
  10. data/.travis/sqlite3/extension-functions.sh +6 -0
  11. data/.travis.yml +223 -0
  12. data/Gemfile +21 -16
  13. data/README.md +13 -125
  14. data/Rakefile +30 -41
  15. data/TODO +1 -0
  16. data/appveyor.yml +22 -51
  17. data/arel_extensions.gemspec +14 -14
  18. data/functions.html +3 -3
  19. data/gemfiles/rails3.gemfile +10 -10
  20. data/gemfiles/rails4.gemfile +14 -14
  21. data/gemfiles/rails5_0.gemfile +14 -14
  22. data/gemfiles/rails5_1_4.gemfile +14 -14
  23. data/gemfiles/rails5_2.gemfile +14 -16
  24. data/init/mssql.sql +4 -4
  25. data/init/mysql.sql +38 -38
  26. data/init/oracle.sql +0 -0
  27. data/init/postgresql.sql +21 -21
  28. data/init/sqlite.sql +0 -0
  29. data/lib/arel_extensions/attributes.rb +3 -4
  30. data/lib/arel_extensions/boolean_functions.rb +14 -53
  31. data/lib/arel_extensions/common_sql_functions.rb +17 -16
  32. data/lib/arel_extensions/comparators.rb +28 -27
  33. data/lib/arel_extensions/date_duration.rb +14 -13
  34. data/lib/arel_extensions/insert_manager.rb +15 -18
  35. data/lib/arel_extensions/math.rb +53 -55
  36. data/lib/arel_extensions/math_functions.rb +39 -46
  37. data/lib/arel_extensions/nodes/abs.rb +1 -0
  38. data/lib/arel_extensions/nodes/blank.rb +2 -1
  39. data/lib/arel_extensions/nodes/case.rb +16 -16
  40. data/lib/arel_extensions/nodes/cast.rb +8 -10
  41. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  42. data/lib/arel_extensions/nodes/coalesce.rb +4 -3
  43. data/lib/arel_extensions/nodes/collate.rb +10 -9
  44. data/lib/arel_extensions/nodes/concat.rb +18 -9
  45. data/lib/arel_extensions/nodes/date_diff.rb +26 -42
  46. data/lib/arel_extensions/nodes/duration.rb +3 -0
  47. data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
  48. data/lib/arel_extensions/nodes/floor.rb +1 -1
  49. data/lib/arel_extensions/nodes/format.rb +8 -35
  50. data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
  51. data/lib/arel_extensions/nodes/function.rb +37 -42
  52. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  53. data/lib/arel_extensions/nodes/json.rb +39 -48
  54. data/lib/arel_extensions/nodes/length.rb +0 -5
  55. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  56. data/lib/arel_extensions/nodes/locate.rb +2 -1
  57. data/lib/arel_extensions/nodes/log10.rb +2 -1
  58. data/lib/arel_extensions/nodes/matches.rb +7 -5
  59. data/lib/arel_extensions/nodes/md5.rb +1 -0
  60. data/lib/arel_extensions/nodes/power.rb +5 -5
  61. data/lib/arel_extensions/nodes/rand.rb +1 -0
  62. data/lib/arel_extensions/nodes/repeat.rb +5 -3
  63. data/lib/arel_extensions/nodes/replace.rb +8 -16
  64. data/lib/arel_extensions/nodes/round.rb +6 -5
  65. data/lib/arel_extensions/nodes/soundex.rb +15 -15
  66. data/lib/arel_extensions/nodes/std.rb +21 -18
  67. data/lib/arel_extensions/nodes/substring.rb +16 -8
  68. data/lib/arel_extensions/nodes/then.rb +1 -1
  69. data/lib/arel_extensions/nodes/trim.rb +6 -4
  70. data/lib/arel_extensions/nodes/union.rb +8 -5
  71. data/lib/arel_extensions/nodes/union_all.rb +7 -4
  72. data/lib/arel_extensions/nodes/wday.rb +4 -0
  73. data/lib/arel_extensions/nodes.rb +1 -1
  74. data/lib/arel_extensions/null_functions.rb +7 -5
  75. data/lib/arel_extensions/predications.rb +43 -44
  76. data/lib/arel_extensions/railtie.rb +5 -5
  77. data/lib/arel_extensions/set_functions.rb +7 -5
  78. data/lib/arel_extensions/string_functions.rb +29 -58
  79. data/lib/arel_extensions/tasks.rb +6 -6
  80. data/lib/arel_extensions/version.rb +1 -1
  81. data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
  82. data/lib/arel_extensions/visitors/mssql.rb +181 -279
  83. data/lib/arel_extensions/visitors/mysql.rb +210 -280
  84. data/lib/arel_extensions/visitors/oracle.rb +180 -201
  85. data/lib/arel_extensions/visitors/oracle12.rb +31 -18
  86. data/lib/arel_extensions/visitors/postgresql.rb +173 -252
  87. data/lib/arel_extensions/visitors/sqlite.rb +126 -140
  88. data/lib/arel_extensions/visitors/to_sql.rb +237 -272
  89. data/lib/arel_extensions/visitors.rb +59 -75
  90. data/lib/arel_extensions.rb +31 -159
  91. data/test/database.yml +7 -15
  92. data/test/helper.rb +18 -0
  93. data/test/real_db_test.rb +116 -105
  94. data/test/support/fake_record.rb +3 -3
  95. data/test/test_comparators.rb +17 -14
  96. data/test/visitors/test_bulk_insert_oracle.rb +11 -11
  97. data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
  98. data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
  99. data/test/visitors/test_oracle.rb +55 -55
  100. data/test/visitors/test_to_sql.rb +226 -419
  101. data/test/with_ar/all_agnostic_test.rb +361 -578
  102. data/test/with_ar/insert_agnostic_test.rb +21 -27
  103. data/test/with_ar/test_bulk_sqlite.rb +16 -17
  104. data/test/with_ar/test_math_sqlite.rb +26 -26
  105. data/test/with_ar/test_string_mysql.rb +33 -31
  106. data/test/with_ar/test_string_sqlite.rb +34 -30
  107. metadata +22 -29
  108. data/.github/workflows/ruby.yml +0 -341
  109. data/gemfiles/rails6.gemfile +0 -30
  110. data/gemfiles/rails6_1.gemfile +0 -30
  111. data/gemfiles/rails7.gemfile +0 -23
  112. data/gemspecs/arel_extensions-v1.gemspec +0 -28
  113. data/gemspecs/arel_extensions-v2.gemspec +0 -28
  114. data/generate_gems.sh +0 -15
  115. data/lib/arel_extensions/aliases.rb +0 -14
  116. data/lib/arel_extensions/helpers.rb +0 -51
  117. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
  118. data/lib/arel_extensions/nodes/sum.rb +0 -7
  119. data/lib/arel_extensions/visitors/convert_format.rb +0 -37
  120. data/test/arelx_test_helper.rb +0 -71
  121. data/version_v1.rb +0 -3
  122. data/version_v2.rb +0 -3
@@ -1,21 +1,24 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Union < Arel::Nodes::Union
4
- def initialize left, right
5
- super(left, right)
4
+
5
+ def initialize left,right
6
+ return super(left,right)
6
7
  end
7
8
 
8
9
  def +(other)
9
- ArelExtensions::Nodes::Union.new(self, other)
10
+ return ArelExtensions::Nodes::Union.new(self,other)
10
11
  end
11
12
 
12
13
  def union(other)
13
- ArelExtensions::Nodes::UnionAll.new(self, other)
14
+ return ArelExtensions::Nodes::UnionAll.new(self,other)
14
15
  end
15
16
 
16
17
  def as other
17
- Arel::Nodes::TableAlias.new Arel.grouping(self), Arel::Nodes::SqlLiteral.new(other.to_s)
18
+ Arel::Nodes::TableAlias.new Arel::Nodes::Grouping.new(self), Arel::Nodes::SqlLiteral.new(other.to_s)
18
19
  end
19
20
  end
21
+
20
22
  end
21
23
  end
24
+
@@ -1,17 +1,20 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class UnionAll < Arel::Nodes::UnionAll
4
- def initialize left, right
5
- super(left, right)
4
+
5
+ def initialize left,right
6
+ return super(left,right)
6
7
  end
7
8
 
8
9
  def union_all(other)
9
- ArelExtensions::Nodes::UnionAll.new(self, other)
10
+ return ArelExtensions::Nodes::UnionAll.new(self,other)
10
11
  end
11
12
 
12
13
  def as other
13
- Arel::Nodes::TableAlias.new Arel.grouping(self), Arel::Nodes::SqlLiteral.new(other.to_s)
14
+ Arel::Nodes::TableAlias.new Arel::Nodes::Grouping.new(self), Arel::Nodes::SqlLiteral.new(other.to_s)
14
15
  end
15
16
  end
17
+
16
18
  end
17
19
  end
20
+
@@ -1,15 +1,19 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Wday < Function
4
+
5
+
4
6
  def initialize other, aliaz = nil
5
7
  tab = Array.new
6
8
  tab << other
7
9
  super(tab, aliaz)
8
10
  end
9
11
 
12
+
10
13
  def date
11
14
  @expressions.first
12
15
  end
16
+
13
17
  end
14
18
  end
15
19
  end
@@ -1,2 +1,2 @@
1
1
  require 'arel_extensions/nodes/function'
2
- require 'arel_extensions/nodes/aggregate_function'
2
+
@@ -3,21 +3,23 @@ require 'arel_extensions/nodes/is_null'
3
3
 
4
4
  module ArelExtensions
5
5
  module NullFunctions
6
- # ISNULL function lets you return an alternative value when an expression is NULL.
6
+
7
+ #ISNULL function lets you return an alternative value when an expression is NULL.
7
8
  def is_null
8
9
  ArelExtensions::Nodes::IsNull.new [self]
9
10
  end
10
-
11
- # ISNOTNULL function lets you return an alternative value when an expression is NOT NULL.
11
+
12
+ #ISNOTNULL function lets you return an alternative value when an expression is NOT NULL.
12
13
  def is_not_null
13
14
  ArelExtensions::Nodes::IsNotNull.new [self]
14
15
  end
15
-
16
+
16
17
  # returns the first non-null expr in the expression list. You must specify at least two expressions.
17
- # If all occurrences of expr evaluate to null, then the function returns null.
18
+ #If all occurrences of expr evaluate to null, then the function returns null.
18
19
  def coalesce *args
19
20
  args.unshift(self)
20
21
  ArelExtensions::Nodes::Coalesce.new args
21
22
  end
23
+
22
24
  end
23
25
  end
@@ -1,78 +1,76 @@
1
1
  module ArelExtensions
2
2
  module Predications
3
- def when right, expression = nil
4
- ArelExtensions::Nodes::Case.new(self).when(right, expression)
3
+ def when right, expression=nil
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.quoted(other), escape)
9
+ Arel::Nodes::Matches.new(self, Arel::Nodes.build_quoted(other), escape)
10
10
  else
11
- Arel::Nodes::Matches.new(self, Arel.quoted(other), escape, case_sensitive)
11
+ Arel::Nodes::Matches.new(self, Arel::Nodes.build_quoted(other), escape, case_sensitive)
12
12
  end
13
13
  end
14
14
 
15
- def imatches(other, escape = nil)
15
+ def imatches(other, escape=nil)
16
16
  ArelExtensions::Nodes::IMatches.new(self, other, escape)
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
- def in(*other) # In should handle nil element in the Array
24
- other = other.first if other.length <= 1
23
+ def in(other) #In should handle nil element in the Array
25
24
  case other
26
25
  when Range
27
26
  self.between(other)
28
- when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
29
- Arel::Nodes::In.new(self, quoted_node(other))
30
27
  when Enumerable
31
- nils, values = other.partition{ |v| v.nil? }
32
- ranges, values = values.partition{ |v| v.is_a?(Range) || v.is_a?(Arel::SelectManager)}
33
- # In order of (imagined) decreasing efficiency: nil, values, and then more complex.
34
- clauses =
35
- nils.uniq.map { |r| self.in(r) } \
36
- + (case values.uniq.size
37
- when 0 then []
38
- when 1 then [values[0].is_a?(Arel::Nodes::Grouping) ? self.in(values[0]) : self.eq(values[0])]
39
- else [Arel::Nodes::In.new(self, quoted_array(values))] end) \
40
- + ranges.uniq.map { |r| self.in(r) }
41
- clauses.empty? ? Arel.false : clauses.reduce(&:or)
28
+ if other.include?(nil)
29
+ other.delete(nil)
30
+ case other.length
31
+ when 0
32
+ self.is_null
33
+ when 1
34
+ self.is_null.or(self==other[0])
35
+ else
36
+ self.is_null.or(Arel::Nodes::In.new(self,quoted_array(other)))
37
+ end
38
+ else
39
+ Arel::Nodes::In.new(self,quoted_array(other))
40
+ end
42
41
  when nil
43
42
  self.is_null
44
43
  when Arel::SelectManager
45
44
  Arel::Nodes::In.new(self, other.ast)
46
45
  else
47
- Arel::Nodes::In.new(self, quoted_node(other))
46
+ Arel::Nodes::In.new(self,quoted_node(other))
48
47
  end
49
48
  end
50
49
 
51
- def not_in(*other) # In should handle nil element in the Array
52
- other = other.first if other.length <= 1
50
+ def not_in(other) #In should handle nil element in the Array
53
51
  case other
54
52
  when Range
55
53
  Arel::Nodes::Not.new(self.between(other))
56
- when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
57
- Arel::Nodes::NotIn.new(self, quoted_node(other))
58
54
  when Enumerable
59
- nils, values = other.partition{ |v| v.nil? }
60
- ranges, values = values.partition{ |v| v.is_a?(Range) || v.is_a?(Arel::SelectManager)}
61
- # In order of (imagined) decreasing efficiency: nil, values, and then more complex.
62
- clauses =
63
- nils.uniq.map { |r| self.not_in(r) } \
64
- + (case values.uniq.size
65
- when 0 then []
66
- when 1 then [values[0].is_a?(Arel::Nodes::Grouping) ? self.not_in(values[0]) : self.not_eq(values[0])]
67
- else [Arel::Nodes::NotIn.new(self, quoted_array(values))] end) \
68
- + ranges.uniq.map { |r| self.not_in(r) }
69
- Arel::Nodes::And.new clauses
55
+ if other.include?(nil)
56
+ other.delete(nil)
57
+ case other.length
58
+ when 0
59
+ self.is_not_null
60
+ when 1
61
+ self.is_not_null.and(self!=other[0])
62
+ else
63
+ self.is_not_null.and(Arel::Nodes::NotIn.new(self,quoted_array(other)))
64
+ end
65
+ else
66
+ Arel::Nodes::NotIn.new(self,quoted_array(other))
67
+ end
70
68
  when nil
71
69
  self.is_not_null
72
70
  when Arel::SelectManager
73
71
  Arel::Nodes::NotIn.new(self, other.ast)
74
72
  else
75
- Arel::Nodes::NotIn.new(self, quoted_node(other))
73
+ Arel::Nodes::NotIn.new(self,quoted_node(other))
76
74
  end
77
75
  end
78
76
 
@@ -81,20 +79,21 @@ module ArelExtensions
81
79
  when Arel::Attributes::Attribute, Arel::Nodes::Node, Integer
82
80
  object
83
81
  when DateTime
84
- Arel.quoted(object, self)
82
+ Arel::Nodes.build_quoted(object, self)
85
83
  when Time
86
- Arel.quoted(object.strftime('%H:%M:%S'), self)
84
+ Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
87
85
  when String
88
- Arel.quoted(object)
86
+ Arel::Nodes.build_quoted(object)
89
87
  when Date
90
- Arel.quoted(object.to_s, self)
88
+ Arel::Nodes.build_quoted(object.to_s, self)
91
89
  when NilClass
92
90
  Arel.sql('NULL')
93
91
  when ActiveSupport::Duration
94
92
  object.to_i
95
93
  else
96
- raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
94
+ raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
97
95
  end
98
96
  end
97
+
99
98
  end
100
99
  end
@@ -1,9 +1,9 @@
1
1
  require 'rails'
2
2
 
3
3
  module ArelExtensions
4
- class Railtie < Rails::Railtie
5
- rake_tasks do
6
- load 'arel_extensions/tasks.rb'
7
- end
8
- end
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load 'arel_extensions/tasks.rb'
7
+ end
8
+ end
9
9
  end
@@ -3,28 +3,30 @@ require 'arel_extensions/nodes/union_all'
3
3
 
4
4
  module ArelExtensions
5
5
  module SetFunctions
6
+
6
7
  def +(other)
7
- ArelExtensions::Nodes::Union.new(self, other)
8
+ ArelExtensions::Nodes::Union.new(self,other)
8
9
  end
9
10
 
10
11
  def union(other)
11
- ArelExtensions::Nodes::Union.new(self, other)
12
+ ArelExtensions::Nodes::Union.new(self,other)
12
13
  end
13
14
 
14
15
  def union_all(other)
15
- ArelExtensions::Nodes::UnionAll.new(self, other)
16
+ ArelExtensions::Nodes::UnionAll.new(self,other)
16
17
  end
17
18
 
18
19
  def uniq
19
20
  self
20
21
  end
22
+
21
23
  end
22
24
  end
23
25
 
24
- class Arel::Nodes::Union
26
+ Arel::Nodes::Union.class_eval do
25
27
  include ArelExtensions::SetFunctions
26
28
  end
27
29
 
28
- class Arel::Nodes::UnionAll
30
+ Arel::Nodes::UnionAll.class_eval do
29
31
  include ArelExtensions::SetFunctions
30
32
  end
@@ -1,4 +1,4 @@
1
- require 'arel_extensions/nodes/concat' # if Arel::VERSION.to_i < 7
1
+ require 'arel_extensions/nodes/concat' #if Arel::VERSION.to_i < 7
2
2
  require 'arel_extensions/nodes/length'
3
3
  require 'arel_extensions/nodes/locate'
4
4
  require 'arel_extensions/nodes/substring'
@@ -19,26 +19,19 @@ require 'arel_extensions/nodes/md5'
19
19
 
20
20
  module ArelExtensions
21
21
  module StringFunctions
22
- # *FindInSet function .......
22
+
23
+ #*FindInSet function .......
23
24
  def &(other)
24
25
  ArelExtensions::Nodes::FindInSet.new [other, self]
25
26
  end
26
27
 
27
- # LENGTH function returns the length (bytewise) of the value in a text field.
28
+ #LENGTH function returns the length of the value in a text field.
28
29
  def length
29
- ArelExtensions::Nodes::Length.new self, true
30
- end
31
-
32
- def byte_length
33
- ArelExtensions::Nodes::Length.new self, true
30
+ ArelExtensions::Nodes::Length.new [self]
34
31
  end
35
32
 
36
- def char_length
37
- ArelExtensions::Nodes::Length.new self, false
38
- end
39
-
40
- # LOCATE function returns the first starting position of a string in another string.
41
- # If string1 or string2 is NULL then it returns NULL. If string1 not found in string2 then it returns 0.
33
+ #LOCATE function returns the first starting position of a string in another string.
34
+ #If string1 or string2 is NULL then it returns NULL. If string1 not found in string2 then it returns 0.
42
35
  def locate val
43
36
  ArelExtensions::Nodes::Locate.new [self, val]
44
37
  end
@@ -58,7 +51,7 @@ module ArelExtensions
58
51
  end
59
52
  end
60
53
 
61
- # SOUNDEX function returns a character string containing the phonetic representation of char.
54
+ #SOUNDEX function returns a character string containing the phonetic representation of char.
62
55
  def soundex
63
56
  ArelExtensions::Nodes::Soundex.new [self]
64
57
  end
@@ -71,19 +64,6 @@ module ArelExtensions
71
64
  grouping_any :imatches, others, escape
72
65
  end
73
66
 
74
- # def grouping_any method, others, *extra
75
- # puts "*******************"
76
- # puts method
77
- # puts others.inspect
78
- # puts extra.inspect
79
- # puts "-------------------"
80
- # res = super(method,others,*extra)
81
- # puts res.to_sql
82
- # puts res.inspect
83
- # puts "*******************"
84
- # res
85
- # end
86
-
87
67
  def imatches_all others, escape = nil
88
68
  grouping_all :imatches, others, escape, escape
89
69
  end
@@ -101,62 +81,53 @@ module ArelExtensions
101
81
  end
102
82
 
103
83
  def ai_matches other # accent insensitive & case sensitive
104
- ArelExtensions::Nodes::AiMatches.new(self, other)
84
+ ArelExtensions::Nodes::AiMatches.new(self,other)
105
85
  end
106
86
 
107
87
  def ai_imatches other # accent insensitive & case insensitive
108
- ArelExtensions::Nodes::AiIMatches.new(self, other)
88
+ ArelExtensions::Nodes::AiIMatches.new(self,other)
109
89
  end
110
90
 
111
91
  def smatches other # accent sensitive & case sensitive
112
- ArelExtensions::Nodes::SMatches.new(self, other)
92
+ ArelExtensions::Nodes::SMatches.new(self,other)
113
93
  end
114
94
 
115
- def ai_collate
116
- ArelExtensions::Nodes::Collate.new(self, nil, true, false)
95
+ def ai_collate
96
+ ArelExtensions::Nodes::Collate.new(self,nil,true,false)
117
97
  end
118
98
 
119
99
  def ci_collate
120
- ArelExtensions::Nodes::Collate.new(self, nil, false, true)
121
- end
122
-
123
- def collate ai = false, ci = false, option = nil
124
- ArelExtensions::Nodes::Collate.new(self, option, ai, ci)
100
+ ArelExtensions::Nodes::Collate.new(self,nil,false,true)
125
101
  end
126
102
 
127
- # REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.
128
- def replace pattern, substitute
129
- if pattern.is_a? Regexp
130
- ArelExtensions::Nodes::RegexpReplace.new self, pattern, substitute
131
- else
132
- ArelExtensions::Nodes::Replace.new self, pattern, substitute
133
- end
103
+ def collate ai=false,ci=false, option=nil
104
+ ArelExtensions::Nodes::Collate.new(self,option,ai,ci)
134
105
  end
135
106
 
136
- def regexp_replace pattern, substitute
137
- ArelExtensions::Nodes::RegexpReplace.new self, pattern, substitute
107
+ #REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.
108
+ def replace left, right
109
+ ArelExtensions::Nodes::Replace.new [self, left, right]
138
110
  end
139
-
111
+
140
112
  def concat other
141
113
  ArelExtensions::Nodes::Concat.new [self, other]
142
114
  end
143
115
 
144
- # concat elements of a group, separated by sep and ordered by a list of Ascending or Descending
145
- def group_concat(sep = nil, *orders, group: nil, order: nil)
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.")
148
- end
116
+ #concat elements of a group, separated by sep and ordered by a list of Ascending or Descending
117
+ def group_concat sep = nil, *orders
149
118
  order_tabs = [orders].flatten.map{ |o|
150
119
  if o.is_a?(Arel::Nodes::Ascending) || o.is_a?(Arel::Nodes::Descending)
151
120
  o
152
121
  elsif o.respond_to?(:asc)
153
122
  o.asc
123
+ else
124
+ nil
154
125
  end
155
126
  }.compact
156
- ArelExtensions::Nodes::GroupConcat.new(self, sep, group: group, order: (order || order_tabs))
127
+ ArelExtensions::Nodes::GroupConcat.new [self, sep, order_tabs]
157
128
  end
158
129
 
159
- # Function returns a string after removing left, right or the both prefixes or suffixes int argument
130
+ #Function returns a string after removing left, right or the both prefixes or suffixes int argument
160
131
  def trim other = ' '
161
132
  ArelExtensions::Nodes::Trim.new [self, other]
162
133
  end
@@ -184,11 +155,11 @@ module ArelExtensions
184
155
  def not_blank
185
156
  ArelExtensions::Nodes::NotBlank.new [self]
186
157
  end
187
-
188
- def repeat other = 1
158
+
159
+ def repeat other = 1
189
160
  ArelExtensions::Nodes::Repeat.new [self, other]
190
161
  end
191
-
162
+
192
163
  def levenshtein_distance other
193
164
  ArelExtensions::Nodes::LevenshteinDistance.new [self, other]
194
165
  end
@@ -1,12 +1,12 @@
1
1
  namespace :arel_extensions do
2
- desc 'Install DB functions into current DB'
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')
2
+ desc 'Install DB functions into current DB'
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')
6
6
  else
7
7
  ENV['DB'] || ActiveRecord::Base.connection.adapter_name
8
8
  end
9
- ActiveRecord::Base.establish_connection(Rails.env.to_sym)
9
+ ActiveRecord::Base.establish_connection(Rails.env)
10
10
  CommonSqlFunctions.new(ActiveRecord::Base.connection).add_sql_functions(@env_db)
11
- end
11
+ end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '1.3.5'.freeze
2
+ VERSION = "2.0.0.rc3".freeze
3
3
  end
@@ -1,69 +1,76 @@
1
1
  module ArelExtensions
2
2
  module Visitors
3
- class Arel::Visitors::IBM_DB
3
+ Arel::Visitors::IBM_DB.class_eval do
4
+
4
5
  def visit_ArelExtensions_Nodes_Ceil o, collector
5
- collector << 'CEILING('
6
+ collector << "CEILING("
6
7
  collector = visit o.expr, collector
7
- collector << ')'
8
+ collector << ")"
8
9
  collector
9
10
  end
10
11
 
11
12
  def visit_ArelExtensions_Nodes_Trim o, collector
12
- collector << 'LTRIM(RTRIM('
13
+ collector << "LTRIM(RTRIM("
13
14
  o.expressions.each_with_index { |arg, i|
14
- collector << COMMA if i != 0
15
+ collector << Arel::Visitors::IBM_DB::COMMA unless i == 0
15
16
  collector = visit arg, collector
16
17
  }
17
- collector << '))'
18
+ collector << "))"
18
19
  collector
19
20
  end
20
21
 
22
+
21
23
  def visit_ArelExtensions_Nodes_DateDiff o, collector
22
- collector << 'DAY('
24
+ collector << "DAY("
23
25
  collector = visit o.left, collector
24
- collector << ','
26
+ collector << ","
25
27
  if o.right.is_a?(Arel::Attributes::Attribute)
26
28
  collector = visit o.right, collector
27
29
  else
28
30
  collector << "'#{o.right}'"
29
31
  end
30
- collector << ')'
32
+ collector << ")"
31
33
  collector
32
34
  end
33
35
 
36
+
34
37
  def visit_ArelExtensions_Nodes_Duration o, collector
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('
38
+ #visit left for period
39
+ if o.left == "d"
40
+ collector << "DAY("
41
+ elsif o.left == "m"
42
+ collector << "MONTH("
43
+ elsif o.left == "w"
44
+ collector << "WEEK"
45
+ elsif o.left == "y"
46
+ collector << "YEAR("
44
47
  end
45
- # visit right
48
+ #visit right
46
49
  if o.right.is_a?(Arel::Attributes::Attribute)
47
50
  collector = visit o.right, collector
48
51
  else
49
52
  collector << "'#{o.right}'"
50
53
  end
51
- collector << ')'
54
+ collector << ")"
52
55
  collector
53
56
  end
54
57
 
58
+
55
59
  def visit_ArelExtensions_Nodes_IsNull o, collector
56
- collector << 'COALESCE('
60
+ collector << "COALESCE("
57
61
  collector = visit o.left, collector
58
- collector << ','
59
- if o.right.is_a?(Arel::Attributes::Attribute)
62
+ collector << ","
63
+ if(o.right.is_a?(Arel::Attributes::Attribute))
60
64
  collector = visit o.right, collector
61
65
  else
62
66
  collector << "'#{o.right}'"
63
67
  end
64
- collector << ')'
68
+ collector << ")"
65
69
  collector
66
70
  end
71
+
72
+
73
+
67
74
  end
68
75
  end
69
76
  end