Class: MatrixSdk::EventHandlerArray
- Includes:
- Logging
- Defined in:
- lib/matrix_sdk/extensions.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.
84 85 86 87 88 |
# File 'lib/matrix_sdk/extensions.rb', line 84 def initialize(*args) @reraise_exceptions = false super(*args) end |
Instance Attribute Details
#reraise_exceptions ⇒ Object
Returns the value of attribute reraise_exceptions.
82 83 84 |
# File 'lib/matrix_sdk/extensions.rb', line 82 def reraise_exceptions @reraise_exceptions end |
Instance Method Details
#add_handler(filter = nil, id = nil, &block) ⇒ Object
90 91 92 93 |
# File 'lib/matrix_sdk/extensions.rb', line 90 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
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/matrix_sdk/extensions.rb', line 99 def fire(event, filter = nil) reverse_each do |_k, h| begin h[:block].call(event) if 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 end |
#remove_handler(id) ⇒ Object
95 96 97 |
# File 'lib/matrix_sdk/extensions.rb', line 95 def remove_handler(id) delete id end |