Permalink
Browse files

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
  • Loading branch information...
1 parent c6f819e commit d2b9e39c8562dba58d0d76646866a1949eb3f9a6 @jeremy jeremy committed Jul 5, 2005
Showing with 10 additions and 6 deletions.
  1. +10 −6 actionpack/lib/action_controller/base.rb
@@ -286,20 +286,24 @@ def process(request, response) #: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.

0 comments on commit d2b9e39

Please sign in to comment.