Class: Shipeasy::SDK::See::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/shipeasy/sdk/see.rb

Overview

Accumulates consequence + extras; ‘.to(outcome)` dispatches once.

Instance Method Summary collapse

Constructor Details

#initialize(problem, dispatch) ⇒ Chain

Returns a new instance of Chain.



199
200
201
202
203
204
205
206
# File 'lib/shipeasy/sdk/see.rb', line 199

def initialize(problem, dispatch)
  @problem  = problem
  @dispatch = dispatch
  @subject  = nil
  @outcome  = nil
  @extras   = nil
  @done     = false
end

Instance Method Details

#causes_the(subject) ⇒ Object Also known as: causesThe



208
209
210
211
# File 'lib/shipeasy/sdk/see.rb', line 208

def causes_the(subject)
  @subject = subject.to_s
  self
end

#extras(extras) ⇒ Object



214
215
216
217
218
219
# File 'lib/shipeasy/sdk/see.rb', line 214

def extras(extras)
  if extras.is_a?(Hash) && !extras.empty?
    @extras = (@extras || {}).merge(extras)
  end
  self
end

#to(outcome) ⇒ Object

Terminal: build the event and fire-and-forget the report. Idempotent.



222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/shipeasy/sdk/see.rb', line 222

def to(outcome)
  return if @done

  @done = true
  @outcome = outcome.to_s
  begin
    @dispatch.call(
      Built.new(@problem, @subject || DEFAULT_SUBJECT, @outcome.empty? ? DEFAULT_OUTCOME : @outcome, @extras)
    )
  rescue StandardError
    # Reporting must never raise into caller code.
    nil
  end
end