Class: TelegramOnSteroids::Session
- Inherits:
-
Object
- Object
- TelegramOnSteroids::Session
- Defined in:
- lib/telegram_on_steroids/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 |
# File 'lib/telegram_on_steroids/session.rb', line 2 def initialize(params) @session_id = [params.user_id, params.chat_id].join('.') @store = TelegramOnSteroids.config.session_store @session = if serialized_session = @store.read(@session_id) Oj.load(serialized_session) else {} end end |
Instance Method Details
#clear ⇒ Object
24 25 26 |
# File 'lib/telegram_on_steroids/session.rb', line 24 def clear @session.clear end |
#delete(key) ⇒ Object
20 21 22 |
# File 'lib/telegram_on_steroids/session.rb', line 20 def delete(key) @session.delete(key) end |
#dump ⇒ Object
28 29 30 |
# File 'lib/telegram_on_steroids/session.rb', line 28 def dump @session_id && @store.write(@session_id, Oj.dump(@session)) end |
#flash ⇒ Object
this is a temporary per-action store
40 41 42 43 44 |
# File 'lib/telegram_on_steroids/session.rb', line 40 def flash @session_id ? @session[:flash] ||= {} : NullSession.new end |
#read(key) ⇒ Object
12 13 14 |
# File 'lib/telegram_on_steroids/session.rb', line 12 def read(key) @session[key] end |
#reset_flash ⇒ Object
46 47 48 |
# File 'lib/telegram_on_steroids/session.rb', line 46 def reset_flash flash.clear end |
#user_session ⇒ Object
this is a user space to store some session data separately from the gem session
33 34 35 36 37 |
# File 'lib/telegram_on_steroids/session.rb', line 33 def user_session @session_id ? @session[:user_session] ||= {} : NullSession.new end |
#write(key, value) ⇒ Object
16 17 18 |
# File 'lib/telegram_on_steroids/session.rb', line 16 def write(key, value) @session[key] = value end |