diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb index 95dcc048..c454152d 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 57a7c579..a7fa6f17 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 d52671f1..18adeae9 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 1944a843..6972c58d 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 baa4068d..d93e46aa 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 d395c863..0a3621cf 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 00000000..edda89e1 --- /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 ae90c0c4..abec5317 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -97,7 +97,7 @@ def visit_Arel_Nodes_Having o 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 32778f7d..8d637c7d 100644 --- a/test/visitors/test_depth_first.rb +++ b/test/visitors/test_depth_first.rb @@ -130,6 +130,9 @@ def test_insert_statement @visitor.accept stmt assert_equal [:a, :b, stmt.columns, :c, stmt], @collector.calls end + + def test_offset + end end end end