diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 5158df8ac9d539b100f24bd769e41f49f66ea3e1..928243fc65a2d6a99e8cee9242f012ec54d25f5d 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1684,13 +1684,11 @@ def with_scope_level(kind) 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 @@ def nested_options #:nodoc: 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 @@ class Scope # :nodoc: 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 @@ def fetch(key, &block) 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