module ActionController::Caching class Sweeper < ActiveRecord::Observer #:nodoc: attr_accessor :controller attr_accessor :controller_stack # ActiveRecord::Observer will mark this class as reloadable even though it should not be. # However, subclasses of ActionController::Caching::Sweeper should be Reloadable include Reloadable::Deprecated def initialize self.controller_stack = [] super end def before(c) self.controller_stack << c self.controller = c callback(:before) end def after(c) callback(:after) # Clean up, so that the controller can be collected after this request self.controller_stack.pop self.controller = self.controller_stack.last end private def callback(timing) controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}" action_callback_method_name = "#{controller_callback_method_name}_#{controller.action_name}" send(controller_callback_method_name) if respond_to?(controller_callback_method_name) send(action_callback_method_name) if respond_to?(action_callback_method_name) end def method_missing(method, *arguments) return if @controller.nil? @controller.send(method, *arguments) end end end