Module: EventBus

Included in:
Application, EventWatcherForGem
Defined in:
lib/a-commons.rb

Overview

(or SourceEvent)

Instance Method Summary collapse

Instance Method Details

#attach_listener(_listener, _class_event) ⇒ Object



504
505
506
507
508
# File 'lib/a-commons.rb', line 504

def attach_listener(_listener, _class_event)
  @@listeners = {} unless defined? @@listeners
  @@listeners[_class_event] = []   unless @@listeners.has_key?(_class_event)
  @@listeners[_class_event] << _listener
end

#broadcast_event(_event) ⇒ Object



420
421
422
423
424
425
426
# File 'lib/a-commons.rb', line 420

def broadcast_event(_event)
  return _event if !defined?(@@listeners)
  event_classes = _event_class_stack(_event.class)
  event_classes.each do |_c|
    _broadcast_fase(_c, _event)
  end
end

#detach_listener(_listener, _class_event) ⇒ Object



498
499
500
501
502
# File 'lib/a-commons.rb', line 498

def detach_listener(_listener, _class_event)
  if @@listeners[_class_event]
    @@listeners[_class_event].delete(_listener)
  end
end

#process_event(_event) ⇒ Object



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/a-commons.rb', line 399

def process_event(_event)
  return _event if !defined?(@@listeners)
  event_classes = _event_class_stack(_event.class)
  #before fase
  event_classes.each do |_c|
    _process_fase(_c, _event, 'before')
    break if _event.is_breaked? # not responding to this means "you need to pass in an instance, not a class name
  end unless _event.is_breaked?
  # fase
  event_classes.each do |_c|
    _process_fase(_c, _event)
    break if _event.is_breaked?
  end unless _event.is_breaked?
  #after fase
  event_classes.each do |_c|
    _process_fase(_c, _event, 'after')
    break if _event.is_breaked?
  end unless _event.is_breaked?
  _event
end