Module: StandardLedger::EventEmitter Private

Defined in:
lib/standard_ledger/event_emitter.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Internal helper that emits StandardLedger lifecycle events through whichever event reporter is live in the host process.

  • On Rails 8.1+, ‘Rails.event.notify(name, **payload)` is the canonical bus.

  • On older Rails (or any host without the structured reporter), we fall back to ‘ActiveSupport::Notifications.instrument(name, payload)`.

Detection is performed at *call time* — the gem is required before Rails has finished booting, so we cannot cache the decision at load time.

Class Method Summary collapse

Class Method Details

.emit(event_name, payload) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Emit a single event. Both backends are best-effort: any exception raised by a subscriber is swallowed so ledger observability never takes down a host’s request path (the projection has already either succeeded or been rolled back by the time we emit).



20
21
22
23
24
25
26
27
28
# File 'lib/standard_ledger/event_emitter.rb', line 20

def emit(event_name, payload)
  if (bus = rails_event_bus)
    bus.notify(event_name, **payload)
  else
    ::ActiveSupport::Notifications.instrument(event_name, payload)
  end
rescue => e
  warn "[StandardLedger] event emit for #{event_name.inspect} failed: #{e.class}: #{e.message}"
end

.rails_event_available?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Boolean shorthand kept for callers (and specs) that just want to know whether the modern bus is live.

Returns:

  • (Boolean)


43
44
45
# File 'lib/standard_ledger/event_emitter.rb', line 43

def rails_event_available?
  !rails_event_bus.nil?
end