Class: Bezel::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.



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

def initialize(req)
  if req.cookies['_bezel_flash']
    @flash = JSON.parse(req.cookies['_bezel_flash'])
  else
    @flash = {}
  end
  @flash_now = {}
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  return @flash_now[key] if @flash_now[key]
  @flash[key.to_s]
end

#[]=(key, val) ⇒ Object



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

def []=(key,val)
  @flash[key] = val
end

#nowObject



26
27
28
# File 'lib/flash.rb', line 26

def now
  @flash_now
end

#store_flash(res) ⇒ Object



22
23
24
# File 'lib/flash.rb', line 22

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