зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-05 02:35:50 +03:00
Ability to use type-castion with telegram-bot-types
Этот коммит содержится в:
@@ -1,5 +1,5 @@
|
||||
module Telegram
|
||||
class Bot
|
||||
module Bot
|
||||
class UpdatesController
|
||||
# Most methods are taken from ActionController::Instrumentation,
|
||||
# some are slightly modified.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'active_support/log_subscriber'
|
||||
|
||||
module Telegram
|
||||
class Bot
|
||||
module Bot
|
||||
class UpdatesController
|
||||
class LogSubscriber < ActiveSupport::LogSubscriber
|
||||
def start_processing(event)
|
||||
|
||||
8
lib/telegram/bot/updates_controller/rspec_helpers.rb
Обычный файл
8
lib/telegram/bot/updates_controller/rspec_helpers.rb
Обычный файл
@@ -0,0 +1,8 @@
|
||||
RSpec.shared_context 'telegram/bot/updates_controller' do
|
||||
let(:instance) { described_class.new(bot, update) }
|
||||
let(:update) { {payload_type => payload} }
|
||||
let(:payload_type) { 'some_type' }
|
||||
let(:payload) { double(:payload) }
|
||||
let(:bot) { double(username: bot_name) }
|
||||
let(:bot_name) { 'bot' }
|
||||
end
|
||||
14
lib/telegram/bot/updates_controller/typed_update.rb
Обычный файл
14
lib/telegram/bot/updates_controller/typed_update.rb
Обычный файл
@@ -0,0 +1,14 @@
|
||||
module Telegram
|
||||
module Bot
|
||||
class UpdatesController
|
||||
# Include this module to type cast update to Virtus model
|
||||
# using `telegram-bot-types` gem (install this gem first).
|
||||
module TypedUpdate
|
||||
def initialize(bot, update)
|
||||
update = Types::Update.new(update) if update && !update.is_a?(Types::Update)
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Ссылка в новой задаче
Block a user