Class: Discorb::View::Extension
- Inherits:
-
Extension
- Object
- Extension
- Discorb::View::Extension
- Defined in:
- lib/discorb/view/extension.rb
Overview
Note:
Client must extend this class to use discorb-view.
An extension for using discorb-view.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.inherited(base) ⇒ Object
16 17 18 |
# File 'lib/discorb/view/extension.rb', line 16 def self.inherited(base) base.views = {} end |
.loaded(client) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/discorb/view/extension.rb', line 35 def self.loaded(client) class << client attr_accessor :views end client.views = {} end |
Instance Method Details
#handle_interaction(interaction) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/discorb/view/extension.rb', line 21 def handle_interaction(interaction) unless view = @client.views[interaction..id.to_s] @client.log.warn "View: No handler for #{interaction..id.to_s}" return end handler = view.class.components[interaction.custom_id.to_sym] @client.log.debug "View: Handling #{interaction.custom_id} in #{interaction..id}" view.interaction = interaction update = view.instance_exec(interaction, &handler.block) return unless update @client.log.debug "View: Updating view #{interaction..id}" view.render end |