class TelegramWorkflow::Session

Public Class Methods

new(params) click to toggle source
# File lib/telegram_workflow/session.rb, line 2
def initialize(params)
  @session_id = params.user_id
  @store = TelegramWorkflow.config.session_store

  @session = if serialized_session = @store.read(@session_id)
    Marshal.load(serialized_session)
  else
    {}
  end
end

Public Instance Methods

clear() click to toggle source
# File lib/telegram_workflow/session.rb, line 25
def clear
  @session.clear
end
delete(key) click to toggle source
# File lib/telegram_workflow/session.rb, line 21
def delete(key)
  @session.delete(key)
end
dump() click to toggle source
# File lib/telegram_workflow/session.rb, line 29
def dump
  @session_id && @store.write(@session_id, Marshal.dump(@session))
end
flash() click to toggle source

this is a temporary per-action store

# File lib/telegram_workflow/session.rb, line 41
def flash
  @session_id ?
    @session[:flash] ||= {} :
    NullSession.new
end
read(key) click to toggle source
# File lib/telegram_workflow/session.rb, line 13
def read(key)
  @session[key]
end
reset_flash() click to toggle source
# File lib/telegram_workflow/session.rb, line 47
def reset_flash
  flash.clear
end
user_session() click to toggle source

this is a user space to store some session data separately from the gem session

# File lib/telegram_workflow/session.rb, line 34
def user_session
  @session_id ?
    @session[:user_session] ||= {} :
    NullSession.new
end
write(key, value) click to toggle source
# File lib/telegram_workflow/session.rb, line 17
def write(key, value)
  @session[key] = value
end