summaryrefslogtreecommitdiffstats
path: root/lib/zorglub/session.rb
blob: da30deb299a7e52a7a51949a68b3497aefc2effc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: UTF-8 -*-
#
require 'securerandom'
#
module Zorglub
    #
    class Session
        #
        @session_key =  'zorglub.sid'
        @session_data = {}
        class << self
            attr_reader :session_key, :session_data
        end
        #
        def initialize cookies
            @sid = cookies[self.class.session_key]
            @data = self.class.session_data[@sid]||={}
        end
        #
        def exists?
            not @sid.nil?
        end
        #
        def [] idx
            @data[idx]
        end
        #
        def []= idx, v
            @data[idx] = v
        end
        #
    end
    #
end
#
# EOF