2009-02-27 18:11:02 -05:00
|
|
|
module AbstractController
|
|
|
|
module Callbacks
|
2009-05-28 12:35:36 -04:00
|
|
|
extend ActiveSupport::Concern
|
2009-05-07 11:38:57 -04:00
|
|
|
|
2009-05-29 18:03:23 -04:00
|
|
|
include ActiveSupport::NewCallbacks
|
2009-05-07 11:38:57 -04:00
|
|
|
|
|
|
|
included do
|
2009-05-12 13:53:00 -04:00
|
|
|
define_callbacks :process_action, "response_body"
|
2009-02-27 22:25:45 -05:00
|
|
|
end
|
2009-05-07 11:38:57 -04:00
|
|
|
|
2009-05-15 18:57:12 -04:00
|
|
|
def process_action(method_name)
|
|
|
|
_run_process_action_callbacks(method_name) do
|
2009-02-27 22:25:45 -05:00
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-02-27 22:25:45 -05:00
|
|
|
module ClassMethods
|
|
|
|
def _normalize_callback_options(options)
|
|
|
|
if only = options[:only]
|
2009-05-01 19:01:37 -04:00
|
|
|
only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ")
|
2009-02-27 22:25:45 -05:00
|
|
|
options[:per_key] = {:if => only}
|
|
|
|
end
|
|
|
|
if except = options[:except]
|
2009-05-28 10:49:02 -04:00
|
|
|
except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ")
|
2009-02-27 22:25:45 -05:00
|
|
|
options[:per_key] = {:unless => except}
|
|
|
|
end
|
|
|
|
end
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-06-01 18:40:11 -04:00
|
|
|
def skip_filter(*names, &blk)
|
|
|
|
skip_before_filter(*names, &blk)
|
|
|
|
skip_after_filter(*names, &blk)
|
|
|
|
skip_around_filter(*names, &blk)
|
|
|
|
end
|
|
|
|
|
2009-06-02 22:00:59 -04:00
|
|
|
def _insert_callbacks(names, block)
|
|
|
|
options = names.last.is_a?(Hash) ? names.pop : {}
|
|
|
|
_normalize_callback_options(options)
|
|
|
|
names.push(block) if block
|
|
|
|
names.each do |name|
|
|
|
|
yield name, options
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-27 22:25:45 -05:00
|
|
|
[:before, :after, :around].each do |filter|
|
|
|
|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
|
|
|
def #{filter}_filter(*names, &blk)
|
2009-06-02 22:00:59 -04:00
|
|
|
_insert_callbacks(names, blk) do |name, options|
|
|
|
|
_set_callback(:process_action, :#{filter}, name, options)
|
2009-02-27 22:25:45 -05:00
|
|
|
end
|
|
|
|
end
|
2009-05-23 04:30:25 -04:00
|
|
|
|
2009-05-27 14:02:13 -04:00
|
|
|
def prepend_#{filter}_filter(*names, &blk)
|
2009-06-02 22:00:59 -04:00
|
|
|
_insert_callbacks(names, blk) do |name, options|
|
|
|
|
_set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true))
|
2009-05-27 14:02:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-05-23 04:30:25 -04:00
|
|
|
def skip_#{filter}_filter(*names, &blk)
|
2009-06-02 22:00:59 -04:00
|
|
|
_insert_callbacks(names, blk) do |name, options|
|
|
|
|
_skip_callback(:process_action, :#{filter}, name, options)
|
2009-05-23 04:30:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :append_#{filter}_filter, :#{filter}_filter
|
2009-02-27 22:25:45 -05:00
|
|
|
RUBY_EVAL
|
|
|
|
end
|
|
|
|
end
|
2009-02-27 18:11:02 -05:00
|
|
|
end
|
2009-05-28 10:49:02 -04:00
|
|
|
end
|