aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-12 15:50:14 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-12 15:50:14 -0700
commitf514c9c04aeef8b2a90dc1bfc97d7dff833bdcd8 (patch)
treee0c9fabd82db0d62a1c0ac540e63c239356dc1d0 /actionpack
parent33d20ea18474e5c7a14d72fcbafc0c63bf812aba (diff)
downloadrails-f514c9c04aeef8b2a90dc1bfc97d7dff833bdcd8.tar.gz
rails-f514c9c04aeef8b2a90dc1bfc97d7dff833bdcd8.tar.bz2
rails-f514c9c04aeef8b2a90dc1bfc97d7dff833bdcd8.zip
don't mutate the caller's variables
Remove the `options` reader from `Resource` because nobody needs to see that hash. Also remove mutations on the options hash in `apply_common_behavior_for` because leaving the side effects in that method makes it difficult to understand what is going on in the caller.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb29
1 files changed, 15 insertions, 14 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index baaa374c6b..e7c24b6f04 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1065,7 +1065,7 @@ module ActionDispatch
CANONICAL_ACTIONS = %w(index create new show update destroy)
class Resource #:nodoc:
- attr_reader :controller, :path, :options, :param
+ attr_reader :controller, :path, :param
def initialize(entities, api_only, shallow, options = {})
@name = entities.to_s
@@ -1076,6 +1076,8 @@ module ActionDispatch
@options = options
@shallow = shallow
@api_only = api_only
+ @only = options.delete :only
+ @except = options.delete :except
end
def default_actions
@@ -1087,10 +1089,10 @@ module ActionDispatch
end
def actions
- if only = @options[:only]
- Array(only).map(&:to_sym)
- elsif except = @options[:except]
- default_actions - Array(except).map(&:to_sym)
+ if @only
+ Array(@only).map(&:to_sym)
+ elsif @except
+ default_actions - Array(@except).map(&:to_sym)
else
default_actions
end
@@ -1213,6 +1215,7 @@ module ActionDispatch
end
with_scope_level(:resource) do
+ options = apply_action_options options
resource_scope(SingletonResource.new(resources.pop, api_only?, @scope[:shallow], options)) do
yield if block_given?
@@ -1373,6 +1376,7 @@ module ActionDispatch
end
with_scope_level(:resources) do
+ options = apply_action_options options
resource_scope(Resource.new(resources.pop, api_only?, @scope[:shallow], options)) do
yield if block_given?
@@ -1671,23 +1675,20 @@ module ActionDispatch
return true
end
- unless action_options?(options)
- options.merge!(scope_action_options) if scope_action_options?
- end
-
false
end
- def action_options?(options) #:nodoc:
- options[:only] || options[:except]
+ def apply_action_options(options) # :nodoc:
+ return options if action_options? options
+ options.merge scope_action_options
end
- def scope_action_options? #:nodoc:
- @scope[:action_options]
+ def action_options?(options) #:nodoc:
+ options[:only] || options[:except]
end
def scope_action_options #:nodoc:
- @scope[:action_options]
+ @scope[:action_options] || {}
end
def resource_scope? #:nodoc: