From e5248aacd0718afbf2f631dbb3274b501695c474 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 13 Nov 2012 14:32:47 -0800 Subject: lazily calculate name in the options object --- .../lib/action_controller/metal/params_wrapper.rb | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'actionpack/lib/action_controller/metal/params_wrapper.rb') diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index c5dbe6b45e..a475d4bdff 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -113,6 +113,22 @@ module ActionController end end + def name + return super if @name_set + + m = model + synchronize do + return super if @name_set + + @name_set = true + + unless super || klass.anonymous? + self.name = m ? m.to_s.demodulize.underscore : + klass.controller_name.singularize + end + end + end + private # Determine the wrapper model from the controller's name. By convention, # this could be done by trying to find the defined model that has the @@ -195,7 +211,7 @@ module ActionController opts.model = model opts.klass = self - _set_wrapper_defaults(opts) + self._wrapper_options = opts end # Sets the default wrapper key or model which will be used to determine @@ -205,22 +221,10 @@ module ActionController if klass._wrapper_options.format.any? params = klass._wrapper_options.dup params.klass = klass - klass._set_wrapper_defaults(params) + klass._wrapper_options = params end super end - - protected - - def _set_wrapper_defaults(opts) - unless opts.name || opts.klass.anonymous? - model = opts.model - opts.name = model ? model.to_s.demodulize.underscore : - controller_name.singularize - end - - self._wrapper_options = opts - end end # Performs parameters wrapping upon the request. Will be called automatically -- cgit v1.2.3