Class: Telegram::Bot::UpdatesController::Session::SessionHash
- Inherits:
-
Rack::Session::Abstract::SessionHash
- Object
- Rack::Session::Abstract::SessionHash
- Telegram::Bot::UpdatesController::Session::SessionHash
- Defined in:
- lib/telegram/bot/updates_controller/session.rb
Overview
Rack::Session::Abstract::SessionHash is taken to provide lazy loading. All methods that access store are overriden to support ActiveSupport::Cache::Store stores.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #commit ⇒ Object
- #destroy ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(store, id) ⇒ SessionHash
constructor
A new instance of SessionHash.
- #load! ⇒ Object
Constructor Details
#initialize(store, id) ⇒ SessionHash
Returns a new instance of SessionHash.
44 45 46 47 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 44 def initialize(store, id) @store = store @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
42 43 44 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 42 def id @id end |
Instance Method Details
#commit ⇒ Object
66 67 68 69 70 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 66 def commit return unless loaded? data = to_hash.delete_if { |_, v| v.nil? } @store.write(id, data) end |
#destroy ⇒ Object
49 50 51 52 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 49 def destroy clear @store.delete(id) end |
#exists? ⇒ Boolean
54 55 56 57 58 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 54 def exists? return @exists if defined?(@exists) @data = {} @exists = @store.exist? id end |
#load! ⇒ Object
60 61 62 63 64 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 60 def load! session = @store.read(id) @data = session ? stringify_keys(session) : {} @loaded = true end |