Class: Ramaze::Session::Flash
- Includes:
- Enumerable
- Defined in:
- lib/ramaze/current/session/flash.rb
Overview
The purpose of this class is to act as a unifier of the previous and current flash.
Flash means pairs of keys and values that are held only over one request/response cycle. So you can assign a key/value in the current session and retrieve it in the current and following request.
Please see the FlashHelper for details on the usage as you won’t need to touch this class at all.
Instance Method Summary collapse
-
#[](key) ⇒ Object
flash in your Controller.
-
#[]=(key, value) ⇒ Object
flash = value in your Controller.
-
#combined ⇒ Object
combined key/value pairs of previous and current current keys overshadow the old ones.
-
#current ⇒ Object
the current session.
-
#delete(key) ⇒ Object
Delete a key.
-
#each(&block) ⇒ Object
iterate over the combined session.
-
#empty? ⇒ Boolean
check if combined is empty.
-
#initialize(sess) ⇒ Flash
constructor
A new instance of Flash.
-
#inspect ⇒ Object
Inspects the combined SessionFlash.
-
#previous ⇒ Object
the current session.
Constructor Details
#initialize(sess) ⇒ Flash
Returns a new instance of Flash.
15 16 17 |
# File 'lib/ramaze/current/session/flash.rb', line 15 def initialize sess @session = sess end |
Instance Method Details
#[](key) ⇒ Object
flash in your Controller
41 42 43 |
# File 'lib/ramaze/current/session/flash.rb', line 41 def [](key) combined[key] end |
#[]=(key, value) ⇒ Object
flash = value in your Controller
46 47 48 49 50 |
# File 'lib/ramaze/current/session/flash.rb', line 46 def []=(key, value) prev = session[:FLASH] || {} prev[key] = value session[:FLASH] = prev end |
#combined ⇒ Object
combined key/value pairs of previous and current current keys overshadow the old ones.
36 37 38 |
# File 'lib/ramaze/current/session/flash.rb', line 36 def combined previous.merge(current) end |
#current ⇒ Object
the current session
30 31 32 |
# File 'lib/ramaze/current/session/flash.rb', line 30 def current session[:FLASH] ||= {} end |
#delete(key) ⇒ Object
Delete a key
60 61 62 |
# File 'lib/ramaze/current/session/flash.rb', line 60 def delete(key) current.delete(key) end |
#each(&block) ⇒ Object
iterate over the combined session
20 21 22 |
# File 'lib/ramaze/current/session/flash.rb', line 20 def each(&block) combined.each(&block) end |
#empty? ⇒ Boolean
check if combined is empty
66 67 68 |
# File 'lib/ramaze/current/session/flash.rb', line 66 def empty? combined.empty? end |
#inspect ⇒ Object
Inspects the combined SessionFlash
54 55 56 |
# File 'lib/ramaze/current/session/flash.rb', line 54 def inspect combined.inspect end |