Class: Houston::Observer::Callback
- Inherits:
-
Object
- Object
- Houston::Observer::Callback
- Defined in:
- lib/houston/boot/observer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#observer ⇒ Object
readonly
Returns the value of attribute observer.
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(observer, event, options, block) ⇒ Callback
constructor
A new instance of Callback.
- #invoke_async? ⇒ Boolean
- #raise_exceptions? ⇒ Boolean
Constructor Details
#initialize(observer, event, options, block) ⇒ Callback
Returns a new instance of Callback.
96 97 98 99 100 101 102 |
# File 'lib/houston/boot/observer.rb', line 96 def initialize(observer, event, , block) @observer = observer @event = event @invoke_async = .fetch(:async, nil) @raise_exceptions = .fetch(:raise, false) @block = block end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
94 95 96 |
# File 'lib/houston/boot/observer.rb', line 94 def event @event end |
#observer ⇒ Object (readonly)
Returns the value of attribute observer.
94 95 96 |
# File 'lib/houston/boot/observer.rb', line 94 def observer @observer end |
Instance Method Details
#call(*args) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/houston/boot/observer.rb', line 113 def call(*args) Houston.async(invoke_async?) do begin @block.call(*args) rescue Exception # rescues StandardError by default; but we want to rescue and report all errors raise if raise_exceptions? $!.additional_information[:event] = event $!.additional_information[:async] = invoke_async? $!.additional_information[:raise_exceptions] = raise_exceptions? Houston.report_exception($!) end end end |
#invoke_async? ⇒ Boolean
104 105 106 107 |
# File 'lib/houston/boot/observer.rb', line 104 def invoke_async? return @invoke_async unless @invoke_async.nil? Houston.observer.async end |
#raise_exceptions? ⇒ Boolean
109 110 111 |
# File 'lib/houston/boot/observer.rb', line 109 def raise_exceptions? @raise_exceptions end |