From d2b9e39c8562dba58d0d76646866a1949eb3f9a6 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 5 Jul 2005 01:30:49 +0000 Subject: r2828@asus: jeremy | 2005-07-04 22:02:44 -0700 cache controller_name and controller_path git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1689 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/base.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 15430839e7..a8c2f206b9 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -286,20 +286,24 @@ module ActionController #:nodoc: # Converts the class name from something like "OneModule::TwoModule::NeatController" to "NeatController". def controller_class_name - Inflector.demodulize(name) + @controller_class_name ||= name.demodulize end # Converts the class name from something like "OneModule::TwoModule::NeatController" to "neat". def controller_name - Inflector.underscore(controller_class_name.sub(/Controller/, "")) + @controller_name ||= controller_class_name.sub(/Controller$/, '').underscore end # Convert the class name from something like "OneModule::TwoModule::NeatController" to "one_module/two_module/neat". def controller_path - components = self.name.to_s.split('::').collect { |name| name.underscore } - components[-1] = $1 if /^(.*)_controller$/ =~ components[-1] - components.shift if components.first == 'controllers' # Transitional conditional to accomodate root Controllers module - components.join('/') + unless @controller_path + components = self.name.to_s.split('::') + components[-1] = $1 if /^(.*)Controller$/ =~ components.last + # Accomodate the root Controllers module. + components.shift if components.first == 'Controllers' + @controller_path = components.map { |name| name.underscore }.join('/') + end + @controller_path end # Return an array containing the names of public methods that have been marked hidden from the action processor. -- cgit v1.2.3