diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-05-26 11:34:02 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-05-26 11:34:02 -0300 |
commit | b3d40546923b194a89be0d9e00758864fa60b9e8 (patch) | |
tree | 8acac475b371d61924c67a439704c82c61968fff /actionpack/lib/action_controller/base/chained/flash.rb | |
parent | aa5512299041efb923cd582fd26009a72b9ec670 (diff) | |
parent | 2f59066470193c6219dfd958fc5d8096a2ddee68 (diff) | |
download | rails-b3d40546923b194a89be0d9e00758864fa60b9e8.tar.gz rails-b3d40546923b194a89be0d9e00758864fa60b9e8.tar.bz2 rails-b3d40546923b194a89be0d9e00758864fa60b9e8.zip |
Merge commit 'rails/master'
Diffstat (limited to 'actionpack/lib/action_controller/base/chained/flash.rb')
-rw-r--r-- | actionpack/lib/action_controller/base/chained/flash.rb | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/actionpack/lib/action_controller/base/chained/flash.rb b/actionpack/lib/action_controller/base/chained/flash.rb index 56ee9c67e2..6bd482d85a 100644 --- a/actionpack/lib/action_controller/base/chained/flash.rb +++ b/actionpack/lib/action_controller/base/chained/flash.rb @@ -26,9 +26,18 @@ module ActionController #:nodoc: # # See docs on the FlashHash class for more details about the flash. module Flash - def self.included(base) - base.class_eval do - include InstanceMethods + extend ActiveSupport::DependencyModule + + # TODO : Remove the defined? check when new base is the main base + depends_on Session if defined?(ActionController::Http) + + included do + # TODO : Remove the defined? check when new base is the main base + if defined?(ActionController::Http) + include InstanceMethodsForNewBase + else + include InstanceMethodsForBase + alias_method_chain :perform_action, :flash alias_method_chain :reset_session, :flash end @@ -135,29 +144,50 @@ module ActionController #:nodoc: end end - module InstanceMethods #:nodoc: + module InstanceMethodsForBase #:nodoc: protected - def perform_action_with_flash - perform_action_without_flash - remove_instance_variable(:@_flash) if defined? @_flash - end - def reset_session_with_flash - reset_session_without_flash - remove_instance_variable(:@_flash) if defined? @_flash - end + def perform_action_with_flash + perform_action_without_flash + remove_instance_variable(:@_flash) if defined?(@_flash) + end - # Access the contents of the flash. Use <tt>flash["notice"]</tt> to - # read a notice you put there or <tt>flash["notice"] = "hello"</tt> - # to put a new one. - def flash #:doc: - unless defined? @_flash - @_flash = session["flash"] ||= FlashHash.new - @_flash.sweep - end + def reset_session_with_flash + reset_session_without_flash + remove_instance_variable(:@_flash) if defined?(@_flash) + end + end - @_flash - end + module InstanceMethodsForNewBase #:nodoc: + protected + + def reset_session + super + remove_flash_instance_variable + end + + def process_action(method_name) + super + remove_flash_instance_variable + end + + def remove_flash_instance_variable + remove_instance_variable(:@_flash) if defined?(@_flash) + end + end + + protected + + # Access the contents of the flash. Use <tt>flash["notice"]</tt> to + # read a notice you put there or <tt>flash["notice"] = "hello"</tt> + # to put a new one. + def flash #:doc: + unless defined?(@_flash) + @_flash = session["flash"] ||= FlashHash.new + @_flash.sweep + end + + @_flash end end end |