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.
37 38 39 40 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 37 def initialize(store, id) @store = store @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
35 36 37 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 35 def id @id end |
Instance Method Details
#commit ⇒ Object
59 60 61 62 63 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 59 def commit return unless loaded? data = to_hash.delete_if { |_, v| v.nil? } @store.write(id, data) end |
#destroy ⇒ Object
42 43 44 45 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 42 def destroy clear @store.delete(id) end |
#exists? ⇒ Boolean
47 48 49 50 51 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 47 def exists? return @exists if defined?(@exists) @data = {} @exists = @store.exist? id end |
#load! ⇒ Object
53 54 55 56 57 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 53 def load! session = @store.read(id) @data = session ? stringify_keys(session) : {} @loaded = true end |