Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract ActionController::Caching::Sweeper into separate file [#1977

…state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit 5ac05f15c6d8f496c4e152dbbecd8ccb12041770 1 parent 49169f7
@wincent wincent authored josh committed
View
2  actionpack/lib/action_controller/caching.rb
@@ -27,7 +27,7 @@ module Caching
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:
View
46 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
View
42 actionpack/lib/action_controller/caching/sweeping.rb
@@ -51,47 +51,5 @@ def cache_sweeper(*sweepers)
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
Please sign in to comment.
Something went wrong with that request. Please try again.