Class: Reloj::Session

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

Instance Method Summary collapse

Constructor Details

#initialize(req) ⇒ Session

find the cookie for this app, deserialize into hash



7
8
9
10
11
12
13
14
# File 'lib/reloj/core/session.rb', line 7

def initialize(req)
  req.cookies.each do |cookie|
    if cookie.name == '_rails_lite_app'
      @_rails_lite_app = JSON.parse(cookie.value)
    end
  end
  @_rails_lite_app ||= {}
end

Instance Method Details

#[](key) ⇒ Object

convenience methods



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

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

#[]=(key, val) ⇒ Object



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

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

#store_session(res) ⇒ Object

serialize the hash into json and save in a cookie, add to responses



26
27
28
29
30
# File 'lib/reloj/core/session.rb', line 26

def store_session(res)
  cookie = WEBrick::Cookie.new('_rails_lite_app', @_rails_lite_app.to_json)
  cookie.path = '/'
  res.cookies << cookie
end