change rdoc to conform to api guidelines
This commit is contained in:
parent
111c4a4a01
commit
eaeda503e8
@ -6,6 +6,10 @@ module AbstractController
|
||||
class Error < StandardError; end
|
||||
class ActionNotFound < StandardError; end
|
||||
|
||||
# AbstractController is a low-level API. Nobody should be using it directly,
|
||||
# and subclasses of AbstractController (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
|
||||
@ -41,8 +45,7 @@ def internal_methods
|
||||
# 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,8 +57,7 @@ def hidden_actions
|
||||
# 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
|
||||
@ -84,7 +86,7 @@ def clear_action_methods!
|
||||
# controller_name.
|
||||
#
|
||||
# ==== Returns
|
||||
# String
|
||||
# * <tt>String</tt>
|
||||
def controller_path
|
||||
@controller_path ||= name.sub(/Controller$/, '').underscore unless anonymous?
|
||||
end
|
||||
@ -104,7 +106,7 @@ def method_added(name)
|
||||
# ActionNotFound error is raised.
|
||||
#
|
||||
# ==== Returns
|
||||
# self
|
||||
# * <tt>self</tt>
|
||||
def process(action, *args)
|
||||
@_action_name = action_name = action.to_s
|
||||
|
||||
@ -133,10 +135,10 @@ def action_methods
|
||||
# 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 @@ def _handle_action_missing
|
||||
# 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"
|
||||
|
@ -28,9 +28,8 @@ module ClassMethods
|
||||
# a Rails process.
|
||||
#
|
||||
# ==== Options
|
||||
# :only<#to_s>:: The callback should be run only for this action
|
||||
# :except<#to_s>:: The callback should be run for all actions
|
||||
# except this action
|
||||
# * <tt>only</tt> - The callback should be run only for this action
|
||||
# * <tt>except<tt> - The callback should be run for all actions except this action
|
||||
def _normalize_callback_options(options)
|
||||
if only = options[:only]
|
||||
only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ")
|
||||
@ -45,7 +44,7 @@ def _normalize_callback_options(options)
|
||||
# Skip before, after, and around filters matching any of the names
|
||||
#
|
||||
# ==== Parameters
|
||||
# *names<Object>:: A list of valid names that could be used for
|
||||
# * <tt>names</tt> - A list of valid names that could be used for
|
||||
# callbacks. Note that skipping uses Ruby equality, so it's
|
||||
# impossible to skip a callback defined using an anonymous proc
|
||||
# using #skip_filter
|
||||
@ -60,13 +59,13 @@ def skip_filter(*names, &blk)
|
||||
# the normalization across several methods that use it.
|
||||
#
|
||||
# ==== Parameters
|
||||
# callbacks<Array[*Object, Hash]>:: A list of callbacks, with an optional
|
||||
# * <tt>callbacks</tt> - An array of callbacks, with an optional
|
||||
# options hash as the last parameter.
|
||||
# block<Proc>:: A proc that should be added to the callbacks.
|
||||
# * <tt>block</tt> - A proc that should be added to the callbacks.
|
||||
#
|
||||
# ==== Block Parameters
|
||||
# name<Symbol>:: The callback to be added
|
||||
# options<Hash>:: A list of options to be used when adding the callback
|
||||
# * <tt>name</tt> - The callback to be added
|
||||
# * <tt>options</tt> - A hash of options to be used when adding the callback
|
||||
def _insert_callbacks(callbacks, block)
|
||||
options = callbacks.last.is_a?(Hash) ? callbacks.pop : {}
|
||||
_normalize_callback_options(options)
|
||||
@ -82,27 +81,27 @@ def _insert_callbacks(callbacks, block)
|
||||
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
||||
# Append a before, after or around filter. See _insert_callbacks
|
||||
# for details on the allowed parameters.
|
||||
def #{filter}_filter(*names, &blk)
|
||||
_insert_callbacks(names, blk) do |name, options|
|
||||
set_callback(:process_action, :#{filter}, name, options)
|
||||
end
|
||||
end
|
||||
def #{filter}_filter(*names, &blk) # def before_filter(*names, &blk)
|
||||
_insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options}
|
||||
set_callback(:process_action, :#{filter}, name, options) # set_callback(:process_action, :before_filter, name, options)
|
||||
end # end
|
||||
end # end
|
||||
|
||||
# Prepend a before, after or around filter. See _insert_callbacks
|
||||
# for details on the allowed parameters.
|
||||
def prepend_#{filter}_filter(*names, &blk)
|
||||
_insert_callbacks(names, blk) do |name, options|
|
||||
set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true))
|
||||
end
|
||||
end
|
||||
def prepend_#{filter}_filter(*names, &blk) # def prepend_before_filter(*names, &blk)
|
||||
_insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
|
||||
set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) # set_callback(:process_action, :before, name, options.merge(:prepend => true))
|
||||
end # end
|
||||
end # end
|
||||
|
||||
# Skip a before, after or around filter. See _insert_callbacks
|
||||
# for details on the allowed parameters.
|
||||
def skip_#{filter}_filter(*names, &blk)
|
||||
_insert_callbacks(names, blk) do |name, options|
|
||||
skip_callback(:process_action, :#{filter}, name, options)
|
||||
end
|
||||
end
|
||||
def skip_#{filter}_filter(*names, &blk) # def skip_before_filter(*names, &blk)
|
||||
_insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
|
||||
skip_callback(:process_action, :#{filter}, name, options) # skip_callback(:process_action, :before, name, options)
|
||||
end # end
|
||||
end # end
|
||||
|
||||
# *_filter is the same as append_*_filter
|
||||
alias_method :append_#{filter}_filter, :#{filter}_filter
|
||||
|
@ -40,7 +40,7 @@ def inherited(klass)
|
||||
# <% if logged_in? -%>Welcome, <%= current_user.name %><% end -%>
|
||||
#
|
||||
# ==== Parameters
|
||||
# meths<Array[#to_s]>:: The name of a method on the controller
|
||||
# * <tt>method[, method]</tt> - A name or names of a method on the controller
|
||||
# to be made available on the view.
|
||||
def helper_method(*meths)
|
||||
meths.flatten.each do |meth|
|
||||
@ -55,8 +55,8 @@ def #{meth}(*args, &blk)
|
||||
# The +helper+ class method can take a series of helper module names, a block, or both.
|
||||
#
|
||||
# ==== Parameters
|
||||
# *args<Array[Module, Symbol, String, :all]>
|
||||
# block<Block>:: A block defining helper methods
|
||||
# * <tt>*args</tt> - Module, Symbol, String, :all
|
||||
# * <tt>block</tt> - A block defining helper methods
|
||||
#
|
||||
# ==== Examples
|
||||
# When the argument is a module it will be included directly in the template class.
|
||||
@ -100,7 +100,7 @@ def helper(*args, &block)
|
||||
# rendered through this controller.
|
||||
#
|
||||
# ==== Parameters
|
||||
# mod<Module>:: The module to include into the current helper module
|
||||
# * <tt>module</tt> - The module to include into the current helper module
|
||||
# for the class
|
||||
def add_template_helper(mod)
|
||||
_helpers.module_eval { include mod }
|
||||
@ -118,10 +118,10 @@ def add_template_helper(mod)
|
||||
# are returned.
|
||||
#
|
||||
# ==== Parameters
|
||||
# args<Array[String, Symbol, Module]>:: A list of helpers
|
||||
# * <tt>args</tt> - An array of helpers
|
||||
#
|
||||
# ==== Returns
|
||||
# Array[Module]:: A normalized list of modules for the list of
|
||||
# * <tt>Array</tt> - A normalized list of modules for the list of
|
||||
# helpers provided.
|
||||
def modules_for_helpers(args)
|
||||
args.flatten.map! do |arg|
|
||||
|
@ -114,11 +114,13 @@ module AbstractController
|
||||
#
|
||||
# class WeblogController < ActionController::Base
|
||||
# layout proc{ |controller| controller.logged_in? ? "writer_layout" : "reader_layout" }
|
||||
# end
|
||||
#
|
||||
# Of course, the most common way of specifying a layout is still just as a plain template name:
|
||||
#
|
||||
# class WeblogController < ActionController::Base
|
||||
# layout "weblog_standard"
|
||||
# end
|
||||
#
|
||||
# If no directory is specified for the template name, the template will by default be looked for in <tt>app/views/layouts/</tt>.
|
||||
# Otherwise, it will be looked up relative to the template root.
|
||||
@ -183,7 +185,7 @@ module LayoutConditions
|
||||
# layout.
|
||||
#
|
||||
# ==== Returns
|
||||
# Boolean:: True if the action has a layout, false otherwise.
|
||||
# * <tt> Boolean</tt> - True if the action has a layout, false otherwise.
|
||||
def action_has_layout?
|
||||
return unless super
|
||||
|
||||
@ -209,11 +211,11 @@ def action_has_layout?
|
||||
# true:: raise an ArgumentError
|
||||
#
|
||||
# ==== Parameters
|
||||
# layout<String, Symbol, false)>:: The layout to use.
|
||||
# * <tt>String, Symbol, false</tt> - The layout to use.
|
||||
#
|
||||
# ==== Options (conditions)
|
||||
# :only<#to_s, Array[#to_s]>:: A list of actions to apply this layout to.
|
||||
# :except<#to_s, Array[#to_s]>:: Apply this layout to all actions but this one
|
||||
# * :only - A list of actions to apply this layout to.
|
||||
# * :except - Apply this layout to all actions but this one.
|
||||
def layout(layout, conditions = {})
|
||||
include LayoutConditions unless conditions.empty?
|
||||
|
||||
@ -228,7 +230,7 @@ def layout(layout, conditions = {})
|
||||
# value of this method.
|
||||
#
|
||||
# ==== Returns
|
||||
# String:: A template name
|
||||
# * <tt>String</tt> - A template name
|
||||
def _implied_layout_name
|
||||
controller_path
|
||||
end
|
||||
@ -313,8 +315,8 @@ def _layout; end
|
||||
# the name type.
|
||||
#
|
||||
# ==== Parameters
|
||||
# name<String|TrueClass|FalseClass|Symbol>:: The name of the template
|
||||
# details<Hash{Symbol => Object}>:: A list of details to restrict
|
||||
# * <tt>name</tt> - The name of the template
|
||||
# * <tt>details</tt> - A list of details to restrict
|
||||
# the lookup to. By default, layout lookup is limited to the
|
||||
# formats specified for the current request.
|
||||
def _layout_for_option(name)
|
||||
@ -333,14 +335,14 @@ def _layout_for_option(name)
|
||||
# Optionally raises an exception if the layout could not be found.
|
||||
#
|
||||
# ==== Parameters
|
||||
# details<Hash>:: A list of details to restrict the search by. This
|
||||
# * <tt>details</tt> - A list of details to restrict the search by. This
|
||||
# might include details like the format or locale of the template.
|
||||
# require_layout<Boolean>:: If this is true, raise an ArgumentError
|
||||
# * <tt>require_logout</tt> - If this is true, raise an ArgumentError
|
||||
# with details about the fact that the exception could not be
|
||||
# found (defaults to false)
|
||||
#
|
||||
# ==== Returns
|
||||
# Template:: The template object for the default layout (or nil)
|
||||
# * <tt>template</tt> - The template object for the default layout (or nil)
|
||||
def _default_layout(require_layout = false)
|
||||
begin
|
||||
layout_name = _layout if action_has_layout?
|
||||
|
@ -34,9 +34,9 @@ module ClassMethods
|
||||
# Append a path to the list of view paths for this controller.
|
||||
#
|
||||
# ==== Parameters
|
||||
# path<String, ViewPath>:: If a String is provided, it gets converted into
|
||||
# the default view path. You may also provide a custom view path
|
||||
# (see ActionView::ViewPathSet for more information)
|
||||
# * <tt>path</tt> - If a String is provided, it gets converted into
|
||||
# the default view path. You may also provide a custom view path
|
||||
# (see ActionView::ViewPathSet for more information)
|
||||
def append_view_path(path)
|
||||
self.view_paths = view_paths.dup + Array(path)
|
||||
end
|
||||
@ -44,9 +44,9 @@ def append_view_path(path)
|
||||
# Prepend a path to the list of view paths for this controller.
|
||||
#
|
||||
# ==== Parameters
|
||||
# path<String, ViewPath>:: If a String is provided, it gets converted into
|
||||
# the default view path. You may also provide a custom view path
|
||||
# (see ActionView::ViewPathSet for more information)
|
||||
# * <tt>path</tt> - If a String is provided, it gets converted into
|
||||
# the default view path. You may also provide a custom view path
|
||||
# (see ActionView::ViewPathSet for more information)
|
||||
def prepend_view_path(path)
|
||||
self.view_paths = Array(path) + view_paths.dup
|
||||
end
|
||||
@ -59,7 +59,7 @@ def view_paths
|
||||
# Set the view paths.
|
||||
#
|
||||
# ==== Parameters
|
||||
# paths<ViewPathSet, Object>:: If a ViewPathSet is provided, use that;
|
||||
# * <tt>paths</tt> - If a ViewPathSet is provided, use that;
|
||||
# otherwise, process the parameter into a ViewPathSet.
|
||||
def view_paths=(paths)
|
||||
self._view_paths = ActionView::Base.process_view_paths(paths)
|
||||
|
Loading…
Reference in New Issue
Block a user