Base event class for stuff shared by any type of event. Note that :type and :handled apply to all events, so they’re explicitly defined here.

Methods
E
H
N
T
Class Public methods
new(data = {})

Creates an event object and sets up some sane defaults for common elements. Any elements in the data hash are converted to “magic” methods.

# File lib/net/yail/event.rb, line 11
def initialize(data = {})
  # Don't modify incoming data!
  @data = data.dup
  @handled = false
  @type = @data.delete(:type)

  # All events have the capacity for a parent
  @data[:parent] ||= nil

  # Give useful accessors in a hacky but fun way!  I can't decide if I prefer the pain of
  # using method_missing or the pain of not knowing how to do this without a string eval....
  for key in @data.keys
    key = key.to_s
    self.instance_eval("def #{key}; return @data[:#{key}]; end")
  end

  raise "BaseEvent not usable - please subclass" if BaseEvent == self.class
end
Instance Public methods
event_class()
# File lib/net/yail/event.rb, line 42
def event_class
  return "base"
end
handled!()

Slightly unintuitive name to avoid accidental use - we don’t want it to be the norm to stop the event handling chain anymore! Filters + callback should make that a rarity.

# File lib/net/yail/event.rb, line 37
def handled!; @handled = true; end
handled?()

Cheesy shortcut to @handled in “boolean” form

# File lib/net/yail/event.rb, line 40
def handled?; return @handled; end
to_s()

Helps us debug

# File lib/net/yail/event.rb, line 31
def to_s
  return super().gsub(self.class.name, "%s [%s]" % [self.class.name, @type.to_s])
end
type()
# File lib/net/yail/event.rb, line 46
def type
  return ("%s_%s" % [event_class, @type]).to_sym
end