arel 2.0.2 → 2.0.3

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.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 2.0.3
2
+
3
+ * Bug fixes
4
+
5
+ * Fixing Oracle support
6
+ * Added a visitor for "Class" objects
7
+
1
8
  == 2.0.2
2
9
 
3
10
  * Bug fixes
data/arel.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{arel}
5
- s.version = "2.0.1.20101111105523"
5
+ s.version = "2.0.2.20101111111102"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"]
data/lib/arel.rb CHANGED
@@ -28,7 +28,7 @@ require 'arel/sql_literal'
28
28
  ####
29
29
 
30
30
  module Arel
31
- VERSION = '2.0.2'
31
+ VERSION = '2.0.3'
32
32
 
33
33
  def self.sql raw_sql
34
34
  Arel::Nodes::SqlLiteral.new raw_sql
@@ -13,7 +13,7 @@ module Arel
13
13
  when :date, :datetime, :timestamp, :time then Time
14
14
  when :boolean then Boolean
15
15
  else
16
- raise NotImplementedError, "Column type `#{column.type}` is not currently handled"
16
+ Undefined
17
17
  end
18
18
  end
19
19
  end
@@ -5,12 +5,13 @@ module Arel
5
5
  include Arel::Predications
6
6
  end
7
7
 
8
- class String < Attribute; end
9
- class Time < Attribute; end
10
- class Boolean < Attribute; end
11
- class Decimal < Attribute; end
12
- class Float < Attribute; end
13
- class Integer < Attribute; end
8
+ class String < Attribute; end
9
+ class Time < Attribute; end
10
+ class Boolean < Attribute; end
11
+ class Decimal < Attribute; end
12
+ class Float < Attribute; end
13
+ class Integer < Attribute; end
14
+ class Undefined < Attribute; end
14
15
  end
15
16
 
16
17
  Attribute = Attributes::Attribute
@@ -70,19 +70,14 @@ module Arel
70
70
  /DISTINCT.*FIRST_VALUE/ === projection
71
71
  end
72
72
  end
73
- # FIXME: previous version with join and split broke ORDER BY clause
73
+ # Previous version with join and split broke ORDER BY clause
74
74
  # if it contained functions with several arguments (separated by ',').
75
- # Currently splitting is done only if there is no function calls
76
75
  #
77
76
  # orders = o.orders.map { |x| visit x }.join(', ').split(',')
78
77
  orders = o.orders.map do |x|
79
78
  string = visit x
80
- # if there is function call
81
- if string.include?('(')
82
- string
83
- # if no function call then comma splits several ORDER BY columns
84
- elsif string.include?(',')
85
- string.split(',')
79
+ if string.include?(',')
80
+ split_order_string(string)
86
81
  else
87
82
  string
88
83
  end
@@ -94,6 +89,24 @@ module Arel
94
89
  end
95
90
  o
96
91
  end
92
+
93
+ # Split string by commas but count opening and closing brackets
94
+ # and ignore commas inside brackets.
95
+ def split_order_string(string)
96
+ array = []
97
+ i = 0
98
+ string.split(',').each do |part|
99
+ if array[i]
100
+ array[i] << ',' << part
101
+ else
102
+ # to ensure that array[i] will be String and not Arel::Nodes::SqlLiteral
103
+ array[i] = '' << part
104
+ end
105
+ i += 1 if array[i].count('(') == array[i].count(')')
106
+ end
107
+ array
108
+ end
109
+
97
110
  end
98
111
  end
99
112
  end
@@ -281,6 +281,7 @@ module Arel
281
281
  alias :visit_TrueClass :visit_String
282
282
  alias :visit_NilClass :visit_String
283
283
  alias :visit_ActiveSupport_StringInquirer :visit_String
284
+ alias :visit_Class :visit_String
284
285
 
285
286
  def quote value, column = nil
286
287
  @connection.quote value, column
@@ -3,6 +3,11 @@ require 'helper'
3
3
  module Arel
4
4
  describe 'Attributes' do
5
5
  describe 'for' do
6
+ it 'deals with unknown column types' do
7
+ column = Struct.new(:type).new :crazy
8
+ Attributes.for(column).must_equal Attributes::Undefined
9
+ end
10
+
6
11
  it 'returns the correct constant for strings' do
7
12
  [:string, :text, :binary].each do |type|
8
13
  column = Struct.new(:type).new type
@@ -43,6 +43,18 @@ module Arel
43
43
  }
44
44
  end
45
45
 
46
+ it 'splits orders with commas and function calls' do
47
+ # *sigh*
48
+ select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__"
49
+ stmt = Nodes::SelectStatement.new
50
+ stmt.cores.first.projections << Nodes::SqlLiteral.new(select)
51
+ stmt.orders << Nodes::SqlLiteral.new('NVL(LOWER(bar, foo), foo) DESC, UPPER(baz)')
52
+ sql = @visitor.accept(stmt)
53
+ sql.must_be_like %{
54
+ SELECT #{select} ORDER BY alias_0__ DESC, alias_1__
55
+ }
56
+ end
57
+
46
58
  describe 'Nodes::SelectStatement' do
47
59
  describe 'limit' do
48
60
  it 'adds a rownum clause' do
@@ -21,6 +21,10 @@ module Arel
21
21
  end
22
22
  end
23
23
 
24
+ it "should visit_Class" do
25
+ @visitor.accept(DateTime).must_equal "'DateTime'"
26
+ end
27
+
24
28
  it "should visit_DateTime" do
25
29
  @visitor.accept DateTime.now
26
30
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 2
10
- version: 2.0.2
9
+ - 3
10
+ version: 2.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aaron Patterson
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-11-11 00:00:00 -06:00
21
+ date: 2010-11-16 00:00:00 -08:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency