class MijDiscord::Events::DispatcherBase

Constants

Callback

Public Class Methods

new(klass) click to toggle source
# File lib/mij-discord/events.rb, line 102
def initialize(klass)
  raise ArgumentError, 'Class must inherit from EventBase' unless klass < EventBase

  @klass, @callbacks = klass, {}
end

Public Instance Methods

add_callback(key = nil, **filter, &block) click to toggle source
# File lib/mij-discord/events.rb, line 108
def add_callback(key = nil, **filter, &block)
  raise ArgumentError, 'No callback block provided' if block.nil?

  key = block.object_id if key.nil?
  @callbacks[key] = Callback.new(key, block, filter)
  key
end
callbacks() click to toggle source
# File lib/mij-discord/events.rb, line 121
def callbacks
  @callbacks.values
end
raise(event_args, block_args = nil)
Alias for: trigger
remove_callback(key) click to toggle source
# File lib/mij-discord/events.rb, line 116
def remove_callback(key)
  @callbacks.delete(key)
  nil
end
trigger(event_args, block_args = nil) click to toggle source
# File lib/mij-discord/events.rb, line 125
def trigger(event_args, block_args = nil)
  event = @klass.new(*event_args)

  @callbacks.each do |_, cb|
    execute_callback(cb, event, block_args) if event.trigger?(cb.filter)
  end
end
Also aliased as: raise