From de6b56fbd1b6373056cf2204dc14ebfedcd536b3 Mon Sep 17 00:00:00 2001 From: Wincent Colaiuta Date: Wed, 22 Apr 2009 11:30:35 +0200 Subject: [PATCH] Extract ActionController::Caching::Sweeper into separate file Fixes Lighthouse ticket #1977. Signed-off-by: Wincent Colaiuta --- actionpack/lib/action_controller/caching.rb | 2 +- .../lib/action_controller/caching/sweeper.rb | 46 ++++++++++++++++++++ .../lib/action_controller/caching/sweeping.rb | 42 ------------------ 3 files changed, 47 insertions(+), 43 deletions(-) create mode 100644 actionpack/lib/action_controller/caching/sweeper.rb diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 80d13e2..f686223 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -27,7 +27,7 @@ module ActionController #:nodoc: autoload :Actions, 'action_controller/caching/actions' autoload :Fragments, 'action_controller/caching/fragments' autoload :Pages, 'action_controller/caching/pages' - autoload :Sweeper, 'action_controller/caching/sweeping' + autoload :Sweeper, 'action_controller/caching/sweeper' autoload :Sweeping, 'action_controller/caching/sweeping' def self.included(base) #:nodoc: diff --git a/actionpack/lib/action_controller/caching/sweeper.rb b/actionpack/lib/action_controller/caching/sweeper.rb new file mode 100644 index 0000000..3d5b8d5 --- /dev/null +++ b/actionpack/lib/action_controller/caching/sweeper.rb @@ -0,0 +1,46 @@ +require 'active_record' + +module ActionController #:nodoc: + module Caching + module Sweeping + class Sweeper < ActiveRecord::Observer #:nodoc: + attr_accessor :controller + + def before(controller) + self.controller = controller + callback(:before) if controller.perform_caching + end + + def after(controller) + callback(:after) if controller.perform_caching + # Clean up, so that the controller can be collected after this request + self.controller = nil + end + + protected + # gets the action cache path for the given options. + def action_path_for(options) + ActionController::Caching::Actions::ActionCachePath.path_for(controller, options) + end + + # Retrieve instance variables set in the controller. + def assigns(key) + controller.instance_variable_get("@#{key}") + 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, true) + __send__(action_callback_method_name) if respond_to?(action_callback_method_name, true) + end + + def method_missing(method, *arguments, &block) + return if @controller.nil? + @controller.__send__(method, *arguments, &block) + end + end + end +end diff --git a/actionpack/lib/action_controller/caching/sweeping.rb b/actionpack/lib/action_controller/caching/sweeping.rb index c1be264..9b32002 100644 --- a/actionpack/lib/action_controller/caching/sweeping.rb +++ b/actionpack/lib/action_controller/caching/sweeping.rb @@ -51,47 +51,5 @@ module ActionController #:nodoc: end end end - - if defined?(ActiveRecord) and defined?(ActiveRecord::Observer) - class Sweeper < ActiveRecord::Observer #:nodoc: - attr_accessor :controller - - def before(controller) - self.controller = controller - callback(:before) if controller.perform_caching - end - - def after(controller) - callback(:after) if controller.perform_caching - # Clean up, so that the controller can be collected after this request - self.controller = nil - end - - protected - # gets the action cache path for the given options. - def action_path_for(options) - ActionController::Caching::Actions::ActionCachePath.path_for(controller, options) - end - - # Retrieve instance variables set in the controller. - def assigns(key) - controller.instance_variable_get("@#{key}") - 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, true) - __send__(action_callback_method_name) if respond_to?(action_callback_method_name, true) - end - - def method_missing(method, *arguments, &block) - return if @controller.nil? - @controller.__send__(method, *arguments, &block) - end - end - end end end -- 1.6.2.4