Skip to content

Commit

Permalink
base class works with visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Nov 29, 2010
1 parent ae4c814 commit f68b7c4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions History.txt
@@ -1,5 +1,10 @@
== 2.0.5 (unreleased)

* Enhancements

* Arel::Visitors::DepthFirst can walk your AST depth first
* Arel::Nodes::Node is enumerable, depth first

* Bug fixes

* #lock will lock SELECT statements "FOR UPDATE" on mysql
Expand Down
2 changes: 2 additions & 0 deletions lib/arel/nodes/node.rb
Expand Up @@ -37,6 +37,8 @@ def to_sql engine = Table.engine

# Iterate through AST, nodes will be yielded depth-first
def each &block
return enum_for(:each) unless block_given?

Visitors::DepthFirst.new(block).accept self
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/arel/visitors/depth_first.rb
Expand Up @@ -93,6 +93,7 @@ def terminal o
alias :visit_ActiveSupport_Multibyte_Chars :terminal
alias :visit_ActiveSupport_StringInquirer :terminal
alias :visit_Arel_Nodes_Lock :terminal
alias :visit_Arel_Nodes_Node :terminal
alias :visit_Arel_Nodes_SqlLiteral :terminal
alias :visit_Arel_SqlLiteral :terminal
alias :visit_BigDecimal :terminal
Expand Down
6 changes: 6 additions & 0 deletions test/visitors/test_depth_first.rb
Expand Up @@ -192,6 +192,12 @@ def test_insert_statement
@visitor.accept stmt
assert_equal [:a, :b, stmt.columns, :c, stmt], @collector.calls
end

def test_node
node = Nodes::Node.new
@visitor.accept node
assert_equal [node], @collector.calls
end
end
end
end

0 comments on commit f68b7c4

Please sign in to comment.