aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/nodes
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-15 09:26:01 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-15 09:26:01 -0700
commited6192c55b8e77b60e4203dc30ae056f222a1499 (patch)
tree5ea5e020eba247bd7729dd11830ce7c9292fc4ac /lib/arel/nodes
parent188fc7a46456bd3e5ebdb09ef8a753d7a34a6af5 (diff)
downloadrails-ed6192c55b8e77b60e4203dc30ae056f222a1499.tar.gz
rails-ed6192c55b8e77b60e4203dc30ae056f222a1499.tar.bz2
rails-ed6192c55b8e77b60e4203dc30ae056f222a1499.zip
adding a grouping node
Diffstat (limited to 'lib/arel/nodes')
-rw-r--r--lib/arel/nodes/binary.rb10
-rw-r--r--lib/arel/nodes/grouping.rb21
-rw-r--r--lib/arel/nodes/node.rb20
3 files changed, 42 insertions, 9 deletions
diff --git a/lib/arel/nodes/binary.rb b/lib/arel/nodes/binary.rb
index 3cd9583e79..090468adfa 100644
--- a/lib/arel/nodes/binary.rb
+++ b/lib/arel/nodes/binary.rb
@@ -1,6 +1,6 @@
module Arel
module Nodes
- class Binary
+ class Binary < Arel::Nodes::Node
attr_accessor :left, :right
def initialize left, right
@@ -8,14 +8,6 @@ module Arel
@right = right
end
- def or right
- Nodes::Or.new self, right
- end
-
- def and right
- Nodes::And.new self, right
- end
-
# FIXME: this method should go away. I don't like people calling
# to_sql on non-head nodes. This forces us to walk the AST until we
# can find a node that has a "relation" member.
diff --git a/lib/arel/nodes/grouping.rb b/lib/arel/nodes/grouping.rb
new file mode 100644
index 0000000000..0af1df1f7a
--- /dev/null
+++ b/lib/arel/nodes/grouping.rb
@@ -0,0 +1,21 @@
+module Arel
+ module Nodes
+ class Grouping < Arel::Nodes::Node
+ attr_accessor :expr
+
+ def initialize expression
+ @expr = expression
+ end
+
+ # FIXME: this method should go away. I don't like people calling
+ # to_sql on non-head nodes. This forces us to walk the AST until we
+ # can find a node that has a "relation" member.
+ #
+ # Maybe we should just use `Table.engine`? :'(
+ def to_sql
+ viz = Visitors::ToSql.new Table.engine
+ viz.accept self
+ end
+ end
+ end
+end
diff --git a/lib/arel/nodes/node.rb b/lib/arel/nodes/node.rb
new file mode 100644
index 0000000000..fd5ea410ea
--- /dev/null
+++ b/lib/arel/nodes/node.rb
@@ -0,0 +1,20 @@
+module Arel
+ module Nodes
+ ###
+ # Abstract base class for all AST nodes
+ class Node
+ ###
+ # Factory method to create a Nodes::Grouping node that has an Nodes::Or
+ # node as a child.
+ def or right
+ Nodes::Grouping.new Nodes::Or.new(self, right)
+ end
+
+ ###
+ # Factory method to create an Nodes::And node.
+ def and right
+ Nodes::And.new self, right
+ end
+ end
+ end
+end