aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-11-29 14:38:45 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-29 14:38:45 -0800
commit963ca860d579a507effbe818da0c89bf443f33c9 (patch)
tree6d79f4e60753e40b1e96346367a9cd89ebb9d648
parentad16c18cc3a7db4b56611b9244140f0b495a1214 (diff)
downloadrails-963ca860d579a507effbe818da0c89bf443f33c9.tar.gz
rails-963ca860d579a507effbe818da0c89bf443f33c9.tar.bz2
rails-963ca860d579a507effbe818da0c89bf443f33c9.zip
adding unary node
-rw-r--r--lib/arel/nodes.rb1
-rw-r--r--lib/arel/nodes/group.rb7
-rw-r--r--lib/arel/nodes/grouping.rb7
-rw-r--r--lib/arel/nodes/having.rb7
-rw-r--r--lib/arel/nodes/offset.rb8
-rw-r--r--lib/arel/nodes/ordering.rb9
-rw-r--r--lib/arel/nodes/unary.rb11
-rw-r--r--lib/arel/visitors/to_sql.rb2
-rw-r--r--test/visitors/test_depth_first.rb3
9 files changed, 26 insertions, 29 deletions
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb
index 95dcc0480e..c454152d0d 100644
--- a/lib/arel/nodes.rb
+++ b/lib/arel/nodes.rb
@@ -1,4 +1,5 @@
require 'arel/nodes/node'
+require 'arel/nodes/unary'
require 'arel/nodes/binary'
require 'arel/nodes/equality'
require 'arel/nodes/between'
diff --git a/lib/arel/nodes/group.rb b/lib/arel/nodes/group.rb
index 57a7c579da..a7fa6f170d 100644
--- a/lib/arel/nodes/group.rb
+++ b/lib/arel/nodes/group.rb
@@ -1,11 +1,6 @@
module Arel
module Nodes
- class Group
- attr_accessor :expr
-
- def initialize expr
- @expr = expr
- end
+ class Group < Arel::Nodes::Unary
end
end
end
diff --git a/lib/arel/nodes/grouping.rb b/lib/arel/nodes/grouping.rb
index d52671f169..18adeae97f 100644
--- a/lib/arel/nodes/grouping.rb
+++ b/lib/arel/nodes/grouping.rb
@@ -1,11 +1,6 @@
module Arel
module Nodes
- class Grouping < Arel::Nodes::Node
- attr_accessor :expr
-
- def initialize expression
- @expr = expression
- end
+ class Grouping < Arel::Nodes::Unary
end
end
end
diff --git a/lib/arel/nodes/having.rb b/lib/arel/nodes/having.rb
index 1944a84391..6972c58dda 100644
--- a/lib/arel/nodes/having.rb
+++ b/lib/arel/nodes/having.rb
@@ -1,11 +1,6 @@
module Arel
module Nodes
- class Having
- attr_accessor :expr
-
- def initialize expr
- @expr = expr
- end
+ class Having < Arel::Nodes::Unary
end
end
end
diff --git a/lib/arel/nodes/offset.rb b/lib/arel/nodes/offset.rb
index baa4068d93..d93e46aa1f 100644
--- a/lib/arel/nodes/offset.rb
+++ b/lib/arel/nodes/offset.rb
@@ -1,11 +1,7 @@
module Arel
module Nodes
- class Offset
- attr_accessor :value
-
- def initialize value
- @value = value
- end
+ class Offset < Arel::Nodes::Unary
+ alias :value :expr
end
end
end
diff --git a/lib/arel/nodes/ordering.rb b/lib/arel/nodes/ordering.rb
index d395c8631d..0a3621cf54 100644
--- a/lib/arel/nodes/ordering.rb
+++ b/lib/arel/nodes/ordering.rb
@@ -1,10 +1,11 @@
module Arel
module Nodes
- class Ordering < Arel::Nodes::Node
- attr_accessor :expr, :direction
+ class Ordering < Arel::Nodes::Binary
+ alias :expr :left
+ alias :direction :right
- def initialize expression, direction = :asc
- @expr, @direction = expression, direction
+ def initialize expr, direction = :asc
+ super
end
def ascending?
diff --git a/lib/arel/nodes/unary.rb b/lib/arel/nodes/unary.rb
new file mode 100644
index 0000000000..edda89e1f0
--- /dev/null
+++ b/lib/arel/nodes/unary.rb
@@ -0,0 +1,11 @@
+module Arel
+ module Nodes
+ class Unary < Arel::Nodes::Node
+ attr_accessor :expr
+
+ def initialize expr
+ @expr = expr
+ end
+ end
+ end
+end
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index ae90c0c4b6..abec5317ca 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -97,7 +97,7 @@ module Arel
end
def visit_Arel_Nodes_Offset o
- "OFFSET #{visit o.value}"
+ "OFFSET #{visit o.expr}"
end
# FIXME: this does nothing on SQLLite3, but should do things on other
diff --git a/test/visitors/test_depth_first.rb b/test/visitors/test_depth_first.rb
index 32778f7d4b..8d637c7d75 100644
--- a/test/visitors/test_depth_first.rb
+++ b/test/visitors/test_depth_first.rb
@@ -130,6 +130,9 @@ module Arel
@visitor.accept stmt
assert_equal [:a, :b, stmt.columns, :c, stmt], @collector.calls
end
+
+ def test_offset
+ end
end
end
end