Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more roflscaling strings in the visitor

  • Loading branch information...
commit 9367992b4cc274766d3dd099330bbe610c8038f4 1 parent e232226
@tenderlove tenderlove authored
Showing with 28 additions and 10 deletions.
  1. +26 −8 lib/arel/visitors/to_sql.rb
  2. +2 −2 test/test_select_manager.rb
View
34 lib/arel/visitors/to_sql.rb
@@ -47,6 +47,7 @@ class ToSql < Arel::Visitors::Visitor
SPACE = ' ' # :nodoc:
COMMA = ', ' # :nodoc:
GROUP_BY = ' GROUP BY ' # :nodoc:
+ ORDER_BY = ' ORDER BY ' # :nodoc:
WINDOW = ' WINDOW ' # :nodoc:
AND = ' AND ' # :nodoc:
@@ -164,14 +165,31 @@ def visit_Arel_Nodes_Values o
end
def visit_Arel_Nodes_SelectStatement o
- [
- (visit(o.with) if o.with),
- o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
- ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
- (visit(o.limit) if o.limit),
- (visit(o.offset) if o.offset),
- (visit(o.lock) if o.lock),
- ].compact.join ' '
+ str = ''
+
+ if o.with
+ str << visit(o.with)
+ str << SPACE
+ end
+
+ o.cores.each { |x| str << visit_Arel_Nodes_SelectCore(x) }
+
+ unless o.orders.empty?
+ str << SPACE
+ str << ORDER_BY
+ len = o.orders.length - 1
+ o.orders.each_with_index { |x, i|
+ str << visit(x)
+ str << COMMA unless len == i
+ }
+ end
+
+ str << " #{visit(o.limit)}" if o.limit
+ str << " #{visit(o.offset)}" if o.offset
+ str << " #{visit(o.lock)}" if o.lock
+
+ str.strip!
+ str
end
def visit_Arel_Nodes_SelectCore o
View
4 test/test_select_manager.rb
@@ -119,7 +119,7 @@ def test_join_sources
manager = Arel::SelectManager.new Table.engine
manager.project Arel.sql('name')
manager.from as
- manager.to_sql.must_be_like "SELECT name FROM (SELECT * FROM zomg ) foo"
+ manager.to_sql.must_be_like "SELECT name FROM (SELECT * FROM zomg) foo"
end
end
@@ -147,7 +147,7 @@ def test_join_sources
manager1.from(as)
manager1.to_sql.must_be_like %{
- SELECT lol FROM (SELECT * FROM "users" ) omg
+ SELECT lol FROM (SELECT * FROM "users") omg
}
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.