Class: Flash

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(req) ⇒ Flash

Returns a new instance of Flash.



7
8
9
10
11
12
13
14
15
16
# File 'lib/scaffold/lib/controller/cookies/flash.rb', line 7

def initialize(req)
  cookie = req.cookies['_rails_lite_app_flash']
  if cookie
    @now = FlashNow.new(JSON.parse(cookie))
  else
    @now = FlashNow.new
  end
  
  @cookie_data = {}
end

Instance Attribute Details

#nowObject (readonly)

Returns the value of attribute now.



5
6
7
# File 'lib/scaffold/lib/controller/cookies/flash.rb', line 5

def now
  @now
end

Instance Method Details

#[](key) ⇒ Object



18
19
20
# File 'lib/scaffold/lib/controller/cookies/flash.rb', line 18

def [](key)
  now[key.to_s] || cookie_data[key.to_s]
end

#[]=(key, val) ⇒ Object



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

def []=(key, val)
  cookie_data[key.to_s] = val
end

#store_flash(res) ⇒ Object



26
27
28
29
# File 'lib/scaffold/lib/controller/cookies/flash.rb', line 26

def store_flash(res)
  cookie = { path: '/', value: JSON.generate(cookie_data) }
  res.set_cookie('_rails_lite_app_flash', cookie)
end