aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/abstract_controller/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/abstract_controller/base.rb')
-rw-r--r--actionpack/lib/abstract_controller/base.rb46
1 files changed, 24 insertions, 22 deletions
diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb
index db0a6736e0..c384fd0978 100644
--- a/actionpack/lib/abstract_controller/base.rb
+++ b/actionpack/lib/abstract_controller/base.rb
@@ -6,9 +6,14 @@ module AbstractController
class Error < StandardError; end
class ActionNotFound < StandardError; end
+ # <tt>AbstractController::Base</tt> is a low-level API. Nobody should be
+ # using it directly, and subclasses (like ActionController::Base) are
+ # expected to provide their own +render+ method, since rendering means
+ # different things depending on the context.
class Base
attr_internal :response_body
attr_internal :action_name
+ attr_internal :formats
include ActiveSupport::Configurable
extend ActiveSupport::DescendantsTracker
@@ -26,23 +31,21 @@ module AbstractController
# A list of all internal methods for a controller. This finds the first
# abstract superclass of a controller, and gets a list of all public
# instance methods on that abstract class. Public instance methods of
- # a controller would normally be considered action methods, so we
- # are removing those methods on classes declared as abstract
- # (ActionController::Metal and ActionController::Base are defined
- # as abstract)
+ # a controller would normally be considered action methods, so methods
+ # declared on abstract classes are being removed.
+ # (ActionController::Metal and ActionController::Base are defined as abstract)
def internal_methods
controller = self
controller = controller.superclass until controller.abstract?
controller.public_instance_methods(true)
end
- # The list of hidden actions to an empty Array. Defaults to an
- # empty Array. This can be modified by other modules or subclasses
+ # The list of hidden actions to an empty array. Defaults to an
+ # empty array. This can be modified by other modules or subclasses
# to specify particular actions as hidden.
#
# ==== Returns
- # Array[String]:: An array of method names that should not be
- # considered actions.
+ # * <tt>array</tt> - An array of method names that should not be considered actions.
def hidden_actions
[]
end
@@ -54,18 +57,17 @@ module AbstractController
# itself. Finally, #hidden_actions are removed.
#
# ==== Returns
- # Array[String]:: A list of all methods that should be considered
- # actions.
+ # * <tt>array</tt> - A list of all methods that should be considered actions.
def action_methods
@action_methods ||= begin
# All public instance methods of this class, including ancestors
- methods = public_instance_methods(true).map { |m| m.to_s }.to_set -
+ methods = (public_instance_methods(true) -
# Except for public instance methods of Base and its ancestors
- internal_methods.map { |m| m.to_s } +
+ internal_methods +
# Be sure to include shadowed public instance methods of this class
- public_instance_methods(false).map { |m| m.to_s } -
+ public_instance_methods(false)).uniq.map { |x| x.to_s } -
# And always exclude explicitly hidden actions
- hidden_actions
+ hidden_actions.to_a
# Clear out AS callback method pollution
methods.reject { |method| method =~ /_one_time_conditions/ }
@@ -84,7 +86,7 @@ module AbstractController
# controller_name.
#
# ==== Returns
- # String
+ # * <tt>string</tt>
def controller_path
@controller_path ||= name.sub(/Controller$/, '').underscore unless anonymous?
end
@@ -104,12 +106,12 @@ module AbstractController
# ActionNotFound error is raised.
#
# ==== Returns
- # self
+ # * <tt>self</tt>
def process(action, *args)
@_action_name = action_name = action.to_s
unless action_name = method_for_action(action_name)
- raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
+ raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
end
@_response_body = nil
@@ -133,10 +135,10 @@ module AbstractController
# can be considered an action.
#
# ==== Parameters
- # name<String>:: The name of an action to be tested
+ # * <tt>name</tt> - The name of an action to be tested
#
# ==== Returns
- # TrueClass, FalseClass
+ # * <tt>TrueClass</tt>, <tt>FalseClass</tt>
def action_method?(name)
self.class.action_methods.include?(name)
end
@@ -180,11 +182,11 @@ module AbstractController
# returns nil, an ActionNotFound exception will be raised.
#
# ==== Parameters
- # action_name<String>:: An action name to find a method name for
+ # * <tt>action_name</tt> - An action name to find a method name for
#
# ==== Returns
- # String:: The name of the method that handles the action
- # nil:: No method name could be found. Raise ActionNotFound.
+ # * <tt>string</tt> - The name of the method that handles the action
+ # * <tt>nil</tt> - No method name could be found. Raise ActionNotFound.
def method_for_action(action_name)
if action_method?(action_name) then action_name
elsif respond_to?(:action_missing, true) then "_handle_action_missing"