aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-02-07 22:50:49 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-02-07 22:50:49 +0000
commit56d0e33037c602e51c30a6184e64a62def6177e0 (patch)
treec7c567498da7ac994003082b00ad9a7d414524bb /actionpack
parent40f67639c814da3b04e234f8734f5afc1ea6a317 (diff)
downloadrails-56d0e33037c602e51c30a6184e64a62def6177e0.tar.gz
rails-56d0e33037c602e51c30a6184e64a62def6177e0.tar.bz2
rails-56d0e33037c602e51c30a6184e64a62def6177e0.zip
Added support for naming concrete classes in sweeper declarations [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8819 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/caching/sweeping.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index b3f23e3f68..8817688392 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added support for naming concrete classes in sweeper declarations [DHH]
+
* Remove ERB trim variables from trace template in case ActionView::Base.erb_trim_mode is changed in the application. #10098 [tpope, kampers]
* Fix typo in form_helper documentation. #10650 [xaviershay, kampers]
diff --git a/actionpack/lib/action_controller/caching/sweeping.rb b/actionpack/lib/action_controller/caching/sweeping.rb
index eda4459cda..40276a118e 100644
--- a/actionpack/lib/action_controller/caching/sweeping.rb
+++ b/actionpack/lib/action_controller/caching/sweeping.rb
@@ -22,6 +22,13 @@ module ActionController #:nodoc:
# end
#
# In the example above, four actions are cached and three actions are responsible for expiring those caches.
+ #
+ # You can also name an explicit class in the declaration of a sweeper, which is needed if the sweeper is in a module:
+ #
+ # class ListsController < ApplicationController
+ # caches_action :index, :show, :public, :feed
+ # cache_sweeper OpenBar::Sweeper, :only => [ :edit, :destroy, :share ]
+ # end
module Sweeping
def self.included(base) #:nodoc:
base.extend(ClassMethods)
@@ -31,9 +38,10 @@ module ActionController #:nodoc:
def cache_sweeper(*sweepers)
return unless perform_caching
configuration = sweepers.extract_options!
+
sweepers.each do |sweeper|
ActiveRecord::Base.observers << sweeper if defined?(ActiveRecord) and defined?(ActiveRecord::Base)
- sweeper_instance = Object.const_get(Inflector.classify(sweeper)).instance
+ sweeper_instance = (sweeper.is_a?(Symbol) ? Object.const_get(Inflector.classify(sweeper)) : sweeper).instance
if sweeper_instance.is_a?(Sweeper)
around_filter(sweeper_instance, :only => configuration[:only])