Module: Plutonium::Kanban::Broadcaster

Extended by:
Broadcaster
Included in:
Broadcaster
Defined in:
lib/plutonium/kanban/broadcaster.rb

Overview

Builds ActionCable stream names and broadcasts Turbo Stream updates for opt-in realtime kanban boards.

Tenant isolation

The stream name is a three-segment string:

"kanban:<tenant>:<resource>"

where is the scoped entity's GID param (e.g. "Z2lkOi8vYXBwL09yZy8x") or the literal string "global" for unscoped portals.

Two viewers are on the SAME stream only when they share identical resource_class AND scoped_entity — different tenants can never share a stream because their GID params are distinct by definition.

Instance Method Summary collapse

Instance Method Details

#broadcast(resource_class:, scoped_entity:, content:) ⇒ Object

Broadcasts the Turbo Stream HTML to all ActionCable subscribers watching this board's stream.

Parameters:

  • resource_class (Class)
  • scoped_entity (ActiveRecord::Base, nil)
  • content (String)

    the raw turbo-stream HTML (one or more tags) to push to subscribers



46
47
48
49
50
51
# File 'lib/plutonium/kanban/broadcaster.rb', line 46

def broadcast(resource_class:, scoped_entity:, content:)
  Turbo::StreamsChannel.broadcast_stream_to(
    *stream_name(resource_class:, scoped_entity:),
    content: content
  )
end

#stream_name(resource_class:, scoped_entity:) ⇒ Array<String>

Returns the streamables array that identifies this board's ActionCable stream.

Pass the returned array directly to turbo-rails helpers:

turbo_stream_from(*Broadcaster.stream_name(resource_class: Task, scoped_entity: org))
Turbo::StreamsChannel.broadcast_stream_to(*stream_name, content:)

Parameters:

  • resource_class (Class)

    the ActiveRecord model class for the board

  • scoped_entity (ActiveRecord::Base, nil)

    the tenant record, or nil for portals that are not entity-scoped

Returns:

  • (Array<String>)


34
35
36
37
# File 'lib/plutonium/kanban/broadcaster.rb', line 34

def stream_name(resource_class:, scoped_entity:)
  entity_segment = scoped_entity&.to_gid_param || "global"
  ["kanban", entity_segment, resource_class.name]
end