提交 43ce6e22 编写于 作者: A Aaron Patterson

ask the scope object if it is a resource_method_scope

上级 e4cb3819
...@@ -1046,7 +1046,6 @@ module Resources ...@@ -1046,7 +1046,6 @@ module Resources
VALID_ON_OPTIONS = [:new, :collection, :member] VALID_ON_OPTIONS = [:new, :collection, :member]
RESOURCE_OPTIONS = [:as, :controller, :path, :only, :except, :param, :concerns] RESOURCE_OPTIONS = [:as, :controller, :path, :only, :except, :param, :concerns]
CANONICAL_ACTIONS = %w(index create new show update destroy) CANONICAL_ACTIONS = %w(index create new show update destroy)
RESOURCE_METHOD_SCOPES = [:collection, :member, :new]
class Resource #:nodoc: class Resource #:nodoc:
attr_reader :controller, :path, :options, :param attr_reader :controller, :path, :options, :param
...@@ -1633,8 +1632,8 @@ def resource_scope? #:nodoc: ...@@ -1633,8 +1632,8 @@ def resource_scope? #:nodoc:
@scope.resource_scope? @scope.resource_scope?
end end
def resource_method_scope?(scope_level) #:nodoc: def resource_method_scope? #:nodoc:
RESOURCE_METHOD_SCOPES.include? scope_level @scope.resource_method_scope?
end end
def nested_scope? #:nodoc: def nested_scope? #:nodoc:
...@@ -1698,8 +1697,8 @@ def param_constraint #:nodoc: ...@@ -1698,8 +1697,8 @@ def param_constraint #:nodoc:
@scope[:constraints][parent_resource.param] @scope[:constraints][parent_resource.param]
end end
def canonical_action?(action, scope_level) #:nodoc: def canonical_action?(action) #:nodoc:
scope_level && resource_method_scope?(scope_level) && CANONICAL_ACTIONS.include?(action.to_s) resource_method_scope? && CANONICAL_ACTIONS.include?(action.to_s)
end end
def shallow_scope(path, options = {}) #:nodoc: def shallow_scope(path, options = {}) #:nodoc:
...@@ -1713,7 +1712,7 @@ def shallow_scope(path, options = {}) #:nodoc: ...@@ -1713,7 +1712,7 @@ def shallow_scope(path, options = {}) #:nodoc:
end end
def path_for_action(action, path) #:nodoc: def path_for_action(action, path) #:nodoc:
if path.blank? && canonical_action?(action, @scope.scope_level) if path.blank? && canonical_action?(action)
@scope[:path].to_s @scope[:path].to_s
else else
"#{@scope[:path]}/#{action_path(action, path)}" "#{@scope[:path]}/#{action_path(action, path)}"
...@@ -1725,10 +1724,10 @@ def action_path(name, path = nil) #:nodoc: ...@@ -1725,10 +1724,10 @@ def action_path(name, path = nil) #:nodoc:
path || @scope[:path_names][name] || name.to_s path || @scope[:path_names][name] || name.to_s
end end
def prefix_name_for_action(as, action, scope_level) #:nodoc: def prefix_name_for_action(as, action) #:nodoc:
if as if as
prefix = as prefix = as
elsif !canonical_action?(action, scope_level) elsif !canonical_action?(action)
prefix = action prefix = action
end end
...@@ -1738,8 +1737,7 @@ def prefix_name_for_action(as, action, scope_level) #:nodoc: ...@@ -1738,8 +1737,7 @@ def prefix_name_for_action(as, action, scope_level) #:nodoc:
end end
def name_for_action(as, action) #:nodoc: def name_for_action(as, action) #:nodoc:
scope_level = @scope.scope_level prefix = prefix_name_for_action(as, action)
prefix = prefix_name_for_action(as, action, scope_level)
name_prefix = @scope[:as] name_prefix = @scope[:as]
if parent_resource if parent_resource
...@@ -1887,6 +1885,7 @@ class Scope # :nodoc: ...@@ -1887,6 +1885,7 @@ class Scope # :nodoc:
:shallow, :blocks, :defaults, :options] :shallow, :blocks, :defaults, :options]
RESOURCE_SCOPES = [:resource, :resources] RESOURCE_SCOPES = [:resource, :resources]
RESOURCE_METHOD_SCOPES = [:collection, :member, :new]
attr_reader :parent, :scope_level attr_reader :parent, :scope_level
...@@ -1904,6 +1903,10 @@ def resources? ...@@ -1904,6 +1903,10 @@ def resources?
scope_level == :resources scope_level == :resources
end end
def resource_method_scope?
RESOURCE_METHOD_SCOPES.include? scope_level
end
def action_name(name_prefix, prefix, collection_name, member_name) def action_name(name_prefix, prefix, collection_name, member_name)
case scope_level case scope_level
when :nested when :nested
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册