diff options
author | José Valim <jose.valim@gmail.com> | 2011-04-19 22:38:51 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-04-19 22:38:51 +0200 |
commit | 2f549b8bbd733ad0563d977e83a9b2a2b6b8e07c (patch) | |
tree | 34ef746c761100bc80d771d559121025532b5b10 /actionpack/lib/action_dispatch | |
parent | 89ed9fbd1917e431e489dc856042d996d0f088c5 (diff) | |
download | rails-2f549b8bbd733ad0563d977e83a9b2a2b6b8e07c.tar.gz rails-2f549b8bbd733ad0563d977e83a9b2a2b6b8e07c.tar.bz2 rails-2f549b8bbd733ad0563d977e83a9b2a2b6b8e07c.zip |
Use initialize_copy! to proper initialize now on clone.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/flash.rb | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/flash.rb b/actionpack/lib/action_dispatch/middleware/flash.rb index c7f7d4d4f0..2adbce031b 100644 --- a/actionpack/lib/action_dispatch/middleware/flash.rb +++ b/actionpack/lib/action_dispatch/middleware/flash.rb @@ -43,6 +43,8 @@ module ActionDispatch KEY = 'action_dispatch.request.flash_hash'.freeze class FlashNow #:nodoc: + attr_accessor :flash + def initialize(flash) @flash = flash end @@ -66,14 +68,6 @@ module ActionDispatch def notice=(message) self[:notice] = message end - - def close!(new_flash) - @flash = new_flash - end - - def closed? - @flash.closed? - end end class FlashHash @@ -86,6 +80,14 @@ module ActionDispatch @now = nil end + def initialize_copy(other) + if other.now_is_loaded? + @now = other.now.dup + @now.flash = self + end + super + end + def []=(k, v) #:nodoc: raise ClosedError, :flash if closed? keep(k) @@ -150,16 +152,12 @@ module ActionDispatch # # Entries set via <tt>now</tt> are accessed the same way as standard entries: <tt>flash['my-key']</tt>. def now - @now = (!@now || @now.closed?) ? FlashNow.new(self) : @now + @now ||= FlashNow.new(self) end attr_reader :closed alias :closed? :closed - - def close! - @closed = true - @now.close!(self) if @now - end + def close!; @closed = true; end # Keeps either the entire current flash or a specific flash entry available for the next action: # @@ -214,7 +212,12 @@ module ActionDispatch self[:notice] = message end - private + protected + + def now_is_loaded? + !!@now + end + # Used internally by the <tt>keep</tt> and <tt>discard</tt> methods # use() # marks the entire flash as used # use('msg') # marks the "msg" entry as used |