From 53454bfcb6b2351781cc7cde70792e347016c6f5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 10 Aug 2015 12:16:49 -0700 Subject: remove `@nesting` ivar The same information is stored in the `@scope` linked list, so just get it from there. --- actionpack/lib/action_dispatch/routing/mapper.rb | 30 +++++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 5158df8ac9..928243fc65 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1684,13 +1684,11 @@ module ActionDispatch def resource_scope(kind, resource) #:nodoc: @scope = @scope.new(:scope_level_resource => resource) - @nesting.push(resource) with_scope_level(kind) do controller_scope(resource.resource_scope) { yield } end ensure - @nesting.pop @scope = @scope.parent end @@ -1703,12 +1701,10 @@ module ActionDispatch options end - def nesting_depth #:nodoc: - @nesting.size - end - def shallow_nesting_depth #:nodoc: - @nesting.count(&:shallow?) + @scope.find_all { |frame| + frame[:scope_level_resource] + }.count { |frame| frame[:scope_level_resource].shallow? } end def param_constraint? #:nodoc: @@ -1931,7 +1927,7 @@ module ActionDispatch attr_reader :parent, :scope_level - def initialize(hash, parent = {}, scope_level = nil) + def initialize(hash, parent = NULL, scope_level = nil) @hash = hash @parent = parent @scope_level = scope_level @@ -1989,13 +1985,29 @@ module ActionDispatch def [](key) @hash.fetch(key) { @parent[key] } end + + include Enumerable + + def each + node = self + loop do + break if node.equal? NULL + yield node.frame + node = node.parent + end + end + + protected + + def frame; @hash; end + + NULL = Scope.new({}.freeze, {}.freeze) end def initialize(set) #:nodoc: @set = set @scope = Scope.new({ :path_names => @set.resources_path_names }) @concerns = {} - @nesting = [] end include Base -- cgit v1.2.3