class Discorb::View::Base
Base
class for the view. @note You should not use this class directly. @abstract
Attributes
components[RW]
@return [Hash{Symbol => Discorb::Component}] The components.
views[RW]
@return [Array<ViewHandler>] The view handlers.
Public Class Methods
inherited(base)
click to toggle source
@private
# File lib/discorb/view/view.rb, line 38 def inherited(base) base.prepend(Discorb::View::Base::Prepend) base.components = {} base.views = [] end
start(channel, ...)
click to toggle source
Starts the view.
@param [Discorb::Messageable] channel The channel to send the message to.
# File lib/discorb/view/view.rb, line 98 def start(channel, ...) client = channel.instance_variable_get(:@client) if @views.empty? raise "No views defined" elsif not @views.any? { |v| v.check.nil? } raise "No fallback view defined" elsif @views.filter { |v| v.check.nil? }.count > 1 raise "Multiple fallback views defined" end view = new(client, channel, ...) view.start end
view(check = nil, &block)
click to toggle source
Add view handler to the view.
@param [Proc, nil] check The check of the view handler.
The view handler will be executed when the check returns true, or check is nil.
@yield The block to execute when the view handler is executed. @yieldparam [Discorb::View::Base::Prepend::Result] result The result of the view.
@note There must be one handler with no check.
# File lib/discorb/view/view.rb, line 88 def view(check = nil, &block) raise ArgumentError, "block required" unless block_given? @views.insert(0, ViewHandler.new(check, block)) end