Module: EventBus
- Included in:
- Application, EventWatcherForGem
- Defined in:
- lib/a-commons.rb
Overview
(or SourceEvent)
Instance Method Summary collapse
- #attach_listener(_listener, _class_event) ⇒ Object
- #attach_listeners_listener(_listener, _class_event) ⇒ Object
- #broadcast_event(_event) ⇒ Object
- #detach_listener(_listener, _class_event = nil) ⇒ Object
- #detach_listeners_listener(_listener, _class_event = nil) ⇒ Object
- #process_event(_event, _listeners = nil) ⇒ Object
Instance Method Details
#attach_listener(_listener, _class_event) ⇒ Object
844 845 846 847 848 |
# File 'lib/a-commons.rb', line 844 def attach_listener(_listener, _class_event) @@listeners = {} unless defined? @@listeners @@listeners[_class_event] = [] unless @@listeners.has_key?(_class_event) @@listeners[_class_event] << _listener end |
#attach_listeners_listener(_listener, _class_event) ⇒ Object
850 851 852 853 854 |
# File 'lib/a-commons.rb', line 850 def attach_listeners_listener(_listener, _class_event) @@listeners_listeners = {} unless defined? @@listeners_listeners @@listeners_listeners[_class_event] = [] unless @@listeners_listeners.has_key?(_class_event) @@listeners_listeners[_class_event] << _listener end |
#broadcast_event(_event) ⇒ Object
740 741 742 743 744 745 746 |
# File 'lib/a-commons.rb', line 740 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 = nil) ⇒ Object
831 832 833 834 835 836 837 838 839 840 841 842 |
# File 'lib/a-commons.rb', line 831 def detach_listener(_listener, _class_event=nil) if _class_event != nil if @@listeners[_class_event] @@listeners[_class_event].delete(_listener) end else #delete all the issues of listenere @@listeners.each{|klass, header| header.delete(_listener) } end end |
#detach_listeners_listener(_listener, _class_event = nil) ⇒ Object
856 857 858 859 860 861 862 863 864 865 866 867 |
# File 'lib/a-commons.rb', line 856 def detach_listeners_listener(_listener, _class_event=nil) if _class_event != nil if @@listeners_listeners[_class_event] @@listeners_listeners[_class_event].delete(_listener) end else #delete all the issues of listenere @@listeners_listeners.each{|klass, header| header.delete(_listener) } end end |
#process_event(_event, _listeners = nil) ⇒ Object
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
# File 'lib/a-commons.rb', line 693 def process_event(_event, _listeners=nil) # _listener rapresent a filter on @@listeners if != nil return _event if !defined?(@@listeners) @@listeners_listeners = {} unless defined? @@listeners_listeners event_classes = _event_class_stack(_event.class) #before fase event_classes.each do |_c| if _listeners.nil? _process_fase(_c, _event, @@listeners[_c], @@listeners_listeners[_c], 'before') else listeners_to_process = [] _listeners.each{|lis| listeners_to_process << lis if @@listeners[_c] && @@listeners[_c].include?(lis) } _process_fase(_c, _event, listeners_to_process, @@listeners_listeners[_c], 'before') end 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| if _listeners.nil? _process_fase(_c, _event, @@listeners[_c], @@listeners_listeners[_c]) else listeners_to_process = [] _listeners.each{|lis| listeners_to_process << lis if @@listeners[_c] && @@listeners[_c].include?(lis) } _process_fase(_c, _event, listeners_to_process, @@listeners_listeners[_c]) end break if _event.is_breaked? end unless _event.is_breaked? #after fase event_classes.each do |_c| if _listeners.nil? _process_fase(_c, _event, @@listeners[_c], @@listeners_listeners[_c], 'after') else listeners_to_process = [] _listeners.each{|lis| listeners_to_process << lis if @@listeners[_c] && @@listeners[_c].include?(lis) } _process_fase(_c, _event, listeners_to_process, @@listeners_listeners[_c], 'after') end break if _event.is_breaked? end unless _event.is_breaked? _event end |