class Flash
Attributes
Public Class Methods
new(req)
click to toggle source
# File lib/laris/controller/flash.rb, line 4 def initialize(req) raw_cookie = req.cookies['_laris_flash'] @stale_cookie = raw_cookie ? JSON.parse(raw_cookie) : {} @fresh_cookie = {} @persistent = true end
Public Instance Methods
[](key)
click to toggle source
# File lib/laris/controller/flash.rb, line 20 def [](key) fresh_cookie.merge(stale_cookie)[key] end
[]=(key, val)
click to toggle source
# File lib/laris/controller/flash.rb, line 24 def []=(key, val) if persistent? fresh_cookie[key] = val else stale_cookie[key] = val end @persistent = true val end
now()
click to toggle source
# File lib/laris/controller/flash.rb, line 15 def now @persistent = false self end
persistent?()
click to toggle source
# File lib/laris/controller/flash.rb, line 11 def persistent? @persistent end
store_flash(res)
click to toggle source
# File lib/laris/controller/flash.rb, line 35 def store_flash(res) new_cookie = { path: '/', value: fresh_cookie.to_json } res.set_cookie('_laris_flash', new_cookie) end