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.
92 93 94 95 96 |
# File 'lib/matrix_sdk/extensions.rb', line 92 def initialize(*args) @reraise_exceptions = false super(*args) end |
Instance Attribute Details
#reraise_exceptions ⇒ Object
Returns the value of attribute reraise_exceptions.
90 91 92 |
# File 'lib/matrix_sdk/extensions.rb', line 90 def reraise_exceptions @reraise_exceptions end |
Instance Method Details
#add_handler(filter = nil, id = nil, &block) ⇒ Object
98 99 100 101 |
# File 'lib/matrix_sdk/extensions.rb', line 98 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
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/matrix_sdk/extensions.rb', line 107 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
103 104 105 |
# File 'lib/matrix_sdk/extensions.rb', line 103 def remove_handler(id) delete id end |