Class: KStor::Session

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

Overview

A user session in memory.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sid, user, secret_key) ⇒ KStor::Session

Create a new user session.

Parameters:



21
22
23
24
25
26
27
# File 'lib/kstor/session.rb', line 21

def initialize(sid, user, secret_key)
  @id = sid
  @user = user
  @secret_key = secret_key
  @created_at = Time.now
  @updated_at = Time.now
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



11
12
13
# File 'lib/kstor/session.rb', line 11

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/kstor/session.rb', line 8

def id
  @id
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



10
11
12
# File 'lib/kstor/session.rb', line 10

def secret_key
  @secret_key
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

#userObject (readonly)

Returns the value of attribute user.



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

def user
  @user
end

Class Method Details

.create(user, secret_key) ⇒ KStor::Session

Create a new session for a user.

Parameters:

Returns:



43
44
45
46
# File 'lib/kstor/session.rb', line 43

def self.create(user, secret_key)
  sid = SecureRandom.urlsafe_base64(16)
  new(sid, user, secret_key)
end

Instance Method Details

#updateKStor::Session

Update access time, for idle sessions weeding.

Returns:



32
33
34
35
# File 'lib/kstor/session.rb', line 32

def update
  @updated_at = Time.now
  self
end