arel_extensions 1.2.25 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -7
  3. data/.travis.yml +91 -61
  4. data/Gemfile +20 -15
  5. data/README.md +12 -17
  6. data/Rakefile +29 -40
  7. data/appveyor.yml +1 -1
  8. data/arel_extensions.gemspec +3 -3
  9. data/functions.html +3 -3
  10. data/gemfiles/rails3.gemfile +9 -9
  11. data/gemfiles/rails4.gemfile +13 -13
  12. data/gemfiles/rails5_0.gemfile +13 -13
  13. data/gemfiles/rails5_1_4.gemfile +13 -13
  14. data/gemfiles/rails5_2.gemfile +13 -13
  15. data/init/mssql.sql +4 -4
  16. data/init/mysql.sql +38 -38
  17. data/init/postgresql.sql +21 -21
  18. data/lib/arel_extensions/attributes.rb +1 -0
  19. data/lib/arel_extensions/boolean_functions.rb +14 -55
  20. data/lib/arel_extensions/common_sql_functions.rb +8 -7
  21. data/lib/arel_extensions/comparators.rb +15 -14
  22. data/lib/arel_extensions/date_duration.rb +5 -4
  23. data/lib/arel_extensions/insert_manager.rb +16 -17
  24. data/lib/arel_extensions/math.rb +12 -11
  25. data/lib/arel_extensions/math_functions.rb +22 -29
  26. data/lib/arel_extensions/nodes/abs.rb +1 -0
  27. data/lib/arel_extensions/nodes/blank.rb +1 -0
  28. data/lib/arel_extensions/nodes/case.rb +8 -11
  29. data/lib/arel_extensions/nodes/cast.rb +2 -4
  30. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  31. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  32. data/lib/arel_extensions/nodes/coalesce.rb +3 -2
  33. data/lib/arel_extensions/nodes/collate.rb +2 -1
  34. data/lib/arel_extensions/nodes/concat.rb +16 -7
  35. data/lib/arel_extensions/nodes/date_diff.rb +13 -10
  36. data/lib/arel_extensions/nodes/duration.rb +3 -0
  37. data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
  38. data/lib/arel_extensions/nodes/floor.rb +1 -1
  39. data/lib/arel_extensions/nodes/format.rb +8 -34
  40. data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
  41. data/lib/arel_extensions/nodes/function.rb +16 -25
  42. data/lib/arel_extensions/nodes/json.rb +36 -43
  43. data/lib/arel_extensions/nodes/length.rb +0 -5
  44. data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
  45. data/lib/arel_extensions/nodes/locate.rb +1 -0
  46. data/lib/arel_extensions/nodes/log10.rb +2 -1
  47. data/lib/arel_extensions/nodes/matches.rb +6 -4
  48. data/lib/arel_extensions/nodes/md5.rb +1 -0
  49. data/lib/arel_extensions/nodes/power.rb +5 -5
  50. data/lib/arel_extensions/nodes/rand.rb +1 -0
  51. data/lib/arel_extensions/nodes/repeat.rb +4 -2
  52. data/lib/arel_extensions/nodes/replace.rb +6 -22
  53. data/lib/arel_extensions/nodes/round.rb +6 -5
  54. data/lib/arel_extensions/nodes/soundex.rb +15 -15
  55. data/lib/arel_extensions/nodes/std.rb +21 -18
  56. data/lib/arel_extensions/nodes/substring.rb +16 -8
  57. data/lib/arel_extensions/nodes/then.rb +0 -0
  58. data/lib/arel_extensions/nodes/trim.rb +5 -3
  59. data/lib/arel_extensions/nodes/union.rb +5 -2
  60. data/lib/arel_extensions/nodes/union_all.rb +3 -0
  61. data/lib/arel_extensions/nodes/wday.rb +4 -0
  62. data/lib/arel_extensions/nodes.rb +1 -1
  63. data/lib/arel_extensions/null_functions.rb +7 -5
  64. data/lib/arel_extensions/predications.rb +34 -35
  65. data/lib/arel_extensions/railtie.rb +5 -5
  66. data/lib/arel_extensions/set_functions.rb +4 -2
  67. data/lib/arel_extensions/string_functions.rb +23 -52
  68. data/lib/arel_extensions/tasks.rb +5 -5
  69. data/lib/arel_extensions/version.rb +1 -1
  70. data/lib/arel_extensions/visitors/ibm_db.rb +12 -5
  71. data/lib/arel_extensions/visitors/mssql.rb +58 -64
  72. data/lib/arel_extensions/visitors/mysql.rb +98 -149
  73. data/lib/arel_extensions/visitors/oracle.rb +70 -73
  74. data/lib/arel_extensions/visitors/oracle12.rb +15 -2
  75. data/lib/arel_extensions/visitors/postgresql.rb +63 -116
  76. data/lib/arel_extensions/visitors/sqlite.rb +70 -83
  77. data/lib/arel_extensions/visitors/to_sql.rb +110 -142
  78. data/lib/arel_extensions/visitors.rb +60 -68
  79. data/lib/arel_extensions.rb +19 -81
  80. data/test/database.yml +0 -2
  81. data/test/helper.rb +18 -0
  82. data/test/real_db_test.rb +43 -28
  83. data/test/support/fake_record.rb +2 -2
  84. data/test/test_comparators.rb +12 -9
  85. data/test/visitors/test_bulk_insert_oracle.rb +8 -8
  86. data/test/visitors/test_bulk_insert_sqlite.rb +10 -9
  87. data/test/visitors/test_bulk_insert_to_sql.rb +10 -8
  88. data/test/visitors/test_oracle.rb +42 -42
  89. data/test/visitors/test_to_sql.rb +196 -361
  90. data/test/with_ar/all_agnostic_test.rb +160 -195
  91. data/test/with_ar/insert_agnostic_test.rb +4 -3
  92. data/test/with_ar/test_bulk_sqlite.rb +9 -6
  93. data/test/with_ar/test_math_sqlite.rb +12 -8
  94. data/test/with_ar/test_string_mysql.rb +11 -5
  95. data/test/with_ar/test_string_sqlite.rb +12 -4
  96. metadata +11 -22
  97. data/.github/workflows/ruby.yml +0 -102
  98. data/gemfiles/rails6.gemfile +0 -30
  99. data/gemfiles/rails6_1.gemfile +0 -30
  100. data/gemspecs/arel_extensions-v1.gemspec +0 -28
  101. data/gemspecs/arel_extensions-v2.gemspec +0 -28
  102. data/generate_gems.sh +0 -15
  103. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
  104. data/lib/arel_extensions/nodes/sum.rb +0 -7
  105. data/lib/arel_extensions/visitors/convert_format.rb +0 -37
  106. data/test/arelx_test_helper.rb +0 -26
  107. data/version_v1.rb +0 -3
  108. data/version_v2.rb +0 -3
@@ -11,9 +11,9 @@ require 'arel_extensions/nodes/union_all'
11
11
 
12
12
  module ArelExtensions
13
13
  module Math
14
- # function + between
15
- # String and others (convert in string) allows you to concatenate 2 or more strings together.
16
- # Date and integer adds or subtracts a specified time interval from a date.
14
+ #function + between
15
+ #String and others (convert in string) allows you to concatenate 2 or more strings together.
16
+ #Date and integer adds or subtracts a specified time interval from a date.
17
17
  def +(other)
18
18
  case self
19
19
  when Arel::Nodes::Quoted
@@ -24,7 +24,7 @@ module ArelExtensions
24
24
  else
25
25
  return Arel::Nodes::Grouping.new(Arel::Nodes::Addition.new self, other)
26
26
  end
27
- when ArelExtensions::Nodes::Function,ArelExtensions::Nodes::Case
27
+ when ArelExtensions::Nodes::Function,ArelExtensions::Nodes::Case
28
28
  return case self.return_type
29
29
  when :string, :text
30
30
  self.concat(other)
@@ -35,7 +35,7 @@ module ArelExtensions
35
35
  else
36
36
  self.concat(other)
37
37
  end
38
- when Arel::Nodes::Function
38
+ when Arel::Nodes::Function
39
39
  Arel::Nodes::Grouping.new(Arel::Nodes::Addition.new self, other)
40
40
  else
41
41
  begin
@@ -43,7 +43,7 @@ module ArelExtensions
43
43
  rescue Exception
44
44
  col = nil
45
45
  end
46
- if (!col) # if the column doesn't exist in the database
46
+ if (!col) #if the column doesn't exist in the database
47
47
  Arel::Nodes::Grouping.new(Arel::Nodes::Addition.new(self, other))
48
48
  else
49
49
  arg = col.type
@@ -62,8 +62,8 @@ module ArelExtensions
62
62
  end
63
63
  end
64
64
 
65
- # function returns the time between two dates
66
- # function returns the substraction between two ints
65
+ #function returns the time between two dates
66
+ #function returns the substraction between two ints
67
67
  def -(other)
68
68
  case self
69
69
  when Arel::Nodes::Grouping
@@ -91,7 +91,7 @@ module ArelExtensions
91
91
  rescue Exception
92
92
  col = nil
93
93
  end
94
- if (!col) # if the column doesn't exist in the database
94
+ if (!col) #if the column doesn't exist in the database
95
95
  Arel::Nodes::Grouping.new(Arel::Nodes::Subtraction.new(self, other))
96
96
  else
97
97
  arg = col.type
@@ -103,7 +103,7 @@ module ArelExtensions
103
103
  rescue Exception
104
104
  col2 = nil
105
105
  end
106
- if (!col2) # if the column doesn't exist in the database
106
+ if (!col2) #if the column doesn't exist in the database
107
107
  ArelExtensions::Nodes::DateSub.new [self, other]
108
108
  else
109
109
  arg2 = col2.type
@@ -115,7 +115,7 @@ module ArelExtensions
115
115
  end
116
116
  when Arel::Nodes::Node, DateTime, Time, String, Date
117
117
  ArelExtensions::Nodes::DateDiff.new [self, other]
118
- when ArelExtensions::Nodes::Duration, Integer
118
+ when ArelExtensions::Nodes::Duration, Integer
119
119
  ArelExtensions::Nodes::DateSub.new [self, other]
120
120
  else # ActiveSupport::Duration
121
121
  ArelExtensions::Nodes::DateAdd.new [self, -other]
@@ -133,5 +133,6 @@ module ArelExtensions
133
133
  end
134
134
  end
135
135
  end
136
+
136
137
  end
137
138
  end
@@ -7,10 +7,10 @@ require 'arel_extensions/nodes/formatted_number'
7
7
  require 'arel_extensions/nodes/log10'
8
8
  require 'arel_extensions/nodes/power'
9
9
  require 'arel_extensions/nodes/std'
10
- require 'arel_extensions/nodes/sum'
11
10
 
12
11
  module ArelExtensions
13
12
  module MathFunctions
13
+
14
14
  # Arel does not handle Decimal literal properly
15
15
  def * other
16
16
  case other
@@ -46,7 +46,7 @@ module ArelExtensions
46
46
  ArelExtensions::Nodes::Floor.new [self]
47
47
  end
48
48
 
49
- # function gives the base 10 log
49
+ # function gives the base 10 log
50
50
  def log10
51
51
  ArelExtensions::Nodes::Log10.new [self]
52
52
  end
@@ -62,29 +62,21 @@ module ArelExtensions
62
62
  end
63
63
 
64
64
  # Aggregate Functions
65
- def std opts = {unbiased: true}
66
- ArelExtensions::Nodes::Std.new self, **opts
67
- end
68
-
69
- def variance opts = {unbiased: true}
70
- ArelExtensions::Nodes::Variance.new self, **opts
65
+ def std unbiased = true
66
+ ArelExtensions::Nodes::Std.new [self,unbiased]
71
67
  end
72
68
 
73
- def sum opts = {unbiased: true}
74
- if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("9.0.0")
75
- Arel::Nodes::Sum.new [self]
76
- else
77
- ArelExtensions::Nodes::Sum.new self, **opts
78
- end
69
+ def variance unbiased = true
70
+ ArelExtensions::Nodes::Variance.new [self,unbiased]
79
71
  end
80
72
 
81
- # function that can be invoked to produce random numbers between 0 and 1
82
- # def rand seed = nil
83
- # ArelExtensions::Nodes::Rand.new [seed]
84
- # end
85
- alias_method(:random, :rand) rescue nil
73
+ #function that can be invoked to produce random numbers between 0 and 1
74
+ # def rand seed = nil
75
+ # ArelExtensions::Nodes::Rand.new [seed]
76
+ # end
77
+ alias_method :random, :rand
86
78
 
87
- # function is used to round a numeric field to the number of decimals specified
79
+ #function is used to round a numeric field to the number of decimals specified
88
80
  def round precision = nil
89
81
  if precision
90
82
  ArelExtensions::Nodes::Round.new [self, precision]
@@ -94,19 +86,19 @@ module ArelExtensions
94
86
  end
95
87
 
96
88
  # function returning a number at a specific format
97
- def format_number format_string, locale = nil
89
+ def format_number format_string, locale=nil
98
90
  begin
99
91
  sprintf(format_string,0) # this line is to get the right error message if the format_string is not correct
100
92
  m = /^(.*)%([ #+\-0]*)([1-9][0-9]+|[1-9]?)[.]?([0-9]*)([a-zA-Z])(.*)$/.match(format_string)
101
93
  opts = {
102
- prefix: m[1],
103
- flags: m[2].split(//).uniq.join,
104
- width: m[3].to_i,
105
- precision: m[4] != '' ? m[4].to_i : 6,
106
- type: m[5],
107
- suffix: m[6],
108
- locale: locale,
109
- original_string: format_string
94
+ :prefix => m[1],
95
+ :flags => m[2].split(//).uniq.join,
96
+ :width => m[3].to_i,
97
+ :precision => m[4] != '' ? m[4].to_i : 6,
98
+ :type => m[5],
99
+ :suffix => m[6],
100
+ :locale => locale,
101
+ :original_string => format_string
110
102
  }
111
103
  # opts = {:locale => 'fr_FR', :type => "e"/"f"/"d", :prefix => "$ ", :suffix => " %", :flags => " +-#0", :width => 5, :precision => 6}
112
104
  ArelExtensions::Nodes::FormattedNumber.new [self,opts]
@@ -114,5 +106,6 @@ module ArelExtensions
114
106
  Arel::Nodes.build_quoted('Wrong Format')
115
107
  end
116
108
  end
109
+
117
110
  end
118
111
  end
@@ -2,6 +2,7 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class Abs < Function
4
4
  RETURN_TYPE = :number
5
+
5
6
  end
6
7
  end
7
8
  end
@@ -19,5 +19,6 @@ module ArelExtensions
19
19
  super expr.first
20
20
  end
21
21
  end
22
+
22
23
  end
23
24
  end
@@ -1,11 +1,7 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
- if Gem::Version.new(Arel::VERSION) < Gem::Version.new("7.1.0")
3
+ if Arel::VERSION < "7.1.0"
4
4
  class Case < Arel::Nodes::Node
5
- include Arel::Expressions
6
- include Arel::Math
7
- include Arel::Predications
8
- include Arel::OrderPredications
9
5
  attr_accessor :case, :conditions, :default
10
6
 
11
7
  def initialize expression = nil, default = nil
@@ -19,6 +15,7 @@ module ArelExtensions
19
15
 
20
16
  class Else < Arel::Nodes::Unary # :nodoc:
21
17
  end
18
+
22
19
  end
23
20
  else
24
21
  class Case < Arel::Nodes::Case
@@ -29,10 +26,8 @@ module ArelExtensions
29
26
  end
30
27
  end
31
28
 
32
- class ArelExtensions::Nodes::Case
29
+ ArelExtensions::Nodes::Case.class_eval do
33
30
  include Arel::Expressions
34
- include Arel::Math
35
- include Arel::Predications
36
31
  include Arel::OrderPredications
37
32
  include ArelExtensions::Math
38
33
  include ArelExtensions::Comparators
@@ -46,6 +41,8 @@ module ArelExtensions
46
41
  @conditions.last.right
47
42
  elsif @default
48
43
  @default.expr
44
+ else
45
+ nil
49
46
  end
50
47
  if obj.respond_to?(:return_type)
51
48
  obj.return_type
@@ -95,9 +92,9 @@ module ArelExtensions
95
92
 
96
93
  def eql? other
97
94
  self.class == other.class &&
98
- self.case == other.case &&
99
- self.conditions == other.conditions &&
100
- self.default == other.default
95
+ self.case == other.case &&
96
+ self.conditions == other.conditions &&
97
+ self.default == other.default
101
98
  end
102
99
  alias :== :eql?
103
100
 
@@ -14,10 +14,7 @@ module ArelExtensions
14
14
  @return_type = :decimal
15
15
  when :number
16
16
  @return_type = :number
17
- when 'char', 'varchar', 'nchar', 'nvarchar'
18
- @return_type = :string
19
- when 'text', :text, 'ntext', :ntext
20
- @as_attr = expr[1].to_sym
17
+ when 'char', 'varchar', 'text', 'nchar', 'nvarchar', 'ntext'
21
18
  @return_type = :string
22
19
  when :datetime, 'datetime','smalldatetime'
23
20
  @return_type = :datetime
@@ -49,6 +46,7 @@ module ArelExtensions
49
46
  def return_type
50
47
  @return_type
51
48
  end
49
+
52
50
  end
53
51
  end
54
52
  end
@@ -1,7 +1,7 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Ceil < Function
4
- RETURN_TYPE = :number
4
+ RETURN_TYPE = :number
5
5
  end
6
6
  end
7
7
  end
File without changes
@@ -2,7 +2,7 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class Coalesce < Function
4
4
  RETURN_TYPE = :string
5
-
5
+
6
6
  attr_accessor :left_node_type
7
7
 
8
8
  def return_type
@@ -20,7 +20,7 @@ module ArelExtensions
20
20
  @left_node_type = :number
21
21
  when ArelExtensions::Nodes::Coalesce, ArelExtensions::Nodes::Function
22
22
  @left_node_type = expr.first.respond_to?(:left_node_type) ? expr.first.left_node_type : nil
23
- when Arel::Nodes::Node, Arel::Attributes::Attribute
23
+ when Arel::Nodes::Node, Arel::Attributes::Attribute
24
24
  @left_node_type = type_of_attribute(expr.first)
25
25
  when Date
26
26
  @left_node_type = :ruby_date
@@ -29,6 +29,7 @@ module ArelExtensions
29
29
  end
30
30
  return super(tab)
31
31
  end
32
+
32
33
  end
33
34
  end
34
35
  end
@@ -5,13 +5,14 @@ module ArelExtensions
5
5
 
6
6
  attr_accessor :ai, :ci, :option
7
7
 
8
- def initialize left, option = nil, ai = false, ci = false
8
+ def initialize left, option=nil, ai=false, ci=false
9
9
  @ai = ai
10
10
  @ci = ci
11
11
  @option = option
12
12
  tab = [convert_to_node(left)]
13
13
  return super(tab)
14
14
  end
15
+
15
16
  end
16
17
  end
17
18
  end
@@ -11,7 +11,7 @@ module ArelExtensions::Nodes
11
11
  else
12
12
  node
13
13
  end
14
- }.flatten.reduce([]) { |res, b|
14
+ }.flatten.reduce([]) { | res, b |
15
15
  # concatenate successive literal strings.
16
16
  if b.is_a?(Arel::Nodes::Quoted) && b.expr == ""
17
17
  res
@@ -37,16 +37,25 @@ module ArelExtensions::Nodes
37
37
  def concat(other)
38
38
  Concat.new(self.expressions + [other])
39
39
  end
40
+
40
41
  end
41
42
 
42
- class GroupConcat < AggregateFunction
43
+ class GroupConcat < Function
43
44
  RETURN_TYPE = :string
44
45
 
45
- attr_accessor :separator
46
-
47
- def initialize node, separator = ', ', **opts
48
- @separator = convert_to_node(separator)
49
- super node, **opts
46
+ attr_accessor :orders
47
+
48
+ def initialize expr
49
+ tab = expr.map { |arg|
50
+ if arg.is_a?(Array)
51
+ @orders = arg
52
+ nil
53
+ else
54
+ convert_to_node(arg)
55
+ end
56
+ }.compact
57
+ super(tab)
50
58
  end
59
+
51
60
  end
52
61
  end
@@ -2,7 +2,7 @@ require 'date'
2
2
 
3
3
  module ArelExtensions
4
4
  module Nodes
5
- class DateDiff < Function # difference entre colonne date et date string/date
5
+ class DateDiff < Function #difference entre colonne date et date string/date
6
6
  attr_accessor :left_node_type
7
7
  attr_accessor :right_node_type
8
8
 
@@ -12,7 +12,7 @@ module ArelExtensions
12
12
  res = []
13
13
  col = expr.first
14
14
  case col
15
- when Arel::Nodes::Node, Arel::Attributes::Attribute
15
+ when Arel::Nodes::Node, Arel::Attributes::Attribute
16
16
  @left_node_type = type_of_attribute(col)
17
17
  when Date
18
18
  @left_node_type = :ruby_date
@@ -21,7 +21,7 @@ module ArelExtensions
21
21
  end
22
22
  res << ([:date, :ruby_date].include?(@left_node_type) ? convert_to_date_node(col) : convert_to_datetime_node(col))
23
23
  case expr[1]
24
- when Arel::Nodes::Node, Arel::Attributes::Attribute
24
+ when Arel::Nodes::Node, Arel::Attributes::Attribute
25
25
  @right_node_type = type_of_attribute(expr[1])
26
26
  when Date
27
27
  @right_node_type = :ruby_date
@@ -97,7 +97,7 @@ module ArelExtensions
97
97
  v ||= self.expressions.last
98
98
  if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === v
99
99
  if @date_type == :ruby_date
100
- Arel.sql("(INTERVAL '1' DAY) * %s" % v.inspect.to_i)
100
+ Arel.sql("(INTERVAL '1' DAY) * %s" % v.inspect.to_i )
101
101
  else
102
102
  Arel.sql("(INTERVAL '1' SECOND) * %s" % v.to_i)
103
103
  end
@@ -136,7 +136,7 @@ module ArelExtensions
136
136
  if ArelExtensions::Nodes::Duration === v
137
137
  v.with_interval = true
138
138
  case v.left
139
- when 'd','m','y'
139
+ when 'd','m','y'
140
140
  Arel.sql('day')
141
141
  when 'h','mn','s'
142
142
  Arel.sql('second')
@@ -145,12 +145,13 @@ module ArelExtensions
145
145
  else
146
146
  Arel.sql(Arel::Visitors::MSSQL::DATE_MAPPING[v.left])
147
147
  end
148
+ else
149
+ nil
148
150
  end
149
151
  end
150
152
  end
151
153
 
152
154
  private
153
-
154
155
  def convert(object)
155
156
  case object
156
157
  when Arel::Attributes::Attribute, Arel::Nodes::Node, ActiveSupport::Duration
@@ -158,16 +159,16 @@ module ArelExtensions
158
159
  when Integer
159
160
  object.days
160
161
  when DateTime, Time, Date
161
- raise(ArgumentError, "#{object.class} cannot be converted to Integer")
162
+ raise(ArgumentError, "#{object.class} can not be converted to Integer")
162
163
  when String
163
164
  Arel::Nodes.build_quoted(object)
164
165
  else
165
- raise(ArgumentError, "#{object.class} cannot be converted to Integer")
166
+ raise(ArgumentError, "#{object.class} can not be converted to Integer")
166
167
  end
167
168
  end
168
169
  end
169
170
 
170
- class DateSub < Function # difference entre colonne date et date string/date
171
+ class DateSub < Function #difference entre colonne date et date string/date
171
172
  RETURN_TYPE = :integer
172
173
 
173
174
  def initialize(expr)
@@ -184,10 +185,12 @@ module ArelExtensions
184
185
  if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === object
185
186
  object.to_i
186
187
  else
187
- raise(ArgumentError, "#{object.class} cannot be converted to Number")
188
+ raise(ArgumentError, "#{object.class} can not be converted to Number")
188
189
  end
189
190
  end
190
191
  end
192
+
191
193
  end
194
+
192
195
  end
193
196
  end
@@ -13,13 +13,16 @@ module ArelExtensions
13
13
  super(tab, aliaz)
14
14
  end
15
15
 
16
+
16
17
  def left
17
18
  @expressions.first
18
19
  end
19
20
 
21
+
20
22
  def right
21
23
  @expressions[1]
22
24
  end
25
+
23
26
  end
24
27
  end
25
28
  end
@@ -2,6 +2,7 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class FindInSet < Function
4
4
  RETURN_TYPE = :integer
5
+
5
6
  end
6
7
  end
7
8
  end
@@ -1,7 +1,7 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Floor < Function
4
- RETURN_TYPE = :number
4
+ RETURN_TYPE = :number
5
5
  end
6
6
  end
7
7
  end
@@ -1,41 +1,15 @@
1
- require 'strscan'
2
-
3
1
  module ArelExtensions
4
2
  module Nodes
5
- class Format < Function
3
+ class Format < Function
6
4
  RETURN_TYPE = :string
7
5
 
8
- attr_accessor :col_type, :iso_format
9
-
10
- def initialize expr
11
- col = expr.first
12
- @iso_format = convert_format(expr[1])
13
- @col_type = type_of_attribute(col)
14
- super [col, convert_to_string_node(@iso_format)]
15
- end
16
-
17
- private
18
-
19
- # Address portability issues with some of the formats.
20
- def convert_format(fmt)
21
- s = StringScanner.new fmt
22
- res = StringIO.new
23
- while !s.eos?
24
- res <<
25
- case
26
- when s.scan(/%D/) then '%m/%d/%y'
27
- when s.scan(/%F/) then '%Y-%m-%d'
28
- when s.scan(/%R/) then '%H:%M'
29
- when s.scan(/%r/) then '%I:%M:%S %p'
30
- when s.scan(/%T/) then '%H:%M:%S'
31
- when s.scan(/%v/) then '%e-%b-%Y'
32
-
33
- when s.scan(/[^%]+/) then s.matched
34
- when s.scan(/./) then s.matched
35
- end
36
- end
37
- res.string
38
- end
6
+ attr_accessor :col_type, :iso_format
7
+ def initialize expr
8
+ col = expr.first
9
+ @iso_format = expr[1]
10
+ @col_type = type_of_attribute(col)
11
+ super [col, convert_to_string_node(@iso_format)]
12
+ end
39
13
  end
40
14
  end
41
15
  end
@@ -1,24 +1,25 @@
1
1
  module ArelExtensions
2
- module Nodes
3
- class FormattedNumber < Function
4
- RETURN_TYPE = :string
5
-
6
- attr_accessor :locale, :prefix, :suffix, :flags, :scientific_notation, :width,:precision, :type, :original_string
7
-
8
- def initialize expr
9
- # expr[1] = {:locale => 'fr_FR', :type => "e"/"f"/"d", :prefix => "$ ", :suffix => " %", :flags => " +-#0", :width => 5, :precision => 6}
10
- col = expr.first
11
- @locale = expr[1][:locale]
12
- @prefix = expr[1][:prefix]
13
- @suffix = expr[1][:suffix]
14
- @width = expr[1][:width]
15
- @precision = expr[1][:precision]
16
- @type = expr[1][:type]
17
- @flags = expr[1][:flags]
18
- @scientific_notation = /[eE]/.match(expr[1][:type]) || false
19
- @original_string = expr[1][:original_string]
20
- super [col]
21
- end
22
- end
23
- end
2
+ module Nodes
3
+ class FormattedNumber < Function
4
+ RETURN_TYPE = :string
5
+
6
+ attr_accessor :locale, :prefix, :suffix, :flags, :scientific_notation, :width,:precision, :type, :original_string
7
+
8
+ def initialize expr
9
+ # expr[1] = {:locale => 'fr_FR', :type => "e"/"f"/"d", :prefix => "$ ", :suffix => " %", :flags => " +-#0", :width => 5, :precision => 6}
10
+ col = expr.first
11
+ @locale = expr[1][:locale]
12
+ @prefix = expr[1][:prefix]
13
+ @suffix = expr[1][:suffix]
14
+ @width = expr[1][:width]
15
+ @precision = expr[1][:precision]
16
+ @type = expr[1][:type]
17
+ @flags = expr[1][:flags]
18
+ @scientific_notation = /[eE]/.match(expr[1][:type]) || false
19
+ @original_string = expr[1][:original_string]
20
+ super [col]
21
+ end
22
+
23
+ end
24
+ end
24
25
  end