Module: Nexo::TurboBroadcaster
- Defined in:
- lib/nexo/turbo_broadcaster.rb
Overview
Opt-in Turbo mirror: subscribes to the nexo.workflow.event notifications
and re-broadcasts each event to a per-run Turbo stream. A no-op without
turbo-rails, so the plain-Ruby core stays coupling-free.
Class Method Summary collapse
-
.subscribe! ⇒ Object
Subscribes once (idempotent via @subscribed) to "nexo.workflow.event" and appends each event to the run's Turbo stream, rendering the overridable "nexo/event" partial.
Class Method Details
.subscribe! ⇒ Object
Subscribes once (idempotent via @subscribed) to "nexo.workflow.event" and appends each event to the run's Turbo stream, rendering the overridable "nexo/event" partial. Returns early (no subscription) unless turbo-rails is present, so calling it in a non-Turbo host is harmless.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nexo/turbo_broadcaster.rb', line 24 def self.subscribe! return unless defined?(::Turbo::StreamsChannel) return if @subscribed @subscribed = true ::ActiveSupport::Notifications.subscribe("nexo.workflow.event") do |*, payload| ::Turbo::StreamsChannel.broadcast_append_to( "nexo_run_#{payload[:run_id]}", target: "nexo_run_#{payload[:run_id]}_events", partial: "nexo/event", locals: {event: payload[:event]} ) end end |