class SessionRouter

Public Class Methods

new(client) click to toggle source
Calls superclass method
# File lib/shot_mvc/session_router.rb, line 30
def initialize(client)
        super(client)

        client.on 'session_key' do |key|
                create_session_folder unless Dir.exists? 'app/sessions'
                create_session_file key unless File.exists? "app/sessions/#{key}.json"

                client.config[:session_key] = key
                client.config[:session] = JSON.parse File.read "app/sessions/#{key}.json"

                client.emit 'session_ready'
        end

        client.on 'request_session_key' do
                session_key = SecureRandom.uuid
                client.emit 'assign_session_key', :key => session_key, :session_hash => client.config['server']['Security']['SessionHash']

                create_session_folder unless Dir.exists? 'app/sessions'
                create_session_file session_key unless File.exists? "app/sessions/#{session_key}.json"

                client.config[:session_key] = session_key
                client.config[:session] = JSON.parse File.read "app/sessions/#{session_key}.json"

                client.emit 'session_ready'
        end

        client.emit 'provide_session_key', client.config['server']['Security']['SessionHash']
end

Private Instance Methods

create_session_file(key) click to toggle source
# File lib/shot_mvc/session_router.rb, line 65
def create_session_file(key)
        File.write "app/sessions/#{key}.json", '{}'
end
create_session_folder() click to toggle source
# File lib/shot_mvc/session_router.rb, line 61
def create_session_folder
        Dir.mkdir 'app/sessions'
end