Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow sweepers to be created solely for expiring after controller act…

…ions, 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
  • Loading branch information...
commit 08d23d5375fef67cb3203dfb5e92f41ae87195ee 1 parent a72fe4e
@dhh dhh authored
View
4 actionpack/CHANGELOG
@@ -1,5 +1,9 @@
*SVN*
+* 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]
+
* Give the legacy X-POST_DATA_FORMAT header greater precedence during params parsing for backward compatibility. [Jeremy Kemper]
* Fixed that link_to with an href of # when using :method will not allow for click-through without JavaScript #7037 [stevenbristol/josh]
View
5 actionpack/lib/action_controller/caching.rb
@@ -636,6 +636,11 @@ 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}"
View
10 activerecord/lib/active_record/observer.rb
@@ -140,7 +140,11 @@ def observe(*models)
# 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 @@ def observed_class_inherited(subclass) #:nodoc:
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)
Please sign in to comment.
Something went wrong with that request. Please try again.