Sha256: 6174fbec2bf3f7eddc9ccfc30411fc8eea0fa96adc97eff6912e5f4e4dea489d
Contents?: true
Size: 1.51 KB
Versions: 23
Compression:
Stored size: 1.51 KB
Contents
module Spider module EventSource def self.included(klass) klass.extend(ClassMethods) end module ClassMethods def inherited(sub) if @event_handlers @event_handlers.each do |event_name, arr| arr.each do |proc| sub.on(event_name, &proc) end end end super end def on(event_name, &proc) @event_handlers ||= {} @event_handlers[event_name] ||= [] @event_handlers[event_name] << proc end def trigger(event_name, *params) return unless @event_handlers && @event_handlers[event_name] @event_handlers[event_name].each do |h| h.call(*params) end end end def on(event_name, *params) @event_handlers ||= {} @event_handlers[event_name] ||= [] debugger unless proc @event_handlers[event_name] << proc end def trigger(event_name, *params) self.class.trigger(event_name, *([self]+params)) return unless @event_handlers && @event_handlers[event_name] @event_handlers[event_name].each do |h| h.call(*params) end end end end
Version data entries
23 entries across 23 versions & 1 rubygems
Version | Path |
---|---|
spiderfw-0.5.16 | lib/spiderfw/utils/events/event_source.rb |
spiderfw-0.5.15 | lib/spiderfw/utils/events/event_source.rb |
spiderfw-0.5.14 | lib/spiderfw/utils/events/event_source.rb |