Class: Bezel::Session

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

Instance Method Summary collapse

Constructor Details

#initialize(req) ⇒ Session

Returns a new instance of Session.



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

def initialize(req)
  if req.cookies['_']
    @cookie =  JSON.parse(req.cookies['_bezel'])
  else
    @cookie = {}
  end
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  @cookie[key]
end

#[]=(key, val) ⇒ Object



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

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

#store_session(res) ⇒ Object



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

def store_session(res)
  json_cookie = @cookie.to_json
  res.set_cookie('_bezel', value: json_cookie, path: '/' )
end