Class: Discordrb::Events::EventHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/events/generic.rb

Overview

Generic event handler that can be extended

Instance Method Summary collapse

Constructor Details

#initialize(attributes, block) ⇒ EventHandler


78
79
80
81
# File 'lib/discordrb/events/generic.rb', line 78

def initialize(attributes, block)
  @attributes = attributes
  @block = block
end

Instance Method Details

#after_call(event) ⇒ Object

to be overwritten by extending event handlers


102
# File 'lib/discordrb/events/generic.rb', line 102

def after_call(event); end

#call(event) ⇒ Object

Calls this handler


97
98
99
# File 'lib/discordrb/events/generic.rb', line 97

def call(event)
  @block.call(event)
end

#match(event) ⇒ Object

Checks whether this handler matches the given event, and then calls it.


91
92
93
# File 'lib/discordrb/events/generic.rb', line 91

def match(event)
  call(event) if matches? event
end

#matches?(_) ⇒ Boolean

Whether or not this event handler matches the given event with its attributes.

Raises:

  • (RuntimeError)

    if this method is called - overwrite it in your event handler!


85
86
87
# File 'lib/discordrb/events/generic.rb', line 85

def matches?(_)
  raise 'Attempted to call matches?() from a generic EventHandler'
end

#matches_all(attributes, to_check, &block) ⇒ Object

See Also:

  • matches_all

105
106
107
# File 'lib/discordrb/events/generic.rb', line 105

def matches_all(attributes, to_check, &block)
  Discordrb::Events.matches_all(attributes, to_check, &block)
end