lib/onstomp/interfaces/event_manager.rb in onstomp-1.0.0pre1 vs lib/onstomp/interfaces/event_manager.rb in onstomp-1.0.0
- old
+ new
@@ -30,10 +30,17 @@
event_callbacks[event_name].each { |cb| cb.call(*args) }
end
# Mixin to allow includers to define custom event methods
module ClassMethods
+ # A convenient way to get a list of all of the event methods a class
+ # has defined for itself. Returns an array of event method names as symbols.
+ # @return [Array<Symbol>]
+ def event_methods
+ @event_methods ||= []
+ end
+
# Creates a convenience method for binding callbacks to the given
# event name.
# @param [Symbol] name
# @example
# class ExampleClass
@@ -42,9 +49,10 @@
# create_event_method :do_event
# end
#
# example_obj.do_event { |arg1, arg2| ... }
def create_event_method name
+ event_methods << name
module_eval "def #{name}(&block); bind_event(:#{name}, block); end"
end
# Creates convenience methods for binding callbacks to the given
# event name with a set of prefixes.