Sha256: cbbca29aeb9d80fbf8e467836c10f83c52ddd9282c4e0e259378b7fcdf28ca13
Contents?: true
Size: 1.79 KB
Versions: 3
Compression:
Stored size: 1.79 KB
Contents
require 'active_support/core_ext/hash/keys' require 'active_support/core_ext/hash/transform_values' module Telegram module Bot module ConfigMethods # Overwrite config. attr_writer :bots_config # Keep this setting here, so we can avoid loading Bot::UpdatesPoller # when polling is disabled. attr_writer :bot_poller_mode # It just tells routes helpers whether to add routed bots to # Bot::UpdatesPoller, so their config will be available by bot key in # Bot::UpdatesPoller.start. # # It's enabled by default in Rails dev environment and `rake telegram:bot:poller` # task. Use `BOT_POLLER_MODE=true` envvar to set it manually. def bot_poller_mode? return @bot_poller_mode if defined?(@bot_poller_mode) @bot_poller_mode = ENV.fetch('BOT_POLLER_MODE') do Rails.env.development? if defined?(Rails) end end # Hash of bots made with bots_config. def bots @bots ||= bots_config.transform_values(&Client.method(:wrap)) end # Default bot. def bot @bot ||= bots[:default] end # Returns config for .bots method. By default uses `telegram['bots']` section # from `secrets.yml` merging `telegram['bot']` at `:default` key. # # Can be overwritten with .bots_config= def bots_config return @bots_config if @bots_config telegram_config = Rails.application.secrets[:telegram] (telegram_config['bots'] || {}).symbolize_keys.tap do |config| default = telegram_config['bot'] config[:default] = default if default end end # Resets all cached bots and their configs. def reset_bots @bots = nil @bot = nil @bots_config = nil end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
telegram-bot-0.8.0 | lib/telegram/bot/config_methods.rb |
telegram-bot-0.7.4 | lib/telegram/bot/config_methods.rb |
telegram-bot-0.7.3 | lib/telegram/bot/config_methods.rb |