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

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

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

#commitObject



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

#destroyObject



49
50
51
52
# File 'lib/telegram/bot/updates_controller/session.rb', line 49

def destroy
  clear
  @store.delete(id)
end

#exists?Boolean

Returns:

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