diff options
author | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-12-20 15:42:39 -0500 |
---|---|---|
committer | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-12-20 15:42:39 -0500 |
commit | eb493f5ac84f2d65fbd1666e1496f0a8deafa27f (patch) | |
tree | 6c8226f652f99648a1898c2cfa33f9aa13041925 /actionpack/lib/action_dispatch/journey/visitors.rb | |
parent | 42b555dcf3d3dfc8c4b56e6bf903389f014bf05e (diff) | |
download | rails-eb493f5ac84f2d65fbd1666e1496f0a8deafa27f.tar.gz rails-eb493f5ac84f2d65fbd1666e1496f0a8deafa27f.tar.bz2 rails-eb493f5ac84f2d65fbd1666e1496f0a8deafa27f.zip |
update AD::Journey to follow Rails coding conventions
Diffstat (limited to 'actionpack/lib/action_dispatch/journey/visitors.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/journey/visitors.rb | 187 |
1 files changed, 95 insertions, 92 deletions
diff --git a/actionpack/lib/action_dispatch/journey/visitors.rb b/actionpack/lib/action_dispatch/journey/visitors.rb index 8c055376ca..46bd58c178 100644 --- a/actionpack/lib/action_dispatch/journey/visitors.rb +++ b/actionpack/lib/action_dispatch/journey/visitors.rb @@ -7,69 +7,70 @@ module ActionDispatch h[k] = "visit_#{k}" } - def accept node - visit node + def accept(node) + visit(node) end private - def visit node - send DISPATCH_CACHE[node.type], node - end - def binary node - visit node.left - visit node.right - end - def visit_CAT(n); binary(n); end + def visit node + send(DISPATCH_CACHE[node.type], node) + end - def nary node - node.children.each { |c| visit c } - end - def visit_OR(n); nary(n); end + def binary(node) + visit(node.left) + visit(node.right) + end + def visit_CAT(n); binary(n); end - def unary node - visit node.left - end - def visit_GROUP(n); unary(n); end - def visit_STAR(n); unary(n); end + def nary(node) + node.children.each { |c| visit(c) } + end + def visit_OR(n); nary(n); end - def terminal node; end - %w{ LITERAL SYMBOL SLASH DOT }.each do |t| - class_eval %{ def visit_#{t}(n); terminal(n); end }, __FILE__, __LINE__ - end + def unary(node) + visit(node.left) + end + def visit_GROUP(n); unary(n); end + def visit_STAR(n); unary(n); end + + def terminal(node); end + %w{ LITERAL SYMBOL SLASH DOT }.each do |t| + class_eval %{ def visit_#{t}(n); terminal(n); end }, __FILE__, __LINE__ + end end # Loop through the requirements AST class Each < Visitor # :nodoc: attr_reader :block - def initialize block + def initialize(block) @block = block end - def visit node + def visit(node) super - block.call node + block.call(node) end end class String < Visitor # :nodoc: private - def binary node + def binary(node) [visit(node.left), visit(node.right)].join end - def nary node - node.children.map { |c| visit c }.join '|' + def nary(node) + node.children.map { |c| visit(c) }.join '|' end - def terminal node + def terminal(node) node.left end - def visit_GROUP node - "(#{visit node.left})" + def visit_GROUP(node) + "(#{visit(node.left)})" end end @@ -77,43 +78,44 @@ module ActionDispatch class Formatter < Visitor # :nodoc: attr_reader :options, :consumed - def initialize options + def initialize(options) @options = options @consumed = {} end private - def visit_GROUP node - if consumed == options - nil - else - route = visit node.left - route.include?("\0") ? nil : route + + def visit_GROUP(node) + if consumed == options + nil + else + route = visit(node.left) + route.include?("\0") ? nil : route + end end - end - def terminal node - node.left - end + def terminal(node) + node.left + end - def binary node - [visit(node.left), visit(node.right)].join - end + def binary(node) + [visit(node.left), visit(node.right)].join + end - def nary node - node.children.map { |c| visit c }.join - end + def nary(node) + node.children.map { |c| visit(c) }.join + end - def visit_SYMBOL node - key = node.to_sym + def visit_SYMBOL(node) + key = node.to_sym - if value = options[key] - consumed[key] = value - Router::Utils.escape_path(value) - else - "\0" + if value = options[key] + consumed[key] = value + Router::Utils.escape_path(value) + else + "\0" + end end - end end class Dot < Visitor # :nodoc: @@ -122,7 +124,7 @@ module ActionDispatch @edges = [] end - def accept node + def accept(node) super <<-eodot digraph parse_tree { @@ -136,50 +138,51 @@ module ActionDispatch end private - def binary node - node.children.each do |c| - @edges << "#{node.object_id} -> #{c.object_id};" + + def binary(node) + node.children.each do |c| + @edges << "#{node.object_id} -> #{c.object_id};" + end + super end - super - end - def nary node - node.children.each do |c| - @edges << "#{node.object_id} -> #{c.object_id};" + def nary(node) + node.children.each do |c| + @edges << "#{node.object_id} -> #{c.object_id};" + end + super end - super - end - def unary node - @edges << "#{node.object_id} -> #{node.left.object_id};" - super - end + def unary(node) + @edges << "#{node.object_id} -> #{node.left.object_id};" + super + end - def visit_GROUP node - @nodes << "#{node.object_id} [label=\"()\"];" - super - end + def visit_GROUP(node) + @nodes << "#{node.object_id} [label=\"()\"];" + super + end - def visit_CAT node - @nodes << "#{node.object_id} [label=\"○\"];" - super - end + def visit_CAT(node) + @nodes << "#{node.object_id} [label=\"○\"];" + super + end - def visit_STAR node - @nodes << "#{node.object_id} [label=\"*\"];" - super - end + def visit_STAR(node) + @nodes << "#{node.object_id} [label=\"*\"];" + super + end - def visit_OR node - @nodes << "#{node.object_id} [label=\"|\"];" - super - end + def visit_OR(node) + @nodes << "#{node.object_id} [label=\"|\"];" + super + end - def terminal node - value = node.left + def terminal(node) + value = node.left - @nodes << "#{node.object_id} [label=\"#{value}\"];" - end + @nodes << "#{node.object_id} [label=\"#{value}\"];" + end end end end |