Module: Clicksign::Instrumentation

Defined in:
lib/clicksign/instrumentation.rb

Constant Summary collapse

EVENTS =
%i[request retry error].freeze

Class Method Summary collapse

Class Method Details

.clearObject

Removes all registered callbacks — intended for test teardown.



27
28
29
# File 'lib/clicksign/instrumentation.rb', line 27

def clear
  @callbacks = Hash.new { |h, k| h[k] = [] }
end

.on(event, &block) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/clicksign/instrumentation.rb', line 10

def on(event, &block)
  unless EVENTS.include?(event)
    raise ArgumentError, "Unknown event: #{event}. Valid: #{EVENTS.join(', ')}"
  end

  @callbacks[event] << block
end

.publish(event, payload) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/clicksign/instrumentation.rb', line 18

def publish(event, payload)
  @callbacks[event].each do |cb|
    cb.call(payload)
  rescue StandardError
    # Callbacks must not affect the request — errors are silently ignored.
  end
end