Class: Mistri::EventDelivery::Boundary

Inherits:
Object
  • Object
show all
Defined in:
lib/mistri/event_delivery.rb

Overview

Wraps one subscriber and unwraps only failures that it created.

Instance Method Summary collapse

Constructor Details

#initialize(subscriber, passthrough: []) ⇒ Boundary

Returns a new instance of Boundary.



20
21
22
23
24
# File 'lib/mistri/event_delivery.rb', line 20

def initialize(subscriber, passthrough: [])
  @subscriber = subscriber
  @passthrough = passthrough.freeze
  @callable = method(:call).to_proc
end

Instance Method Details

#call(event) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/mistri/event_delivery.rb', line 28

def call(event)
  @subscriber.call(event)
rescue Failure
  raise
rescue StandardError => e
  raise if @passthrough.any? { |error_class| e.is_a?(error_class) }

  raise Failure.new(e, self)
end

#to_procObject



26
# File 'lib/mistri/event_delivery.rb', line 26

def to_proc = @callable

#unwrap(error) ⇒ Object



38
39
40
# File 'lib/mistri/event_delivery.rb', line 38

def unwrap(error)
  error.boundary.equal?(self) ? error.original : error
end