Class: Rubycord::Events::EventHandler

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

Overview

Generic event handler that can be extended

Instance Method Summary collapse

Constructor Details

#initialize(attributes, block) ⇒ EventHandler

Returns a new instance of EventHandler.



76
77
78
79
# File 'lib/rubycord/events/generic.rb', line 76

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

Instance Method Details

#after_call(event) ⇒ Object

to be overwritten by extending event handlers



100
101
# File 'lib/rubycord/events/generic.rb', line 100

def after_call(event)
end

#call(event) ⇒ Object

Calls this handler

Parameters:

  • event (Object)

    The event object to call this handler with



95
96
97
# File 'lib/rubycord/events/generic.rb', line 95

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

#match(event) ⇒ Object

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

Parameters:

  • event (Object)

    The event object to match and call the handler with



89
90
91
# File 'lib/rubycord/events/generic.rb', line 89

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

#matches?(_) ⇒ Boolean

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

Returns:

  • (Boolean)

Raises:

  • (RuntimeError)

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



83
84
85
# File 'lib/rubycord/events/generic.rb', line 83

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

#matches_all(attributes, to_check) ⇒ Object

See Also:

  • matches_all


104
105
106
# File 'lib/rubycord/events/generic.rb', line 104

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