Class: Flash

Inherits:
Object
  • Object
show all
Defined in:
lib/flash.rb

Instance Method Summary collapse

Constructor Details

#initialize(req) ⇒ Flash

Returns a new instance of Flash.



5
6
7
8
9
10
# File 'lib/flash.rb', line 5

def initialize(req)
  cookie = req.cookies['flash']

  @now = cookie ? JSON.parse(cookie) : {}
  @flash = {}
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/flash.rb', line 16

def [](key)
  @now[key.to_s] || @flash[key.to_s]
end

#[]=(key, value) ⇒ Object



20
21
22
# File 'lib/flash.rb', line 20

def []=(key, value)
  @flash[key.to_s] = value
end

#store_flash(res) ⇒ Object



12
13
14
# File 'lib/flash.rb', line 12

def store_flash(res)
  res.set_cookie('flash', { path: '/', value: @flash.to_json })
end