Class: MatrixSdk::EventHandlerArray
- Includes:
- Logging
- Defined in:
- lib/matrix_sdk/util/events.rb
Instance Attribute Summary collapse
-
#reraise_exceptions ⇒ Object
Returns the value of attribute reraise_exceptions.
Instance Method Summary collapse
- #add_handler(filter = nil, id = nil, &block) ⇒ Object
- #fire(event, filter = nil) ⇒ Object
-
#initialize(*args) ⇒ EventHandlerArray
constructor
A new instance of EventHandlerArray.
- #remove_handler(id) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(*args) ⇒ EventHandlerArray
Returns a new instance of EventHandlerArray.
8 9 10 11 12 |
# File 'lib/matrix_sdk/util/events.rb', line 8 def initialize(*args) @reraise_exceptions = false super(*args) end |
Instance Attribute Details
#reraise_exceptions ⇒ Object
Returns the value of attribute reraise_exceptions.
6 7 8 |
# File 'lib/matrix_sdk/util/events.rb', line 6 def reraise_exceptions @reraise_exceptions end |
Instance Method Details
#add_handler(filter = nil, id = nil, &block) ⇒ Object
14 15 16 17 |
# File 'lib/matrix_sdk/util/events.rb', line 14 def add_handler(filter = nil, id = nil, &block) id ||= block.hash self[id] = { filter: filter, id: id, block: block } end |
#fire(event, filter = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/matrix_sdk/util/events.rb', line 23 def fire(event, filter = nil) reverse_each do |_k, h| h[:block].call(event) if !h[:filter] || event.matches?(h[:filter], filter) rescue StandardError => e logger.error "#{e.class.name} occurred when firing event (#{event})\n#{e}" raise e if @reraise_exceptions end end |
#remove_handler(id) ⇒ Object
19 20 21 |
# File 'lib/matrix_sdk/util/events.rb', line 19 def remove_handler(id) delete id end |