Class: Reloj::Flash
- Inherits:
-
Object
- Object
- Reloj::Flash
- Defined in:
- lib/reloj/core/flash.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
-
#initialize(req) ⇒ Flash
constructor
find the cookie for this app deserialize the cookie into a hash.
- #now ⇒ Object
-
#store_flash(res) ⇒ Object
serialize the hash into json and save in a cookie add to the responses cookies.
Constructor Details
#initialize(req) ⇒ Flash
find the cookie for this app deserialize the cookie into a hash
8 9 10 11 12 13 14 15 16 |
# File 'lib/reloj/core/flash.rb', line 8 def initialize(req) req..each do || if .name == '_flash' @_old_flash = JSON.parse(.value) end end @_old_flash ||= {} @_new_flash ||= {} end |
Instance Method Details
#[](key) ⇒ Object
18 19 20 |
# File 'lib/reloj/core/flash.rb', line 18 def [](key) @_old_flash[key] || @_new_flash[key] end |
#[]=(key, val) ⇒ Object
22 23 24 |
# File 'lib/reloj/core/flash.rb', line 22 def []=(key, val) @_new_flash[key] = val end |
#now ⇒ Object
26 27 28 |
# File 'lib/reloj/core/flash.rb', line 26 def now @_old_flash end |
#store_flash(res) ⇒ Object
serialize the hash into json and save in a cookie add to the responses cookies
32 33 34 35 36 |
# File 'lib/reloj/core/flash.rb', line 32 def store_flash(res) = WEBrick::Cookie.new('_flash', @_new_flash.to_json) .path = '/' res. << end |