aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/params_wrapper.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-11-13 14:32:47 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-11-13 16:35:16 -0800
commite5248aacd0718afbf2f631dbb3274b501695c474 (patch)
tree97fcb5367acdc763925f308ba1be9edf4c070f89 /actionpack/lib/action_controller/metal/params_wrapper.rb
parent2a51d6c3bba3b295ad6696baeae351b359225c2e (diff)
downloadrails-e5248aacd0718afbf2f631dbb3274b501695c474.tar.gz
rails-e5248aacd0718afbf2f631dbb3274b501695c474.tar.bz2
rails-e5248aacd0718afbf2f631dbb3274b501695c474.zip
lazily calculate name in the options object
Diffstat (limited to 'actionpack/lib/action_controller/metal/params_wrapper.rb')
-rw-r--r--actionpack/lib/action_controller/metal/params_wrapper.rb32
1 files changed, 18 insertions, 14 deletions
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