mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
base class works with visitor
This commit is contained in:
parent
ae4c814f53
commit
f68b7c4e7e
4 changed files with 14 additions and 0 deletions
|
@ -1,5 +1,10 @@
|
||||||
== 2.0.5 (unreleased)
|
== 2.0.5 (unreleased)
|
||||||
|
|
||||||
|
* Enhancements
|
||||||
|
|
||||||
|
* Arel::Visitors::DepthFirst can walk your AST depth first
|
||||||
|
* Arel::Nodes::Node is enumerable, depth first
|
||||||
|
|
||||||
* Bug fixes
|
* Bug fixes
|
||||||
|
|
||||||
* #lock will lock SELECT statements "FOR UPDATE" on mysql
|
* #lock will lock SELECT statements "FOR UPDATE" on mysql
|
||||||
|
|
|
@ -37,6 +37,8 @@ module Arel
|
||||||
|
|
||||||
# Iterate through AST, nodes will be yielded depth-first
|
# Iterate through AST, nodes will be yielded depth-first
|
||||||
def each &block
|
def each &block
|
||||||
|
return enum_for(:each) unless block_given?
|
||||||
|
|
||||||
Visitors::DepthFirst.new(block).accept self
|
Visitors::DepthFirst.new(block).accept self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -93,6 +93,7 @@ module Arel
|
||||||
alias :visit_ActiveSupport_Multibyte_Chars :terminal
|
alias :visit_ActiveSupport_Multibyte_Chars :terminal
|
||||||
alias :visit_ActiveSupport_StringInquirer :terminal
|
alias :visit_ActiveSupport_StringInquirer :terminal
|
||||||
alias :visit_Arel_Nodes_Lock :terminal
|
alias :visit_Arel_Nodes_Lock :terminal
|
||||||
|
alias :visit_Arel_Nodes_Node :terminal
|
||||||
alias :visit_Arel_Nodes_SqlLiteral :terminal
|
alias :visit_Arel_Nodes_SqlLiteral :terminal
|
||||||
alias :visit_Arel_SqlLiteral :terminal
|
alias :visit_Arel_SqlLiteral :terminal
|
||||||
alias :visit_BigDecimal :terminal
|
alias :visit_BigDecimal :terminal
|
||||||
|
|
|
@ -192,6 +192,12 @@ module Arel
|
||||||
@visitor.accept stmt
|
@visitor.accept stmt
|
||||||
assert_equal [:a, :b, stmt.columns, :c, stmt], @collector.calls
|
assert_equal [:a, :b, stmt.columns, :c, stmt], @collector.calls
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_node
|
||||||
|
node = Nodes::Node.new
|
||||||
|
@visitor.accept node
|
||||||
|
assert_equal [node], @collector.calls
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue