Skip to content

Commit

Permalink
adding unary node
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Nov 29, 2010
1 parent ad16c18 commit 963ca86
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 29 deletions.
1 change: 1 addition & 0 deletions 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'
Expand Down
7 changes: 1 addition & 6 deletions 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
7 changes: 1 addition & 6 deletions 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
7 changes: 1 addition & 6 deletions 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
8 changes: 2 additions & 6 deletions 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
9 changes: 5 additions & 4 deletions 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?
Expand Down
11 changes: 11 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion lib/arel/visitors/to_sql.rb
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/visitors/test_depth_first.rb
Expand Up @@ -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

0 comments on commit 963ca86

Please sign in to comment.