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.
Creates an event object and sets up some sane defaults for common elements. Any elements in the data hash are converted to “magic” methods.
Source: show
# 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
Source: show
# File lib/net/yail/event.rb, line 42 def event_class return "base" end
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.
Source: show
# File lib/net/yail/event.rb, line 37 def handled!; @handled = true; end
Cheesy shortcut to @handled in “boolean” form
Source: show
# File lib/net/yail/event.rb, line 40 def handled?; return @handled; end