2009-02-27 23:11:02 +00:00
|
|
|
module AbstractController
|
|
|
|
module Callbacks
|
2009-05-07 15:38:57 +00:00
|
|
|
extend ActiveSupport::DependencyModule
|
|
|
|
|
|
|
|
depends_on ActiveSupport::NewCallbacks
|
|
|
|
|
|
|
|
included do
|
2009-05-12 17:53:00 +00:00
|
|
|
define_callbacks :process_action, "response_body"
|
2009-02-28 03:25:45 +00:00
|
|
|
end
|
2009-05-07 15:38:57 +00:00
|
|
|
|
2009-05-15 22:57:12 +00:00
|
|
|
def process_action(method_name)
|
|
|
|
_run_process_action_callbacks(method_name) do
|
2009-02-28 03:25:45 +00:00
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
2009-05-28 14:49:02 +00:00
|
|
|
|
2009-02-28 03:25:45 +00:00
|
|
|
module ClassMethods
|
|
|
|
def _normalize_callback_options(options)
|
|
|
|
if only = options[:only]
|
2009-05-01 23:01:37 +00:00
|
|
|
only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ")
|
2009-02-28 03:25:45 +00:00
|
|
|
options[:per_key] = {:if => only}
|
|
|
|
end
|
|
|
|
if except = options[:except]
|
2009-05-28 14:49:02 +00:00
|
|
|
except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ")
|
2009-02-28 03:25:45 +00:00
|
|
|
options[:per_key] = {:unless => except}
|
|
|
|
end
|
|
|
|
end
|
2009-05-28 14:49:02 +00:00
|
|
|
|
2009-02-28 03:25:45 +00:00
|
|
|
[:before, :after, :around].each do |filter|
|
|
|
|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
|
|
|
def #{filter}_filter(*names, &blk)
|
|
|
|
options = names.last.is_a?(Hash) ? names.pop : {}
|
|
|
|
_normalize_callback_options(options)
|
|
|
|
names.push(blk) if block_given?
|
|
|
|
names.each do |name|
|
|
|
|
process_action_callback(:#{filter}, name, options)
|
|
|
|
end
|
|
|
|
end
|
2009-05-23 08:30:25 +00:00
|
|
|
|
2009-05-27 18:02:13 +00:00
|
|
|
def prepend_#{filter}_filter(*names, &blk)
|
|
|
|
options = names.last.is_a?(Hash) ? names.pop : {}
|
|
|
|
_normalize_callback_options(options)
|
|
|
|
names.push(blk) if block_given?
|
|
|
|
names.each do |name|
|
|
|
|
process_action_callback(:#{filter}, name, options.merge(:prepend => true))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-05-23 08:30:25 +00:00
|
|
|
def skip_#{filter}_filter(*names, &blk)
|
|
|
|
options = names.last.is_a?(Hash) ? names.pop : {}
|
|
|
|
_normalize_callback_options(options)
|
|
|
|
names.push(blk) if block_given?
|
|
|
|
names.each do |name|
|
|
|
|
skip_process_action_callback(:#{filter}, name, options)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :append_#{filter}_filter, :#{filter}_filter
|
2009-02-28 03:25:45 +00:00
|
|
|
RUBY_EVAL
|
|
|
|
end
|
|
|
|
end
|
2009-02-27 23:11:02 +00:00
|
|
|
end
|
2009-05-28 14:49:02 +00:00
|
|
|
end
|