1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-09-03 09:46:17 +03:00
Этот коммит содержится в:
Max Melentiev
2016-03-04 15:27:41 +06:00
родитель 2a511abe16
Коммит 32b6794924
4 изменённых файлов: 100 добавлений и 4 удалений

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

@@ -4,6 +4,35 @@ module Telegram
class ClientStub < Client
attr_reader :requests
module StubbedConstructor
def new(*args)
if self == ClientStub || !ClientStub.stub_all?
super
else
ClientStub.new(args[1])
end
end
end
class << self
# Makes all
def stub_all!(enabled = true)
Client.extend(StubbedConstructor) unless Client < StubbedConstructor
return @_stub_all = enabled unless block_given?
begin
old = @_stub_all
stub_all!(enabled)
yield
ensure
stub_all!(old)
end
end
def stub_all?
@_stub_all
end
end
def initialize(username = nil)
@username = username
reset

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

@@ -41,6 +41,13 @@ module Telegram
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