Class: Houston::Observer::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/houston/boot/observer.rb

Direct Known Subclasses

CallbackOnce

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(observer, event, options, block) ⇒ Callback



96
97
98
99
100
101
102
# File 'lib/houston/boot/observer.rb', line 96

def initialize(observer, event, options, block)
  @observer = observer
  @event = event
  @invoke_async = options.fetch(:async, nil)
  @raise_exceptions = options.fetch(:raise, false)
  @block = block
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



94
95
96
# File 'lib/houston/boot/observer.rb', line 94

def event
  @event
end

#observerObject (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