1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-09-03 09:46:17 +03:00

Make #session raise error when store is not configured

Add more explanation on sessions in readme
Этот коммит содержится в:
Max Melentiev
2017-10-06 11:05:25 +03:00
родитель df7039326d
Коммит ef4f3caa5f
3 изменённых файлов: 85 добавлений и 12 удалений

Просмотреть файл

@@ -8,19 +8,26 @@ module Telegram
module Session
extend ActiveSupport::Concern
module ClassMethods
# Builds session with given key and optional store (default to session_store).
# This way it's easier to define multiple custom sessions,
# ex. one for group chat and one for user.
def build_session(key, store = session_store)
raise 'session_store is not configured' unless store
key ? SessionHash.new(store, key) : NullSessionHash.new
end
end
def process_action(*)
super
ensure
session.commit
session.commit if @_session
end
protected
def session
@_session ||= begin
key = session_key
key ? SessionHash.new(self.class.session_store, key) : NullSessionHash.new
end
@_session ||= self.class.build_session(session_key)
end
def session_key