lib/telegram/bot/config_methods.rb in telegram-bot-0.14.0 vs lib/telegram/bot/config_methods.rb in telegram-bot-0.14.1
- old
+ new
@@ -38,27 +38,24 @@
' Add :default to bots_config' \
' or use telegram.bot/telegram.bots.default section in secrets.yml.'
end
end
- # Hash of botan clients made from #bots.
- def botans
- @botans ||= bots.map { |k, v| [k, v.botan] }.to_h
- 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
@bots_config ||=
if defined?(Rails.application)
app = Rails.application
- store = app.respond_to?(:credentials) ? app.credentials : app.secrets
- secrets = store.fetch(:telegram, {}).with_indifferent_access
- secrets.fetch(:bots, {}).symbolize_keys.tap do |config|
- default = secrets[:bot]
+ store = app.credentials[:telegram] if app.respond_to?(:credentials)
+ store ||= app.secrets[:telegram] if app.respond_to?(:secrets)
+ store ||= {}
+ store = store.with_indifferent_access
+ store.fetch(:bots, {}).symbolize_keys.tap do |config|
+ default = store[:bot]
config[:default] = default if default
end
else
{}
end
@@ -67,10 +64,9 @@
# Resets all cached bots and their configs.
def reset_bots
@bots = nil
@bot = nil
@bots_config = nil
- @botans = nil
end
end
end
end