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
rubocop:disable Lint/MissingSuper.
- #load! ⇒ Object
Constructor Details
#initialize(store, id) ⇒ SessionHash
rubocop:disable Lint/MissingSuper
47 48 49 50 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 47 def initialize(store, id) # rubocop:disable Lint/MissingSuper @store = store @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
45 46 47 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 45 def id @id end |
Instance Method Details
#commit ⇒ Object
69 70 71 72 73 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 69 def commit return unless loaded? data = to_hash.compact @store.write(id, data) end |
#destroy ⇒ Object
52 53 54 55 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 52 def destroy clear @store.delete(id) end |
#exists? ⇒ Boolean
57 58 59 60 61 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 57 def exists? return @exists if defined?(@exists) @data = {} @exists = @store.exist? id end |
#load! ⇒ Object
63 64 65 66 67 |
# File 'lib/telegram/bot/updates_controller/session.rb', line 63 def load! session = @store.read(id) @data = session ? stringify_keys(session) : {} @loaded = true end |