arel_extensions 1.2.16 → 1.2.17

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e46b6324a71d0a11c194ec36d821f85c3f798921524808181bc31a9d6345c336
4
- data.tar.gz: ef7c397dfb8fb93ae74405aa4c160e3981df4ac1415520e23c90ddb795848da0
3
+ metadata.gz: 63535bd97d5c08485672454464e4fd96413ba4f5e7660dd45f008b113f6c92ef
4
+ data.tar.gz: 1478ed16cc0a12b70198334394a456c43a33a480ab9d52786a1be75f11016d4a
5
5
  SHA512:
6
- metadata.gz: ebe47f910039b108fe7572a57d633a379ac606929a73d7370a8e85fe0a72b1ae04888e0b6ec2ea1223a5a8049de3aa2676729241b416e6a01224d9230a0aa0f5
7
- data.tar.gz: 9c7c8d3ebf6a048c9b7e01ee43950d8692eb43ebf20e704b39e79317a322ff84a6440fd34b5eb754b00a598764c359a0ab8a934367f5cbf8a2424008e6a18457
6
+ metadata.gz: 0c862b43fb3b4f5758fa2454888bd5abbea6dc802cfb401ba5866fc9c3ce05de6aafb5db151b3a85ac63617fba2f773bb5230c5f0a2f4781a8c07ee521e70783
7
+ data.tar.gz: 1114bf913a0e79a0ebf1a9c28c995e3eb428147615bc51861c55de322e0dc3c5968949dce4cf432c525e470fbfa9d49a6d3a371ccdf69fe602a8f2db608c1834
@@ -129,6 +129,8 @@ matrix:
129
129
  jdk: openjdk11
130
130
  - rvm: 2.7.1
131
131
  gemfile: gemfiles/rails4.gemfile
132
+ - rvm : jruby-9.0.5.0
133
+ gemfile: gemfiles/rails4.gemfile
132
134
  - rvm : jruby-9.2.11.1
133
135
  gemfile: gemfiles/rails4.gemfile
134
136
  - rvm: 2.0.0
@@ -63,8 +63,28 @@ class Arel::Nodes::Or
63
63
  @children = children
64
64
  end
65
65
 
66
+ def initialize_copy(other)
67
+ super
68
+ @children = other.children.copy if other.children
69
+ end
70
+
71
+
72
+ def left
73
+ children.first
74
+ end
75
+
76
+ def right
77
+ children[1]
78
+ end
79
+
66
80
  def hash
67
81
  children.hash
68
82
  end
69
83
 
84
+ def eql?(other)
85
+ self.class == other.class &&
86
+ children == other.children
87
+ end
88
+ alias :== :eql?
89
+
70
90
  end
@@ -12,7 +12,7 @@ module ArelExtensions
12
12
  db.enable_load_extension(0)
13
13
  rescue => e
14
14
  $load_extension_disabled = true
15
- puts "can not load extensions #{e.inspect}"
15
+ puts "cannot load extensions #{e.inspect}"
16
16
  end
17
17
  end
18
18
  end
@@ -44,7 +44,7 @@ module ArelExtensions
44
44
  begin
45
45
  add_sqlite_functions
46
46
  rescue => e
47
- puts "can not add sqlite functions #{e.inspect}"
47
+ puts "cannot add sqlite functions #{e.inspect}"
48
48
  end
49
49
  end
50
50
  if File.exist?("init/#{env_db}.sql")
@@ -14,7 +14,10 @@ module ArelExtensions
14
14
  @return_type = :decimal
15
15
  when :number
16
16
  @return_type = :number
17
- when 'char', 'varchar', 'text', 'nchar', 'nvarchar', 'ntext'
17
+ when 'char', 'varchar', 'nchar', 'nvarchar'
18
+ @return_type = :string
19
+ when 'text', :text, 'ntext', :ntext
20
+ @as_attr = expr[1].to_sym
18
21
  @return_type = :string
19
22
  when :datetime, 'datetime','smalldatetime'
20
23
  @return_type = :datetime
@@ -157,11 +157,11 @@ module ArelExtensions
157
157
  when Integer
158
158
  object.days
159
159
  when DateTime, Time, Date
160
- raise(ArgumentError, "#{object.class} can not be converted to Integer")
160
+ raise(ArgumentError, "#{object.class} cannot be converted to Integer")
161
161
  when String
162
162
  Arel::Nodes.build_quoted(object)
163
163
  else
164
- raise(ArgumentError, "#{object.class} can not be converted to Integer")
164
+ raise(ArgumentError, "#{object.class} cannot be converted to Integer")
165
165
  end
166
166
  end
167
167
  end
@@ -183,7 +183,7 @@ module ArelExtensions
183
183
  if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === object
184
184
  object.to_i
185
185
  else
186
- raise(ArgumentError, "#{object.class} can not be converted to Number")
186
+ raise(ArgumentError, "#{object.class} cannot be converted to Number")
187
187
  end
188
188
  end
189
189
  end
@@ -1,3 +1,5 @@
1
+ require 'strscan'
2
+
1
3
  module ArelExtensions
2
4
  module Nodes
3
5
  class Format < Function
@@ -6,10 +8,33 @@ module ArelExtensions
6
8
  attr_accessor :col_type, :iso_format
7
9
  def initialize expr
8
10
  col = expr.first
9
- @iso_format = expr[1]
11
+ @iso_format = convert_format(expr[1])
10
12
  @col_type = type_of_attribute(col)
11
13
  super [col, convert_to_string_node(@iso_format)]
12
14
  end
15
+
16
+ private
17
+
18
+ # Address portability issues with some of the formats.
19
+ def convert_format(fmt)
20
+ s = StringScanner.new fmt
21
+ res = StringIO.new
22
+ while !s.eos?
23
+ res <<
24
+ case
25
+ when s.scan(/%D/) then '%m/%d/%y'
26
+ when s.scan(/%F/) then '%Y-%m-%d'
27
+ when s.scan(/%R/) then '%H:%M'
28
+ when s.scan(/%r/) then '%I:%M:%S %p'
29
+ when s.scan(/%T/) then '%H:%M:%S'
30
+ when s.scan(/%v/) then '%e-%b-%Y'
31
+
32
+ when s.scan(/[^%]+/) then s.matched
33
+ when s.scan(/./) then s.matched
34
+ end
35
+ end
36
+ res.string
37
+ end
13
38
  end
14
39
  end
15
40
  end
@@ -10,6 +10,10 @@ module ArelExtensions
10
10
 
11
11
  RETURN_TYPE = :string # by default...
12
12
 
13
+ # Support multibyte string if they are available.
14
+ MBSTRING =
15
+ defined?(ActiveSupport::Multibyte::Chars) ? ActiveSupport::Multibyte::Chars : String
16
+
13
17
  # overrides as to make new Node like AliasPredication
14
18
 
15
19
  def return_type
@@ -63,7 +67,7 @@ module ArelExtensions
63
67
  Arel::Nodes.build_quoted(object, self)
64
68
  when Time
65
69
  Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
66
- when String, Symbol
70
+ when MBSTRING, String, Symbol
67
71
  Arel::Nodes.build_quoted(object.to_s)
68
72
  when Date
69
73
  Arel::Nodes.build_quoted(object.to_s, self)
@@ -74,7 +78,7 @@ module ArelExtensions
74
78
  when Array
75
79
  Arel::Nodes::Grouping.new(object.map{|r| convert_to_node(e)})
76
80
  else
77
- raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
81
+ raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
78
82
  end
79
83
  end
80
84
 
@@ -97,8 +101,8 @@ module ArelExtensions
97
101
  Arel::Nodes.build_quoted(object, self)
98
102
  when Time
99
103
  Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
100
- when String
101
- Arel::Nodes.build_quoted(object)
104
+ when MBSTRING, String
105
+ Arel::Nodes.build_quoted(object.to_s)
102
106
  when Date
103
107
  Arel::Nodes.build_quoted(object, self)
104
108
  when NilClass
@@ -106,7 +110,7 @@ module ArelExtensions
106
110
  when ActiveSupport::Duration
107
111
  Arel::Nodes.build_quoted(object.to_i.to_s)
108
112
  else
109
- raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
113
+ raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
110
114
  end
111
115
  end
112
116
 
@@ -116,12 +120,12 @@ module ArelExtensions
116
120
  object
117
121
  when DateTime, Time
118
122
  Arel::Nodes.build_quoted(Date.new(object.year, object.month, object.day), self)
119
- when String
120
- Arel::Nodes.build_quoted(Date.parse(object), self)
123
+ when MBSTRING, String
124
+ Arel::Nodes.build_quoted(Date.parse(object.to_s), self)
121
125
  when Date
122
126
  Arel::Nodes.build_quoted(object, self)
123
127
  else
124
- raise(ArgumentError, "#{object.class} can not be converted to Date")
128
+ raise(ArgumentError, "#{object.class} cannot be converted to Date")
125
129
  end
126
130
  end
127
131
 
@@ -131,12 +135,12 @@ module ArelExtensions
131
135
  object
132
136
  when DateTime, Time
133
137
  Arel::Nodes.build_quoted(object, self)
134
- when String
135
- Arel::Nodes.build_quoted(Time.parse(object), self)
138
+ when MBSTRING, String
139
+ Arel::Nodes.build_quoted(Time.parse(object.to_s), self)
136
140
  when Date
137
141
  Arel::Nodes.build_quoted(Time.utc(object.year, object.month, object.day, 0, 0, 0), self)
138
142
  else
139
- raise(ArgumentError, "#{object.class} can not be converted to Datetime")
143
+ raise(ArgumentError, "#{object.class} cannot be converted to Datetime")
140
144
  end
141
145
  end
142
146
 
@@ -154,7 +158,7 @@ module ArelExtensions
154
158
  when NilClass
155
159
  0
156
160
  else
157
- raise(ArgumentError, "#{object.class} can not be converted to NUMBER arg")
161
+ raise(ArgumentError, "#{object.class} cannot be converted to NUMBER arg")
158
162
  end
159
163
  end
160
164
 
@@ -26,7 +26,7 @@ module ArelExtensions
26
26
  case other
27
27
  when Range
28
28
  self.between(other)
29
- when Arel::Nodes::Grouping
29
+ when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
30
30
  Arel::Nodes::In.new(self, quoted_node(other))
31
31
  when Enumerable
32
32
  nils, values = other.partition{ |v| v.nil? }
@@ -54,7 +54,7 @@ module ArelExtensions
54
54
  case other
55
55
  when Range
56
56
  Arel::Nodes::Not.new(self.between(other))
57
- when Arel::Nodes::Grouping
57
+ when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
58
58
  Arel::Nodes::NotIn.new(self, quoted_node(other))
59
59
  when Enumerable
60
60
  nils, values = other.partition{ |v| v.nil? }
@@ -94,7 +94,7 @@ module ArelExtensions
94
94
  when ActiveSupport::Duration
95
95
  object.to_i
96
96
  else
97
- raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
97
+ raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
98
98
  end
99
99
  end
100
100
  end
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "1.2.16".freeze
2
+ VERSION = "1.2.17".freeze
3
3
  end
@@ -447,9 +447,9 @@ module ArelExtensions
447
447
  collector
448
448
  end
449
449
 
450
- # JSON if implemented only after 10.2.3 in MariaDb and 5.7 in MySql
450
+ # JSON if implemented only after 10.2.3 (aggregations after 10.5.0) in MariaDb and 5.7 (aggregations after 5.7.22) in MySql
451
451
  def json_supported?
452
- version_supported?('10.2.3', '5.7.0')
452
+ version_supported?('10.5.0', '5.7.22')
453
453
  end
454
454
 
455
455
  def window_supported?
@@ -257,6 +257,16 @@ module ArelExtensions
257
257
  collector = visit o.left, collector
258
258
  collector << ")"
259
259
  return collector
260
+ when :text
261
+ collector << "TO_CLOB("
262
+ collector = visit o.left, collector
263
+ collector << ")"
264
+ return collector
265
+ when :ntext
266
+ collector << "TO_NCLOB("
267
+ collector = visit o.left, collector
268
+ collector << ")"
269
+ return collector
260
270
  when :time
261
271
  if (o.left.respond_to?(:return_type) && o.left.return_type == :string) || o.left.is_a?(Arel::Nodes::Quoted)
262
272
  collector << "TO_DATE("
@@ -350,6 +350,8 @@ module ArelExtensions
350
350
  as_attr = case o.as_attr
351
351
  when :string
352
352
  Arel::Nodes::SqlLiteral.new('varchar')
353
+ when :text, :ntext
354
+ Arel::Nodes::SqlLiteral.new('text')
353
355
  when :time
354
356
  Arel::Nodes::SqlLiteral.new('time')
355
357
  when :int
@@ -295,6 +295,8 @@ module ArelExtensions
295
295
  as_attr = Arel::Nodes::SqlLiteral.new('time')
296
296
  when :binary
297
297
  as_attr = Arel::Nodes::SqlLiteral.new('binary')
298
+ when :text, :ntext
299
+ as_attr = Arel::Nodes::SqlLiteral.new('text')
298
300
  else
299
301
  as_attr = Arel::Nodes::SqlLiteral.new(o.as_attr.to_s)
300
302
  end
@@ -21,7 +21,7 @@ def setup_db
21
21
  db.enable_load_extension(0)
22
22
  rescue => e
23
23
  $load_extension_disabled = true
24
- $stderr << "can not load extensions #{e.inspect}\n"
24
+ $stderr << "cannot load extensions #{e.inspect}\n"
25
25
  end
26
26
  end
27
27
  #function find_in_set
@@ -356,6 +356,7 @@ module ArelExtensions
356
356
  assert_equal '2016-05-23', t(@lucas, @created_at.format('%Y-%m-%d'))
357
357
  skip "SQL Server does not accept any format" if @env_db == 'mssql'
358
358
  assert_equal '2014/03/03 12:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S'))
359
+ assert_equal '12:42%', t(@lucas, @updated_at.format('%R%%'))
359
360
  end
360
361
 
361
362
  def test_coalesce
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "1.2.16".freeze
2
+ VERSION = "1.2.17".freeze
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "2.0.12".freeze
2
+ VERSION = "2.0.13".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.16
4
+ version: 1.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yann Azoury
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-09-17 00:00:00.000000000 Z
13
+ date: 2020-10-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: arel