Class: RiveScript::SessionManager
- Inherits:
-
Object
- Object
- RiveScript::SessionManager
- 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
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
Instance Method Summary collapse
-
#default_session ⇒ Object
Default session variables for a new user.
-
#freeze(username) ⇒ Object
Make a snapshot of the user's variables so that they can be restored later via thaw.
-
#get(username, key) ⇒ Object
Retrieve a stored variable for a user.
-
#get_all ⇒ Object
Retrieve all variables about all users.
-
#get_any(username) ⇒ Object
Retrieve all stored user variables for
username. -
#reset(username) ⇒ Object
Reset all variables stored about a particular user.
-
#reset_all ⇒ Object
Reset all data about all users.
-
#set(username, data) ⇒ Object
Set user variables for
username. -
#thaw(username, action = "thaw") ⇒ Object
Restore the frozen snapshot of variables for a user.
Instance Method Details
#default_session ⇒ Object
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.
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.
26 27 28 |
# File 'lib/rivescript/sessions.rb', line 26 def get(username, key) raise NotImplementedError end |
#get_all ⇒ Object
Retrieve all variables about all users.
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.
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.
42 43 44 |
# File 'lib/rivescript/sessions.rb', line 42 def reset(username) raise NotImplementedError end |
#reset_all ⇒ Object
Reset all data about all users.
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.
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".
59 60 61 |
# File 'lib/rivescript/sessions.rb', line 59 def thaw(username, action = "thaw") raise NotImplementedError end |