Module: Telegram::Bot::UpdatesController::MessageContext::ClassMethods
- Defined in:
- lib/telegram/bot/updates_controller/message_context.rb
Instance Attribute Summary collapse
-
#context_to_action ⇒ Object
readonly
Returns the value of attribute context_to_action.
Instance Method Summary collapse
-
#context_handler(context = nil, action = nil, &block) ⇒ Object
Registers handler for context.
- #context_handlers ⇒ Object
-
#context_to_action! ⇒ Object
Use it to use context value as action name for all contexts which miss handlers.
Instance Attribute Details
#context_to_action ⇒ Object (readonly)
Returns the value of attribute context_to_action.
39 40 41 |
# File 'lib/telegram/bot/updates_controller/message_context.rb', line 39 def context_to_action @context_to_action end |
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
30 31 32 33 34 35 36 37 |
# File 'lib/telegram/bot/updates_controller/message_context.rb', line 30 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_handlers ⇒ Object
11 12 13 |
# File 'lib/telegram/bot/updates_controller/message_context.rb', line 11 def context_handlers @_context_handlers ||= {} 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.
45 46 47 |
# File 'lib/telegram/bot/updates_controller/message_context.rb', line 45 def context_to_action! @context_to_action = true end |