Class: Telegram::Bot::UpdatesController::Session::SessionHash

Inherits:
Rack::Session::Abstract::SessionHash
  • Object
show all
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

NullSessionHash

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idObject (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

#commitObject



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

#destroyObject



52
53
54
55
# File 'lib/telegram/bot/updates_controller/session.rb', line 52

def destroy
  clear
  @store.delete(id)
end

#exists?Boolean

Returns:

  • (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