module AbstractController::Callbacks::ClassMethods
def _insert_callbacks(callbacks, block)
* name - The callback to be added
==== Block Parameters
* block - A proc that should be added to the callbacks.
options hash as the last parameter.
* callbacks - An array of callbacks, with an optional
==== Parameters
the normalization across several methods that use it.
then call the block with each callback. This allows us to abstract
Take callback names and an optional callback proc, normalize them,
def _insert_callbacks(callbacks, block) options = callbacks.last.is_a?(Hash) ? callbacks.pop : {} _normalize_callback_options(options) callbacks.push(block) if block callbacks.each do |callback| yield callback, options end end
def _normalize_callback_options(options)
* only - The callback should be run only for this action
==== Options
a Rails process.
proc is only evaluated once per action for the lifetime of
:if => proc {|c| c.action_name == "index" }, but that the
The basic idea is that :only => :index gets converted to
primitive form (:per_key) used by ActiveSupport::Callbacks.
If :only or :except are used, convert the options into the
def _normalize_callback_options(options) if only = options[:only] only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ") options[:per_key] = {:if => only} end if except = options[:except] except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ") options[:per_key] = {:unless => except} end end
def skip_filter(*names, &blk)
impossible to skip a callback defined using an anonymous proc
callbacks. Note that skipping uses Ruby equality, so it's
* names - A list of valid names that could be used for
==== Parameters
Skip before, after, and around filters matching any of the names
def skip_filter(*names, &blk) skip_before_filter(*names) skip_after_filter(*names) skip_around_filter(*names) end