From 963ca860d579a507effbe818da0c89bf443f33c9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 29 Nov 2010 14:38:45 -0800 Subject: adding unary node --- lib/arel/nodes.rb | 1 + lib/arel/nodes/group.rb | 7 +------ lib/arel/nodes/grouping.rb | 7 +------ lib/arel/nodes/having.rb | 7 +------ lib/arel/nodes/offset.rb | 8 ++------ lib/arel/nodes/ordering.rb | 9 +++++---- lib/arel/nodes/unary.rb | 11 +++++++++++ lib/arel/visitors/to_sql.rb | 2 +- test/visitors/test_depth_first.rb | 3 +++ 9 files changed, 26 insertions(+), 29 deletions(-) create mode 100644 lib/arel/nodes/unary.rb 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 -- cgit v1.2.3