aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/mapper.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-08-13 19:22:30 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-08-13 19:30:46 -0700
commit911ef972a540686fd7fe7a3dee659ce3bb1fd12d (patch)
treebd1903cc002c1951cf5097d1c334a61c604db9b6 /actionpack/lib/action_dispatch/routing/mapper.rb
parent2440933fe2c27b27bcafcd9019717800db2641aa (diff)
downloadrails-911ef972a540686fd7fe7a3dee659ce3bb1fd12d.tar.gz
rails-911ef972a540686fd7fe7a3dee659ce3bb1fd12d.tar.bz2
rails-911ef972a540686fd7fe7a3dee659ce3bb1fd12d.zip
move scope_level to a method on the scope object
now we don't have to have a hard coded key
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb27
1 files changed, 20 insertions, 7 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 2f03e22be3..77d9889f28 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1047,7 +1047,6 @@ module ActionDispatch
RESOURCE_OPTIONS = [:as, :controller, :path, :only, :except, :param, :concerns]
CANONICAL_ACTIONS = %w(index create new show update destroy)
RESOURCE_METHOD_SCOPES = [:collection, :member, :new]
- RESOURCE_SCOPES = [:resource, :resources]
class Resource #:nodoc:
attr_reader :controller, :path, :options, :param
@@ -1521,7 +1520,7 @@ module ActionDispatch
if on = options.delete(:on)
send(on) { decomposed_match(path, options) }
else
- case @scope[:scope_level]
+ case @scope.scope_level
when :resources
nested { decomposed_match(path, options) }
when :resource
@@ -1564,7 +1563,7 @@ module ActionDispatch
raise ArgumentError, "must be called with a path and/or options"
end
- if @scope[:scope_level] == :resources
+ if @scope.scope_level == :resources
with_scope_level(:root) do
scope(parent_resource.path) do
super(options)
@@ -1631,7 +1630,7 @@ module ActionDispatch
end
def resource_scope? #:nodoc:
- RESOURCE_SCOPES.include? @scope[:scope_level]
+ @scope.resource_scope?
end
def resource_method_scope?(scope_level) #:nodoc:
@@ -1639,7 +1638,7 @@ module ActionDispatch
end
def nested_scope? #:nodoc:
- @scope[:scope_level] == :nested
+ @scope.nested?
end
def with_exclusive_scope
@@ -1714,7 +1713,7 @@ module ActionDispatch
end
def path_for_action(action, path) #:nodoc:
- if path.blank? && canonical_action?(action, @scope[:scope_level])
+ if path.blank? && canonical_action?(action, @scope.scope_level)
@scope[:path].to_s
else
"#{@scope[:path]}/#{action_path(action, path)}"
@@ -1739,7 +1738,7 @@ module ActionDispatch
end
def name_for_action(as, action) #:nodoc:
- scope_level = @scope[:scope_level]
+ scope_level = @scope.scope_level
prefix = prefix_name_for_action(as, action, scope_level)
name_prefix = @scope[:as]
@@ -1900,6 +1899,8 @@ module ActionDispatch
:controller, :action, :path_names, :constraints,
:shallow, :blocks, :defaults, :options]
+ RESOURCE_SCOPES = [:resource, :resources]
+
attr_reader :parent
def initialize(hash, parent = {})
@@ -1907,6 +1908,18 @@ module ActionDispatch
@parent = parent
end
+ def scope_level
+ self[:scope_level]
+ end
+
+ def nested?
+ scope_level == :nested
+ end
+
+ def resource_scope?
+ RESOURCE_SCOPES.include? scope_level
+ end
+
def options
OPTIONS
end