Class: Flash

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(req) ⇒ Flash

Returns a new instance of Flash.



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

def initialize(req)
  cookie = req.cookies['_rails_lite_app_flash']
  @now = !cookie.nil? ? JSON.parse(cookie) : {}
  @flash = {}
end

Instance Attribute Details

#nowObject (readonly)

Returns the value of attribute now.



4
5
6
# File 'lib/railz_lite/controllers/flash.rb', line 4

def now
  @now
end

Instance Method Details

#[](key) ⇒ Object



11
12
13
# File 'lib/railz_lite/controllers/flash.rb', line 11

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

#[]=(key, val) ⇒ Object



15
16
17
# File 'lib/railz_lite/controllers/flash.rb', line 15

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

#store_flash(res) ⇒ Object



19
20
21
# File 'lib/railz_lite/controllers/flash.rb', line 19

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