arel_extensions 1.7.0 → 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 (146) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -1
  3. data/.gitignore +6 -8
  4. data/.rubocop.yml +4 -194
  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 +28 -2
  13. data/README.md +89 -265
  14. data/Rakefile +30 -50
  15. data/TODO +1 -0
  16. data/appveyor.yml +22 -60
  17. data/arel_extensions.gemspec +17 -14
  18. data/functions.html +3 -3
  19. data/gemfiles/rails3.gemfile +20 -0
  20. data/gemfiles/rails4.gemfile +29 -0
  21. data/gemfiles/rails5_0.gemfile +29 -0
  22. data/gemfiles/rails5_1_4.gemfile +17 -19
  23. data/gemfiles/rails5_2.gemfile +17 -26
  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 +25 -24
  28. data/init/sqlite.sql +0 -0
  29. data/lib/arel_extensions/attributes.rb +3 -9
  30. data/lib/arel_extensions/boolean_functions.rb +16 -57
  31. data/lib/arel_extensions/common_sql_functions.rb +20 -21
  32. data/lib/arel_extensions/comparators.rb +28 -31
  33. data/lib/arel_extensions/date_duration.rb +13 -19
  34. data/lib/arel_extensions/insert_manager.rb +15 -22
  35. data/lib/arel_extensions/math.rb +70 -68
  36. data/lib/arel_extensions/math_functions.rb +52 -57
  37. data/lib/arel_extensions/nodes/abs.rb +1 -0
  38. data/lib/arel_extensions/nodes/blank.rb +5 -6
  39. data/lib/arel_extensions/nodes/case.rb +27 -31
  40. data/lib/arel_extensions/nodes/cast.rb +12 -12
  41. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  42. data/lib/arel_extensions/nodes/coalesce.rb +5 -4
  43. data/lib/arel_extensions/nodes/collate.rb +10 -9
  44. data/lib/arel_extensions/nodes/concat.rb +22 -13
  45. data/lib/arel_extensions/nodes/date_diff.rb +70 -77
  46. data/lib/arel_extensions/nodes/duration.rb +5 -2
  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 +39 -50
  52. data/lib/arel_extensions/nodes/is_null.rb +0 -2
  53. data/lib/arel_extensions/nodes/json.rb +47 -72
  54. data/lib/arel_extensions/nodes/length.rb +0 -5
  55. data/lib/arel_extensions/nodes/levenshtein_distance.rb +2 -2
  56. data/lib/arel_extensions/nodes/locate.rb +3 -2
  57. data/lib/arel_extensions/nodes/log10.rb +2 -1
  58. data/lib/arel_extensions/nodes/matches.rb +8 -6
  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 +3 -2
  62. data/lib/arel_extensions/nodes/repeat.rb +6 -4
  63. data/lib/arel_extensions/nodes/replace.rb +8 -16
  64. data/lib/arel_extensions/nodes/round.rb +7 -6
  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 -58
  68. data/lib/arel_extensions/nodes/then.rb +2 -2
  69. data/lib/arel_extensions/nodes/trim.rb +7 -5
  70. data/lib/arel_extensions/nodes/union.rb +9 -6
  71. data/lib/arel_extensions/nodes/union_all.rb +8 -5
  72. data/lib/arel_extensions/nodes/wday.rb +6 -2
  73. data/lib/arel_extensions/nodes.rb +1 -1
  74. data/lib/arel_extensions/null_functions.rb +6 -18
  75. data/lib/arel_extensions/predications.rb +49 -54
  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 +55 -110
  79. data/lib/arel_extensions/tasks.rb +6 -6
  80. data/lib/arel_extensions/version.rb +1 -3
  81. data/lib/arel_extensions/visitors/ibm_db.rb +36 -29
  82. data/lib/arel_extensions/visitors/mssql.rb +248 -493
  83. data/lib/arel_extensions/visitors/mysql.rb +244 -420
  84. data/lib/arel_extensions/visitors/oracle.rb +258 -311
  85. data/lib/arel_extensions/visitors/oracle12.rb +34 -20
  86. data/lib/arel_extensions/visitors/postgresql.rb +239 -350
  87. data/lib/arel_extensions/visitors/sqlite.rb +169 -191
  88. data/lib/arel_extensions/visitors/to_sql.rb +299 -371
  89. data/lib/arel_extensions/visitors.rb +62 -83
  90. data/lib/arel_extensions.rb +32 -243
  91. data/test/database.yml +10 -20
  92. data/test/helper.rb +18 -0
  93. data/test/real_db_test.rb +120 -123
  94. data/test/support/fake_record.rb +3 -11
  95. data/test/test_comparators.rb +17 -14
  96. data/test/visitors/test_bulk_insert_oracle.rb +12 -12
  97. data/test/visitors/test_bulk_insert_sqlite.rb +14 -13
  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 +375 -912
  102. data/test/with_ar/insert_agnostic_test.rb +22 -28
  103. data/test/with_ar/test_bulk_sqlite.rb +17 -18
  104. data/test/with_ar/test_math_sqlite.rb +27 -27
  105. data/test/with_ar/test_string_mysql.rb +34 -32
  106. data/test/with_ar/test_string_sqlite.rb +35 -31
  107. metadata +64 -50
  108. data/.github/workflows/publish.yml +0 -30
  109. data/.github/workflows/release.yml +0 -30
  110. data/.github/workflows/ruby.yml +0 -452
  111. data/CONTRIBUTING.md +0 -102
  112. data/Makefile +0 -48
  113. data/NEWS.md +0 -131
  114. data/bin/build +0 -15
  115. data/bin/publish +0 -8
  116. data/dev/arelx.dockerfile +0 -41
  117. data/dev/compose.yaml +0 -69
  118. data/dev/postgres.dockerfile +0 -5
  119. data/dev/rbenv +0 -189
  120. data/gemfiles/rails5.gemfile +0 -36
  121. data/gemfiles/rails6.gemfile +0 -40
  122. data/gemfiles/rails6_1.gemfile +0 -48
  123. data/gemfiles/rails7.gemfile +0 -48
  124. data/gemfiles/rails7_1.gemfile +0 -48
  125. data/gemfiles/rails7_2.gemfile +0 -47
  126. data/gemfiles/rails8.gemfile +0 -40
  127. data/gemfiles/rails8_1.gemfile +0 -41
  128. data/gemspecs/arel_extensions-v1.gemspec +0 -25
  129. data/gemspecs/arel_extensions-v2.gemspec +0 -25
  130. data/generate_gems.sh +0 -15
  131. data/lib/arel_extensions/aliases.rb +0 -14
  132. data/lib/arel_extensions/constants.rb +0 -13
  133. data/lib/arel_extensions/helpers.rb +0 -61
  134. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
  135. data/lib/arel_extensions/nodes/byte_size.rb +0 -11
  136. data/lib/arel_extensions/nodes/char_length.rb +0 -11
  137. data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
  138. data/lib/arel_extensions/nodes/rollup.rb +0 -36
  139. data/lib/arel_extensions/nodes/select.rb +0 -10
  140. data/lib/arel_extensions/nodes/sum.rb +0 -7
  141. data/lib/arel_extensions/visitors/convert_format.rb +0 -37
  142. data/lib/arel_extensions/warning.rb +0 -42
  143. data/test/arelx_test_helper.rb +0 -94
  144. data/test/config_loader.rb +0 -9
  145. data/version_v1.rb +0 -5
  146. data/version_v2.rb +0 -5
@@ -3,35 +3,23 @@ require 'arel_extensions/nodes/is_null'
3
3
 
4
4
  module ArelExtensions
5
5
  module NullFunctions
6
- # if_present returns nil if the the value is nil or blank
7
- def if_present
8
- Arel.when(cast(:string).present).then(self)
9
- end
10
6
 
11
- # ISNULL function lets you return an alternative value when an expression is NULL.
7
+ #ISNULL function lets you return an alternative value when an expression is NULL.
12
8
  def is_null
13
9
  ArelExtensions::Nodes::IsNull.new [self]
14
10
  end
15
-
16
- # 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.
17
13
  def is_not_null
18
14
  ArelExtensions::Nodes::IsNotNull.new [self]
19
15
  end
20
-
16
+
21
17
  # returns the first non-null expr in the expression list. You must specify at least two expressions.
22
- # If all occurrences of expr evaluate to null, then the function returns null.
23
- def coalesce(*args)
18
+ #If all occurrences of expr evaluate to null, then the function returns null.
19
+ def coalesce *args
24
20
  args.unshift(self)
25
21
  ArelExtensions::Nodes::Coalesce.new args
26
22
  end
27
23
 
28
- def coalesce_blank(*args)
29
- res = Arel.when(cast(:string).present).then(self)
30
- args[0...-1].each do |a|
31
- val = a.is_a?(Arel::Nodes::Node) ? a : Arel.quoted(a)
32
- res = res.when(val.present).then(a)
33
- end
34
- res.else(args[-1])
35
- end
36
24
  end
37
25
  end
@@ -1,80 +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)
8
- if AREL_VERSION < V7
9
- Arel::Nodes::Matches.new(self, Arel.quoted(other), escape)
7
+ def matches(other, escape=nil,case_sensitive= nil)
8
+ if Arel::VERSION.to_i < 7
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
- def cast(right)
20
- ArelExtensions::Nodes::Cast.new([self, right])
19
+ def cast 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
- between(other)
28
- when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
29
- Arel::Nodes::In.new(self, quoted_node(other))
26
+ self.between(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]) : eq(values[0])]
39
- else [Arel::Nodes::In.new(self, quoted_array(values))]
40
- end) \
41
- + ranges.uniq.map { |r| self.in(r) }
42
- 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
43
41
  when nil
44
- is_null
42
+ self.is_null
45
43
  when Arel::SelectManager
46
44
  Arel::Nodes::In.new(self, other.ast)
47
45
  else
48
- Arel::Nodes::In.new(self, quoted_node(other))
46
+ Arel::Nodes::In.new(self,quoted_node(other))
49
47
  end
50
48
  end
51
49
 
52
- def not_in(*other) # In should handle nil element in the Array
53
- other = other.first if other.length <= 1
50
+ def not_in(other) #In should handle nil element in the Array
54
51
  case other
55
52
  when Range
56
- Arel::Nodes::Not.new(between(other))
57
- when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
58
- Arel::Nodes::NotIn.new(self, quoted_node(other))
53
+ Arel::Nodes::Not.new(self.between(other))
59
54
  when Enumerable
60
- nils, values = other.partition { |v| v.nil? }
61
- ranges, values = values.partition { |v| v.is_a?(Range) || v.is_a?(Arel::SelectManager) }
62
- # In order of (imagined) decreasing efficiency: nil, values, and then more complex.
63
- clauses =
64
- nils.uniq.map { |r| not_in(r) } \
65
- + (case values.uniq.size
66
- when 0 then []
67
- when 1 then [values[0].is_a?(Arel::Nodes::Grouping) ? not_in(values[0]) : not_eq(values[0])]
68
- else [Arel::Nodes::NotIn.new(self, quoted_array(values))]
69
- end) \
70
- + ranges.uniq.map { |r| not_in(r) }
71
- 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
72
68
  when nil
73
- is_not_null
69
+ self.is_not_null
74
70
  when Arel::SelectManager
75
71
  Arel::Nodes::NotIn.new(self, other.ast)
76
72
  else
77
- Arel::Nodes::NotIn.new(self, quoted_node(other))
73
+ Arel::Nodes::NotIn.new(self,quoted_node(other))
78
74
  end
79
75
  end
80
76
 
@@ -83,22 +79,21 @@ module ArelExtensions
83
79
  when Arel::Attributes::Attribute, Arel::Nodes::Node, Integer
84
80
  object
85
81
  when DateTime
86
- Arel.quoted(object, self)
82
+ Arel::Nodes.build_quoted(object, self)
87
83
  when Time
88
- Arel.quoted(object.strftime('%H:%M:%S'), self)
84
+ Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
89
85
  when String
90
- Arel.quoted(object)
91
- when TrueClass, FalseClass
92
- Arel.quoted(object)
86
+ Arel::Nodes.build_quoted(object)
93
87
  when Date
94
- Arel.quoted(object.to_s, self)
88
+ Arel::Nodes.build_quoted(object.to_s, self)
95
89
  when NilClass
96
90
  Arel.sql('NULL')
97
91
  when ActiveSupport::Duration
98
92
  object.to_i
99
93
  else
100
- raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
94
+ raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
101
95
  end
102
96
  end
97
+
103
98
  end
104
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,6 +1,4 @@
1
- require 'arel_extensions/nodes/byte_size'
2
- require 'arel_extensions/nodes/char_length'
3
- require 'arel_extensions/nodes/concat' # if Arel::VERSION.to_i < 7
1
+ require 'arel_extensions/nodes/concat' #if Arel::VERSION.to_i < 7
4
2
  require 'arel_extensions/nodes/length'
5
3
  require 'arel_extensions/nodes/locate'
6
4
  require 'arel_extensions/nodes/substring'
@@ -18,179 +16,127 @@ require 'arel_extensions/nodes/collate'
18
16
  require 'arel_extensions/nodes/levenshtein_distance'
19
17
  require 'arel_extensions/nodes/md5'
20
18
 
19
+
21
20
  module ArelExtensions
22
21
  module StringFunctions
23
- include ArelExtensions::Warning
24
22
 
25
- # *FindInSet function .......
23
+ #*FindInSet function .......
26
24
  def &(other)
27
- ArelExtensions::Nodes::FindInSet.new [
28
- Arel.quoted(other.is_a?(Integer) ? other.to_s : other),
29
- self
30
- ]
25
+ ArelExtensions::Nodes::FindInSet.new [other, self]
31
26
  end
32
27
 
33
- # 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.
34
29
  def length
35
- deprecated "Use `byte_size` or `char_length` instead. `length` relies on the vendor's `LEN/LENGTH` implementation and it's not portable"
36
- ArelExtensions::Nodes::Length.new self, true
37
- end
38
-
39
- def byte_length
40
- deprecated "Use `byte_size` instead. `byte_length` relies on the vendor's `LEN/LENGTH` implementation and it's not portable"
41
- ArelExtensions::Nodes::Length.new self, true
42
- end
43
-
44
- def byte_size
45
- ArelExtensions::Nodes::ByteSize.new self
46
- end
47
-
48
- def char_length
49
- ArelExtensions::Nodes::CharLength.new self
30
+ ArelExtensions::Nodes::Length.new [self]
50
31
  end
51
32
 
52
- # LOCATE function returns the first starting position of a string in another string.
53
- # If string1 or string2 is NULL then it returns NULL. If string1 not found in string2 then it returns 0.
54
- def locate(val)
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.
35
+ def locate val
55
36
  ArelExtensions::Nodes::Locate.new [self, val]
56
37
  end
57
38
 
58
- def substring(start, len = nil)
39
+ def substring start, len = nil
59
40
  ArelExtensions::Nodes::Substring.new [self, start, len]
60
41
  end
61
42
 
62
- # Return a [ArelExtensions::Nodes::Substring] if `start` is a [Range] or an
63
- # [Integer].
64
- #
65
- # Return the result to `self.send(start)` if it's a [String|Symbol]. The
66
- # assumption is that you're trying to reach an [Arel::Table]'s
67
- # [Arel::Attribute].
68
- #
69
- # @note `ind` should be an [Integer|NilClass] if `start` is an [Integer].
70
- # It's ignored in all other cases.
71
- def [](start, end_ = nil)
72
- if start.is_a?(String) || start.is_a?(Symbol)
73
- send(start)
74
- elsif start.is_a?(Range)
75
- ArelExtensions::Nodes::Substring.new [self, start]
76
- elsif start.is_a?(Integer) && !end_
77
- ArelExtensions::Nodes::Substring.new [self, start + 1, 1]
78
- elsif start.is_a?(Integer)
79
- start += 1
80
- ArelExtensions::Nodes::Substring.new [self, start, end_ - start + 1]
43
+ def [](start, ind = nil)
44
+ start += 1 if start.is_a?(Integer)
45
+ if start.is_a?(Range)
46
+ ArelExtensions::Nodes::Substring.new [self, start.begin + 1, start.end - start.begin + 1]
47
+ elsif start.is_a?(Integer) && !ind
48
+ ArelExtensions::Nodes::Substring.new [self, start, 1]
81
49
  else
82
- raise ArgumentError, 'unrecognized argument types; can accept integers, ranges, or strings.'
50
+ ArelExtensions::Nodes::Substring.new [self, start, ind - start + 1]
83
51
  end
84
52
  end
85
53
 
86
- # 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.
87
55
  def soundex
88
56
  ArelExtensions::Nodes::Soundex.new [self]
89
57
  end
90
58
 
91
- def imatches(others, escape = nil)
59
+ def imatches others, escape = nil
92
60
  ArelExtensions::Nodes::IMatches.new self, others, escape
93
61
  end
94
62
 
95
- def imatches_any(others, escape = nil)
63
+ def imatches_any others, escape = nil
96
64
  grouping_any :imatches, others, escape
97
65
  end
98
66
 
99
- # def grouping_any method, others, *extra
100
- # puts "*******************"
101
- # puts method
102
- # puts others.inspect
103
- # puts extra.inspect
104
- # puts "-------------------"
105
- # res = super(method,others,*extra)
106
- # puts res.to_sql
107
- # puts res.inspect
108
- # puts "*******************"
109
- # res
110
- # end
111
-
112
- def imatches_all(others, escape = nil)
67
+ def imatches_all others, escape = nil
113
68
  grouping_all :imatches, others, escape, escape
114
69
  end
115
70
 
116
- def idoes_not_match(others, escape = nil)
71
+ def idoes_not_match others, escape = nil
117
72
  ArelExtensions::Nodes::IDoesNotMatch.new self, others, escape
118
73
  end
119
74
 
120
- def idoes_not_match_any(others, escape = nil)
75
+ def idoes_not_match_any others, escape = nil
121
76
  grouping_any :idoes_not_match, others, escape
122
77
  end
123
78
 
124
- def idoes_not_match_all(others, escape = nil)
79
+ def idoes_not_match_all others, escape = nil
125
80
  grouping_all :idoes_not_match, others, escape
126
81
  end
127
82
 
128
- def ai_matches(other) # accent insensitive & case sensitive
129
- ArelExtensions::Nodes::AiMatches.new(self, other)
83
+ def ai_matches other # accent insensitive & case sensitive
84
+ ArelExtensions::Nodes::AiMatches.new(self,other)
130
85
  end
131
86
 
132
- def ai_imatches(other) # accent insensitive & case insensitive
133
- ArelExtensions::Nodes::AiIMatches.new(self, other)
87
+ def ai_imatches other # accent insensitive & case insensitive
88
+ ArelExtensions::Nodes::AiIMatches.new(self,other)
134
89
  end
135
90
 
136
- def smatches(other) # accent sensitive & case sensitive
137
- ArelExtensions::Nodes::SMatches.new(self, other)
91
+ def smatches other # accent sensitive & case sensitive
92
+ ArelExtensions::Nodes::SMatches.new(self,other)
138
93
  end
139
94
 
140
- def ai_collate
141
- ArelExtensions::Nodes::Collate.new(self, nil, true, false)
95
+ def ai_collate
96
+ ArelExtensions::Nodes::Collate.new(self,nil,true,false)
142
97
  end
143
98
 
144
99
  def ci_collate
145
- ArelExtensions::Nodes::Collate.new(self, nil, false, true)
100
+ ArelExtensions::Nodes::Collate.new(self,nil,false,true)
146
101
  end
147
102
 
148
- def collate(ai = false, ci = false, option = nil)
149
- ArelExtensions::Nodes::Collate.new(self, option, ai, ci)
103
+ def collate ai=false,ci=false, option=nil
104
+ ArelExtensions::Nodes::Collate.new(self,option,ai,ci)
150
105
  end
151
106
 
152
- # REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.
153
- def replace(pattern, substitute)
154
- if pattern.is_a? Regexp
155
- ArelExtensions::Nodes::RegexpReplace.new self, pattern, substitute
156
- else
157
- ArelExtensions::Nodes::Replace.new self, pattern, substitute
158
- end
159
- end
160
-
161
- def regexp_replace(pattern, substitute)
162
- 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]
163
110
  end
164
-
165
- def concat(other)
111
+
112
+ def concat other
166
113
  ArelExtensions::Nodes::Concat.new [self, other]
167
114
  end
168
115
 
169
- # concat elements of a group, separated by sep and ordered by a list of Ascending or Descending
170
- def group_concat(sep = nil, *orders, group: nil, order: nil)
171
- if orders.present?
172
- deprecated 'Use the kwarg `order` instead.', what: 'orders'
173
- end
174
- order_tabs = [orders].flatten.map { |o|
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
118
+ order_tabs = [orders].flatten.map{ |o|
175
119
  if o.is_a?(Arel::Nodes::Ascending) || o.is_a?(Arel::Nodes::Descending)
176
120
  o
177
121
  elsif o.respond_to?(:asc)
178
122
  o.asc
123
+ else
124
+ nil
179
125
  end
180
126
  }.compact
181
- ArelExtensions::Nodes::GroupConcat.new(self, sep, group: group, order: order || order_tabs)
127
+ ArelExtensions::Nodes::GroupConcat.new [self, sep, order_tabs]
182
128
  end
183
129
 
184
- # Function returns a string after removing left, right or the both prefixes or suffixes int argument
185
- def trim(other = ' ')
130
+ #Function returns a string after removing left, right or the both prefixes or suffixes int argument
131
+ def trim other = ' '
186
132
  ArelExtensions::Nodes::Trim.new [self, other]
187
133
  end
188
134
 
189
- def ltrim(other = ' ')
135
+ def ltrim other = ' '
190
136
  ArelExtensions::Nodes::Ltrim.new [self, other]
191
137
  end
192
138
 
193
- def rtrim(other = ' ')
139
+ def rtrim other = ' '
194
140
  ArelExtensions::Nodes::Rtrim.new [self, other]
195
141
  end
196
142
 
@@ -209,17 +155,16 @@ module ArelExtensions
209
155
  def not_blank
210
156
  ArelExtensions::Nodes::NotBlank.new [self]
211
157
  end
212
- alias present not_blank
213
-
214
- def repeat(other = 1)
158
+
159
+ def repeat other = 1
215
160
  ArelExtensions::Nodes::Repeat.new [self, other]
216
161
  end
217
-
218
- def levenshtein_distance(other)
162
+
163
+ def levenshtein_distance other
219
164
  ArelExtensions::Nodes::LevenshteinDistance.new [self, other]
220
165
  end
221
166
 
222
- def edit_distance(other)
167
+ def edit_distance other
223
168
  ArelExtensions::Nodes::LevenshteinDistance.new [self, other]
224
169
  end
225
170
 
@@ -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,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module ArelExtensions
4
- VERSION = '1.7.0'
2
+ VERSION = "2.0.0.rc3".freeze
5
3
  end
@@ -1,69 +1,76 @@
1
1
  module ArelExtensions
2
2
  module Visitors
3
- class Arel::Visitors::IBM_DB
4
- def visit_ArelExtensions_Nodes_Ceil(o, collector)
5
- collector << 'CEILING('
3
+ Arel::Visitors::IBM_DB.class_eval do
4
+
5
+ def visit_ArelExtensions_Nodes_Ceil o, collector
6
+ collector << "CEILING("
6
7
  collector = visit o.expr, collector
7
- collector << ')'
8
+ collector << ")"
8
9
  collector
9
10
  end
10
11
 
11
- def visit_ArelExtensions_Nodes_Trim(o, collector)
12
- collector << 'LTRIM(RTRIM('
12
+ def visit_ArelExtensions_Nodes_Trim o, collector
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
 
21
- def visit_ArelExtensions_Nodes_DateDiff(o, collector)
22
- collector << 'DAY('
22
+
23
+ def visit_ArelExtensions_Nodes_DateDiff o, collector
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
 
34
- 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('
36
+
37
+ def visit_ArelExtensions_Nodes_Duration o, collector
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
 
55
- def visit_ArelExtensions_Nodes_IsNull(o, collector)
56
- collector << 'COALESCE('
58
+
59
+ def visit_ArelExtensions_Nodes_IsNull o, collector
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