Class: LibSL::EventManager
- Inherits:
-
Object
- Object
- LibSL::EventManager
- Defined in:
- lib/events.rb
Class Method Summary collapse
-
.fire_event(type, *args) ⇒ Object
Fires an event that will be handled by registered handlers.
- .handlers ⇒ Object
-
.register_handler(handler) ⇒ Object
Register an event handler if it does not already exist.
-
.remove_handler(handler) ⇒ Object
Removes an event handler.
Class Method Details
.fire_event(type, *args) ⇒ Object
Fires an event that will be handled by registered handlers
55 56 57 |
# File 'lib/events.rb', line 55 def self.fire_event(type, *args) handlers.each { |h| h.handle(type, *args) if h.accept?(type) } end |
.handlers ⇒ Object
35 36 37 38 |
# File 'lib/events.rb', line 35 def self.handlers @@handlers ||= [] @@handlers end |
.register_handler(handler) ⇒ Object
Register an event handler if it does not already exist
42 43 44 |
# File 'lib/events.rb', line 42 def self.register_handler(handler) handlers << handler unless handlers.include? handler end |
.remove_handler(handler) ⇒ Object
Removes an event handler
48 49 50 |
# File 'lib/events.rb', line 48 def self.remove_handler(handler) handlers.delete handler end |