aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-10 12:35:57 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-10 12:35:57 -0700
commit8e014f28ccd380328f49075b62f23322c49033c2 (patch)
tree7cfa7afde35c4d91818b6e93741f1ad5e808f567
parent53454bfcb6b2351781cc7cde70792e347016c6f5 (diff)
downloadrails-8e014f28ccd380328f49075b62f23322c49033c2.tar.gz
rails-8e014f28ccd380328f49075b62f23322c49033c2.tar.bz2
rails-8e014f28ccd380328f49075b62f23322c49033c2.zip
add a null node at the top of the stack
this gives us an easier way to iterate the stack
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb22
1 files changed, 9 insertions, 13 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 928243fc65..9b52598648 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1702,9 +1702,9 @@ module ActionDispatch
end
def shallow_nesting_depth #:nodoc:
- @scope.find_all { |frame|
- frame[:scope_level_resource]
- }.count { |frame| frame[:scope_level_resource].shallow? }
+ @scope.find_all { |node|
+ node.frame[:scope_level_resource]
+ }.count { |node| node.frame[:scope_level_resource].shallow? }
end
def param_constraint? #:nodoc:
@@ -1974,16 +1974,14 @@ module ActionDispatch
self.class.new hash, self, scope_level
end
+ EMPTY_HASH = {}.freeze
def new_level(level)
- self.class.new(self, self, level)
- end
-
- def fetch(key, &block)
- @hash.fetch(key, &block)
+ self.class.new(EMPTY_HASH, self, level)
end
def [](key)
- @hash.fetch(key) { @parent[key] }
+ scope = find { |node| node.frame.key? key }
+ scope && scope.frame[key]
end
include Enumerable
@@ -1992,16 +1990,14 @@ module ActionDispatch
node = self
loop do
break if node.equal? NULL
- yield node.frame
+ yield node
node = node.parent
end
end
- protected
-
def frame; @hash; end
- NULL = Scope.new({}.freeze, {}.freeze)
+ NULL = Scope.new(nil, nil)
end
def initialize(set) #:nodoc: