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.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -7
- data/.travis.yml +91 -61
- data/Gemfile +20 -15
- data/README.md +12 -17
- data/Rakefile +29 -40
- data/appveyor.yml +1 -1
- data/arel_extensions.gemspec +3 -3
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +9 -9
- data/gemfiles/rails4.gemfile +13 -13
- data/gemfiles/rails5_0.gemfile +13 -13
- data/gemfiles/rails5_1_4.gemfile +13 -13
- data/gemfiles/rails5_2.gemfile +13 -13
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/postgresql.sql +21 -21
- data/lib/arel_extensions/attributes.rb +1 -0
- data/lib/arel_extensions/boolean_functions.rb +14 -55
- data/lib/arel_extensions/common_sql_functions.rb +8 -7
- data/lib/arel_extensions/comparators.rb +15 -14
- data/lib/arel_extensions/date_duration.rb +5 -4
- data/lib/arel_extensions/insert_manager.rb +16 -17
- data/lib/arel_extensions/math.rb +12 -11
- data/lib/arel_extensions/math_functions.rb +22 -29
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +1 -0
- data/lib/arel_extensions/nodes/case.rb +8 -11
- data/lib/arel_extensions/nodes/cast.rb +2 -4
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/change_case.rb +0 -0
- data/lib/arel_extensions/nodes/coalesce.rb +3 -2
- data/lib/arel_extensions/nodes/collate.rb +2 -1
- data/lib/arel_extensions/nodes/concat.rb +16 -7
- data/lib/arel_extensions/nodes/date_diff.rb +13 -10
- data/lib/arel_extensions/nodes/duration.rb +3 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +8 -34
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +16 -25
- data/lib/arel_extensions/nodes/json.rb +36 -43
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
- data/lib/arel_extensions/nodes/locate.rb +1 -0
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +6 -4
- data/lib/arel_extensions/nodes/md5.rb +1 -0
- data/lib/arel_extensions/nodes/power.rb +5 -5
- data/lib/arel_extensions/nodes/rand.rb +1 -0
- data/lib/arel_extensions/nodes/repeat.rb +4 -2
- data/lib/arel_extensions/nodes/replace.rb +6 -22
- data/lib/arel_extensions/nodes/round.rb +6 -5
- data/lib/arel_extensions/nodes/soundex.rb +15 -15
- data/lib/arel_extensions/nodes/std.rb +21 -18
- data/lib/arel_extensions/nodes/substring.rb +16 -8
- data/lib/arel_extensions/nodes/then.rb +0 -0
- data/lib/arel_extensions/nodes/trim.rb +5 -3
- data/lib/arel_extensions/nodes/union.rb +5 -2
- data/lib/arel_extensions/nodes/union_all.rb +3 -0
- data/lib/arel_extensions/nodes/wday.rb +4 -0
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +7 -5
- data/lib/arel_extensions/predications.rb +34 -35
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +4 -2
- data/lib/arel_extensions/string_functions.rb +23 -52
- data/lib/arel_extensions/tasks.rb +5 -5
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +12 -5
- data/lib/arel_extensions/visitors/mssql.rb +58 -64
- data/lib/arel_extensions/visitors/mysql.rb +98 -149
- data/lib/arel_extensions/visitors/oracle.rb +70 -73
- data/lib/arel_extensions/visitors/oracle12.rb +15 -2
- data/lib/arel_extensions/visitors/postgresql.rb +63 -116
- data/lib/arel_extensions/visitors/sqlite.rb +70 -83
- data/lib/arel_extensions/visitors/to_sql.rb +110 -142
- data/lib/arel_extensions/visitors.rb +60 -68
- data/lib/arel_extensions.rb +19 -81
- data/test/database.yml +0 -2
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +43 -28
- data/test/support/fake_record.rb +2 -2
- data/test/test_comparators.rb +12 -9
- data/test/visitors/test_bulk_insert_oracle.rb +8 -8
- data/test/visitors/test_bulk_insert_sqlite.rb +10 -9
- data/test/visitors/test_bulk_insert_to_sql.rb +10 -8
- data/test/visitors/test_oracle.rb +42 -42
- data/test/visitors/test_to_sql.rb +196 -361
- data/test/with_ar/all_agnostic_test.rb +160 -195
- data/test/with_ar/insert_agnostic_test.rb +4 -3
- data/test/with_ar/test_bulk_sqlite.rb +9 -6
- data/test/with_ar/test_math_sqlite.rb +12 -8
- data/test/with_ar/test_string_mysql.rb +11 -5
- data/test/with_ar/test_string_sqlite.rb +12 -4
- metadata +11 -22
- data/.github/workflows/ruby.yml +0 -102
- data/gemfiles/rails6.gemfile +0 -30
- data/gemfiles/rails6_1.gemfile +0 -30
- data/gemspecs/arel_extensions-v1.gemspec +0 -28
- data/gemspecs/arel_extensions-v2.gemspec +0 -28
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/sum.rb +0 -7
- data/lib/arel_extensions/visitors/convert_format.rb +0 -37
- data/test/arelx_test_helper.rb +0 -26
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
data/lib/arel_extensions/math.rb
CHANGED
@@ -11,9 +11,9 @@ require 'arel_extensions/nodes/union_all'
|
|
11
11
|
|
12
12
|
module ArelExtensions
|
13
13
|
module Math
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
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
|
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
|
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) #
|
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
|
-
#
|
66
|
-
#
|
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) #
|
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) #
|
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
|
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
|
-
|
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
|
66
|
-
ArelExtensions::Nodes::Std.new self,
|
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
|
74
|
-
|
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
|
-
#
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
alias_method
|
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
|
-
#
|
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
|
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
|
103
|
-
flags
|
104
|
-
width
|
105
|
-
precision
|
106
|
-
type
|
107
|
-
suffix
|
108
|
-
locale
|
109
|
-
original_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
|
@@ -1,11 +1,7 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
|
-
if
|
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
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
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
|
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
|
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 <
|
43
|
+
class GroupConcat < Function
|
43
44
|
RETURN_TYPE = :string
|
44
45
|
|
45
|
-
attr_accessor :
|
46
|
-
|
47
|
-
def initialize
|
48
|
-
|
49
|
-
|
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 #
|
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
|
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}
|
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}
|
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 #
|
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}
|
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
|
@@ -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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|