abstract class Tourmaline::Persistence
- Tourmaline::Persistence
- Reference
- Object
Overview
Abstract class meant to be a base for other persistence classes. The point of persistence (currently) is to allow Users and Chats to be saved as they're seen, and then provide a way for both to be fetched by either id or username.
Example:
bot = MyBot.new(API_KEY, persistence: Tourmaline::JsonPersistence.new)
# ... do some things
if user = bot.persistence.get_user?("foobar")
pp user
end
Direct Known Subclasses
Defined in:
tourmaline/persistence.crConstructors
Instance Method Summary
-
#chat_exists?(chat_id : Int) : Bool
Returns true if the chat with the provided
chat_idexists. -
#chat_exists?(username : String) : Bool
Returns true if the chat with the provided
usernameexists. -
#cleanup
Gets called upon exit.
-
#get_chat(chat_id : Int) : Chat | Nil
Fetches a chat by
chat_id. -
#get_chat(username : String) : Chat | Nil
Fetches a chat by
username. -
#get_user(user_id : Int) : User | Nil
Fetches a user by
user_id. -
#get_user(username : String) : User | Nil
Fetches a user by
username. -
#handle_update(update : Update)
Takes an
Updateobject, pulls out all uniqueChats andUsers, and uses#update_userand#update_chaton each of them respectively. -
#init
Gets called when the bot is initialized.
-
#update_chat(chat : Chat) : Chat
Create or update the provided
Chat. -
#update_user(user : User) : User
Create or update the provided
User. -
#user_exists?(user_id : Int) : Bool
Returns true if the user with the provided
user_idexists. -
#user_exists?(username : String) : Bool
Returns true if the user with the provided
usernameexists.
Constructor Detail
Instance Method Detail
Returns true if the chat with the provided chat_id exists.
Returns true if the chat with the provided username exists.
Fetches a chat by chat_id. Returns nil if the chat is not found.
Fetches a chat by username. Returns nil if the chat is not found.
Fetches a user by user_id. Returns nil if the user is not found.
Fetches a user by username. Returns nil if the user is not found.
Takes an Update object, pulls out all unique Chats and Users,
and uses #update_user and #update_chat on each of them respectively.
Gets called when the bot is initialized. This can be used for setup if you need access to the bot instance.
Returns true if the user with the provided user_id exists.
Returns true if the user with the provided username exists.