Module: Telegram::Bot::UpdatesController::MessageContext::ClassMethods
- Defined in:
- lib/telegram/bot/updates_controller/message_context.rb
Instance Method Summary collapse
-
#context_handler(context = nil, action = nil, &block) ⇒ Object
Registers handler for context.
-
#context_to_action! ⇒ Object
Use it to use context value as action name for all contexts which miss handlers.
Instance Method Details
#context_handler(context = nil, action = nil, &block) ⇒ Object
Registers handler for context.
context_handler :rename do |*|
resource.update!(name: payload['text'])
end
# To run other action with all the callbacks:
context_handler :rename do |*words|
process(:rename, *words)
end
# Or just
context_handler :rename, :your_action_to_call
context_handler :rename # to call :rename
33 34 35 36 37 38 39 40 |
# File 'lib/telegram/bot/updates_controller/message_context.rb', line 33 def context_handler(context = nil, action = nil, &block) context &&= context.to_sym if block action = "_context_handler_#{context}" define_method(action, &block) end context_handlers[context] = action || context end |
#context_to_action! ⇒ Object
Use it to use context value as action name for all contexts which miss handlers. For security reasons it supports only action methods and will raise AbstractController::ActionNotFound if context is invalid.
46 47 48 |
# File 'lib/telegram/bot/updates_controller/message_context.rb', line 46 def context_to_action! @context_to_action = true end |