Class: Session

Inherits:
Object show all
Defined in:
lib/laris/controller/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(req) ⇒ Session

Returns a new instance of Session.



4
5
6
7
# File 'lib/laris/controller/session.rb', line 4

def initialize(req)
  raw_cookie = req.cookies['_laris_session']
  @cookie = raw_cookie ? JSON.parse(raw_cookie) : {}
end

Instance Attribute Details

Returns the value of attribute cookie.



2
3
4
# File 'lib/laris/controller/session.rb', line 2

def cookie
  @cookie
end

Instance Method Details

#[](key) ⇒ Object



9
10
11
# File 'lib/laris/controller/session.rb', line 9

def [](key)
  cookie[key]
end

#[]=(key, val) ⇒ Object



13
14
15
# File 'lib/laris/controller/session.rb', line 13

def []=(key, val)
  cookie[key] = val
end

#store_session(res) ⇒ Object



17
18
19
20
# File 'lib/laris/controller/session.rb', line 17

def store_session(res)
  new_cookie = { path: '/', value: cookie.to_json }
  res.set_cookie('_laris_session', new_cookie)
end