Module: TelegramBotEngine::Registry
- Defined in:
- lib/telegram_bot_engine/registry.rb
Overview
Resolves and caches a Telegram::Bot::Client per Bot record, keyed by bot id (docs/0001 §2 cap 2, §3.2). This fills telegram-bot’s gap: ‘Telegram.bots` is boot-memoized (`@bots ||=`) and not built for runtime hot-add or token rotation. We resolve a fresh `Telegram::Bot::Client.new(token)` per bot_id rather than leaning on `Telegram.reset_bots`, which is unsafe under concurrency (docs/0001 §9).
Class Method Summary collapse
-
.client_for(bot) ⇒ Object
The client for this bot, built once and cached by bot id.
-
.invalidate(bot) ⇒ Object
Drop a bot’s cached client so the next resolve rebuilds it.
-
.reset! ⇒ Object
Clear the whole cache (test isolation; also safe to call on reload).
Class Method Details
.client_for(bot) ⇒ Object
The client for this bot, built once and cached by bot id.
15 16 17 18 19 |
# File 'lib/telegram_bot_engine/registry.rb', line 15 def client_for(bot) @mutex.synchronize do @clients[bot.id] ||= build_client(bot) end end |
.invalidate(bot) ⇒ Object
Drop a bot’s cached client so the next resolve rebuilds it. Called from Bot#after_save / #after_destroy so token rotation can never serve a stale client.
23 24 25 |
# File 'lib/telegram_bot_engine/registry.rb', line 23 def invalidate(bot) @mutex.synchronize { @clients.delete(bot.id) } end |
.reset! ⇒ Object
Clear the whole cache (test isolation; also safe to call on reload).
28 29 30 |
# File 'lib/telegram_bot_engine/registry.rb', line 28 def reset! @mutex.synchronize { @clients = {} } end |