Class: TelegramWorkflow::Session
- Inherits:
-
Object
- Object
- TelegramWorkflow::Session
- Defined in:
- lib/telegram_workflow/session.rb
Defined Under Namespace
Classes: NullSession
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #dump ⇒ Object
-
#flash ⇒ Object
this is a temporary per-action store.
-
#initialize(params) ⇒ Session
constructor
A new instance of Session.
- #read(key) ⇒ Object
- #reset_flash ⇒ Object
-
#user_session ⇒ Object
this is a user space to store some session data separately from the gem session.
- #write(key, value) ⇒ Object
Constructor Details
#initialize(params) ⇒ Session
Returns a new instance of Session.
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/telegram_workflow/session.rb', line 2 def initialize(params) @session_id = params.user_id @store = TelegramWorkflow.config.session_store @session = if serialized_session = @store.read(@session_id) Marshal.load(serialized_session) else {} end end |
Instance Method Details
#clear ⇒ Object
25 26 27 |
# File 'lib/telegram_workflow/session.rb', line 25 def clear @session.clear end |
#delete(key) ⇒ Object
21 22 23 |
# File 'lib/telegram_workflow/session.rb', line 21 def delete(key) @session.delete(key) end |
#dump ⇒ Object
29 30 31 |
# File 'lib/telegram_workflow/session.rb', line 29 def dump @session_id && @store.write(@session_id, Marshal.dump(@session)) end |
#flash ⇒ Object
this is a temporary per-action store
41 42 43 44 45 |
# File 'lib/telegram_workflow/session.rb', line 41 def flash @session_id ? @session[:flash] ||= {} : NullSession.new end |
#read(key) ⇒ Object
13 14 15 |
# File 'lib/telegram_workflow/session.rb', line 13 def read(key) @session[key] end |
#reset_flash ⇒ Object
47 48 49 |
# File 'lib/telegram_workflow/session.rb', line 47 def reset_flash flash.clear end |
#user_session ⇒ Object
this is a user space to store some session data separately from the gem session
34 35 36 37 38 |
# File 'lib/telegram_workflow/session.rb', line 34 def user_session @session_id ? @session[:user_session] ||= {} : NullSession.new end |
#write(key, value) ⇒ Object
17 18 19 |
# File 'lib/telegram_workflow/session.rb', line 17 def write(key, value) @session[key] = value end |