Class: RiveScript::SessionManager

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

Overview

SessionManager is the interface for session managers that store user variables for RiveScript. User variables include those set with the tag or set_uservar, as well as recent reply history and private internal state variables.

The default session manager keeps the variables in memory. To use a custom backend, subclass SessionManager and pass an instance to RiveScript.new(session_manager: manager).

Direct Known Subclasses

MemorySessionManager, NullSessionManager

Instance Method Summary collapse

Instance Method Details

#default_sessionObject

Default session variables for a new user.



64
65
66
# File 'lib/rivescript/sessions.rb', line 64

def default_session
  { "topic" => "random" }
end

#freeze(username) ⇒ Object

Make a snapshot of the user's variables so that they can be restored later via thaw.

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/rivescript/sessions.rb', line 53

def freeze(username)
  raise NotImplementedError
end

#get(username, key) ⇒ Object

Retrieve a stored variable for a user. Returns nil if the user does not exist, or the string "undefined" if the user exists but the key does not.

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/rivescript/sessions.rb', line 26

def get(username, key)
  raise NotImplementedError
end

#get_allObject

Retrieve all variables about all users.

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/rivescript/sessions.rb', line 37

def get_all
  raise NotImplementedError
end

#get_any(username) ⇒ Object

Retrieve all stored user variables for username. Returns nil if the user does not exist.

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/rivescript/sessions.rb', line 32

def get_any(username)
  raise NotImplementedError
end

#reset(username) ⇒ Object

Reset all variables stored about a particular user.

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/rivescript/sessions.rb', line 42

def reset(username)
  raise NotImplementedError
end

#reset_allObject

Reset all data about all users.

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/rivescript/sessions.rb', line 47

def reset_all
  raise NotImplementedError
end

#set(username, data) ⇒ Object

Set user variables for username. data is a Hash of key/value pairs. A value of nil for a variable means it should be deleted.

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/rivescript/sessions.rb', line 19

def set(username, data)
  raise NotImplementedError
end

#thaw(username, action = "thaw") ⇒ Object

Restore the frozen snapshot of variables for a user. action may be "thaw" (default), "discard", or "keep".

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/rivescript/sessions.rb', line 59

def thaw(username, action = "thaw")
  raise NotImplementedError
end