Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding an AS node

  • Loading branch information...
commit 6667cfb995a49bffe66231a7ffc5a78ca7f5140f 1 parent 76932b9
@tenderlove tenderlove authored
View
1  History.txt
@@ -4,6 +4,7 @@
* #lock will lock SELECT statements "FOR UPDATE" on mysql
* Nodes::Node#not factory method added for creating Nodes::Not nodes
+ * Added an As node
== 2.0.4
View
2  Manifest.txt
@@ -17,6 +17,7 @@ lib/arel/expressions.rb
lib/arel/insert_manager.rb
lib/arel/nodes.rb
lib/arel/nodes/and.rb
+lib/arel/nodes/as.rb
lib/arel/nodes/assignment.rb
lib/arel/nodes/avg.rb
lib/arel/nodes/between.rb
@@ -81,6 +82,7 @@ lib/arel/visitors/visitor.rb
lib/arel/visitors/where_sql.rb
test/attributes/test_attribute.rb
test/helper.rb
+test/nodes/test_as.rb
test/nodes/test_count.rb
test/nodes/test_delete_statement.rb
test/nodes/test_equality.rb
View
1  lib/arel/nodes.rb
@@ -6,6 +6,7 @@
require 'arel/nodes/assignment'
require 'arel/nodes/or'
require 'arel/nodes/and'
+require 'arel/nodes/as'
require 'arel/nodes/not'
require 'arel/nodes/greater_than'
require 'arel/nodes/greater_than_or_equal'
View
6 lib/arel/nodes/as.rb
@@ -0,0 +1,6 @@
+module Arel
+ module Nodes
+ class As < Arel::Nodes::Binary
+ end
+ end
+end
View
6 lib/arel/predications.rb
@@ -1,5 +1,9 @@
module Arel
module Predications
+ def as other
+ Nodes::As.new self, other
+ end
+
def not_eq other
Nodes::NotEqual.new self, other
end
@@ -174,4 +178,4 @@ def grouping_all method_id, others
}
end
end
-end
+end
View
4 lib/arel/visitors/to_sql.rb
@@ -250,6 +250,10 @@ def visit_Arel_Nodes_NotEqual o
end
end
+ def visit_Arel_Nodes_As o
+ "#{visit o.left} AS #{visit o.right}"
+ end
+
def visit_Arel_Nodes_UnqualifiedColumn o
"#{quote_column_name o.name}"
end
View
16 test/nodes/test_as.rb
@@ -0,0 +1,16 @@
+require 'helper'
+
+module Arel
+ module Nodes
+ describe 'As' do
+ describe '#as' do
+ it 'makes an AS node' do
+ attr = Table.new(:users)[:id]
+ as = attr.as(Arel.sql('foo'))
+ assert_equal attr, as.left
+ assert_equal 'foo', as.right
+ end
+ end
+ end
+ end
+end
View
6 test/visitors/test_to_sql.rb
@@ -38,6 +38,12 @@ module Visitors
sql.must_be_like "NOT foo"
end
+ it "should visit_As" do
+ as = Nodes::As.new(Arel.sql("foo"), Arel.sql("bar"))
+ sql = @visitor.accept as
+ sql.must_be_like "foo AS bar"
+ end
+
it "should visit_Bignum" do
@visitor.accept 8787878092
end
Please sign in to comment.
Something went wrong with that request. Please try again.