From 050c3964d8fe8d68c03fff593e3c09b5eae77a46 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 12 Feb 2006 05:51:02 +0000 Subject: Stopped the massive bleeding of concerns into ActionController::Base. Base no longer knows about flash, filters, or components. This may well have introduced some instability, please do test with apps, especially the ones using components. [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3580 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/flash.rb | 72 ++++++++++++++++++------------- 1 file changed, 43 insertions(+), 29 deletions(-) (limited to 'actionpack/lib/action_controller/flash.rb') diff --git a/actionpack/lib/action_controller/flash.rb b/actionpack/lib/action_controller/flash.rb index 6a41aa97a6..383263fe92 100644 --- a/actionpack/lib/action_controller/flash.rb +++ b/actionpack/lib/action_controller/flash.rb @@ -24,7 +24,16 @@ module ActionController #:nodoc: # # See docs on the FlashHash class for more details about the flash. module Flash + def self.included(base) + base.send :include, InstanceMethods + base.class_eval do + alias_method :process_cleanup_without_flash, :process_cleanup + alias_method :process_cleanup, :process_cleanup_with_flash + end + end + + class FlashNow #:nodoc: def initialize flash @flash = flash @@ -52,14 +61,14 @@ module ActionController #:nodoc: super end - def update h #:nodoc: - h.keys.each{|k| discard k } + def update(h) #:nodoc: + h.keys.each{ |k| discard(k) } super end - alias merge! update + alias :merge! :update - def replace h #:nodoc: + def replace(h) #:nodoc: @used = {} super end @@ -124,31 +133,36 @@ module ActionController #:nodoc: end end - - protected - # Access the contents of the flash. Use flash["notice"] to read a notice you put there or - # flash["notice"] = "hello" to put a new one. - # Note that if sessions are disabled only flash.now will work. - def flash #:doc: - @flash ||= - if @parent_controller - @parent_controller.flash - elsif @session.is_a?(Hash) - # @session is a Hash, if sessions are disabled - # we don't put the flash in the session in this case - FlashHash.new - else - # otherwise, @session is a CGI::Session or a TestSession - # so make sure it gets retrieved from/saved to session storage after request processing - @session["flash"] ||= FlashHash.new - end - end - - # deprecated. use flash.keep instead - def keep_flash #:doc: - warn 'keep_flash is deprecated; use flash.keep instead.' - flash.keep + module InstanceMethods + def process_cleanup_with_flash + process_cleanup_without_flash + flash.sweep end + + protected + # Access the contents of the flash. Use flash["notice"] to read a notice you put there or + # flash["notice"] = "hello" to put a new one. + # Note that if sessions are disabled only flash.now will work. + def flash #:doc: + @flash ||= + if @parent_controller + @parent_controller.flash + elsif @session.is_a?(Hash) + # @session is a Hash, if sessions are disabled + # we don't put the flash in the session in this case + FlashHash.new + else + # otherwise, @session is a CGI::Session or a TestSession + # so make sure it gets retrieved from/saved to session storage after request processing + @session["flash"] ||= FlashHash.new + end + end + # deprecated. use flash.keep instead + def keep_flash #:doc: + warn 'keep_flash is deprecated; use flash.keep instead.' + flash.keep + end + end end -end +end \ No newline at end of file -- cgit v1.2.3