From f514c9c04aeef8b2a90dc1bfc97d7dff833bdcd8 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 12 Aug 2015 15:50:14 -0700 Subject: 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. --- actionpack/lib/action_dispatch/routing/mapper.rb | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'actionpack/lib') 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: -- cgit v1.2.3