Allow sweepers to be created solely for expiring after controller actions, not model changes [DHH] Added assigns method to ActionController::Caching::Sweeper to easily access instance variables on the controller [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7128 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson
2007-06-26 20:45:41 +00:00
parent a72fe4ea45
commit 08d23d5375
3 changed files with 16 additions and 3 deletions

View File

@@ -140,7 +140,11 @@ module ActiveRecord
# The class observed by default is inferred from the observer's class name:
# assert_equal [Person], PersonObserver.observed_class
def observed_class
name.scan(/(.*)Observer/)[0][0].constantize
if observed_class_name = name.scan(/(.*)Observer/)[0]
observed_class_name[0].constantize
else
nil
end
end
end
@@ -163,11 +167,11 @@ module ActiveRecord
protected
def observed_classes
Set.new([self.class.observed_class].flatten)
Set.new([self.class.observed_class].compact.flatten)
end
def observed_subclasses
observed_classes.sum(&:subclasses)
observed_classes.collect(&:subclasses).flatten
end
def add_observer!(klass)