Module: Turbo::Train::Broadcasts
- Included in:
- Turbo::Train
- Defined in:
- lib/turbo/train/broadcasts.rb
Instance Method Summary collapse
- #broadcast(streamables, content:, server: nil) ⇒ Object
-
#broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, **rendering) ⇒ Object
later.
- #broadcast_action_to(*streamables, action:, target: nil, targets: nil, **rendering) ⇒ Object
- #broadcast_after_later_to(*streamables, **opts) ⇒ Object
- #broadcast_after_to(*streamables, **opts) ⇒ Object
- #broadcast_append_later_to(*streamables, **opts) ⇒ Object
- #broadcast_append_to(*streamables, **opts) ⇒ Object
- #broadcast_before_later_to(*streamables, **opts) ⇒ Object
- #broadcast_before_to(*streamables, **opts) ⇒ Object
- #broadcast_prepend_later_to(*streamables, **opts) ⇒ Object
- #broadcast_prepend_to(*streamables, **opts) ⇒ Object
- #broadcast_remove_later_to(*streamables, **opts) ⇒ Object
- #broadcast_remove_to(*streamables, **opts) ⇒ Object
- #broadcast_render_later_to(*streamables, **rendering) ⇒ Object
- #broadcast_render_to(*streamables, **rendering) ⇒ Object
- #broadcast_replace_later_to(*streamables, **opts) ⇒ Object
- #broadcast_replace_to(*streamables, **opts) ⇒ Object
- #broadcast_update_later_to(*streamables, **opts) ⇒ Object
- #broadcast_update_to(*streamables, **opts) ⇒ Object
Instance Method Details
#broadcast(streamables, content:, server: nil) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/turbo/train/broadcasts.rb', line 2 def broadcast(streamables, content:, server: nil) topics = if streamables.is_a?(Array) streamables.map { |s| signed_stream_name(s) } else [signed_stream_name(streamables)] end data = { topic: topics, data: content } Turbo::Train.server(server).publish(topics: topics, data: data) end |
#broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, **rendering) ⇒ Object
later
56 57 58 |
# File 'lib/turbo/train/broadcasts.rb', line 56 def broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, **rendering) Turbo::Train::ActionBroadcastJob.perform_later streamables, action: action, target: target, targets: targets, **rendering end |
#broadcast_action_to(*streamables, action:, target: nil, targets: nil, **rendering) ⇒ Object
17 18 19 20 21 |
# File 'lib/turbo/train/broadcasts.rb', line 17 def broadcast_action_to(*streamables, action:, target: nil, targets: nil, **rendering) broadcast(streamables, content: turbo_stream_action_tag(action, target: target, targets: targets, template: rendering.delete(:content) || rendering.delete(:html) || (rendering.any? ? render_format(:html, **rendering) : nil) ), server: rendering.delete(:server)) end |
#broadcast_after_later_to(*streamables, **opts) ⇒ Object
76 77 78 |
# File 'lib/turbo/train/broadcasts.rb', line 76 def broadcast_after_later_to(*streamables, **opts) broadcast_action_later_to(*streamables, action: :after, **opts) end |
#broadcast_after_to(*streamables, **opts) ⇒ Object
43 44 45 |
# File 'lib/turbo/train/broadcasts.rb', line 43 def broadcast_after_to(*streamables, **opts) broadcast_action_to(*streamables, action: :after, **opts) end |
#broadcast_append_later_to(*streamables, **opts) ⇒ Object
80 81 82 |
# File 'lib/turbo/train/broadcasts.rb', line 80 def broadcast_append_later_to(*streamables, **opts) broadcast_action_later_to(*streamables, action: :append, **opts) end |
#broadcast_append_to(*streamables, **opts) ⇒ Object
47 48 49 |
# File 'lib/turbo/train/broadcasts.rb', line 47 def broadcast_append_to(*streamables, **opts) broadcast_action_to(*streamables, action: :append, **opts) end |
#broadcast_before_later_to(*streamables, **opts) ⇒ Object
72 73 74 |
# File 'lib/turbo/train/broadcasts.rb', line 72 def broadcast_before_later_to(*streamables, **opts) broadcast_action_later_to(*streamables, action: :before, **opts) end |
#broadcast_before_to(*streamables, **opts) ⇒ Object
39 40 41 |
# File 'lib/turbo/train/broadcasts.rb', line 39 def broadcast_before_to(*streamables, **opts) broadcast_action_to(*streamables, action: :before, **opts) end |
#broadcast_prepend_later_to(*streamables, **opts) ⇒ Object
84 85 86 |
# File 'lib/turbo/train/broadcasts.rb', line 84 def broadcast_prepend_later_to(*streamables, **opts) broadcast_action_later_to(*streamables, action: :prepend, **opts) end |
#broadcast_prepend_to(*streamables, **opts) ⇒ Object
51 52 53 |
# File 'lib/turbo/train/broadcasts.rb', line 51 def broadcast_prepend_to(*streamables, **opts) broadcast_action_to(*streamables, action: :prepend, **opts) end |
#broadcast_remove_later_to(*streamables, **opts) ⇒ Object
64 65 66 |
# File 'lib/turbo/train/broadcasts.rb', line 64 def broadcast_remove_later_to(*streamables, **opts) broadcast_action_later_to(*streamables, action: :remove, **opts) end |
#broadcast_remove_to(*streamables, **opts) ⇒ Object
27 28 29 |
# File 'lib/turbo/train/broadcasts.rb', line 27 def broadcast_remove_to(*streamables, **opts) broadcast_action_to(*streamables, action: :remove, **opts) end |
#broadcast_render_later_to(*streamables, **rendering) ⇒ Object
88 89 90 |
# File 'lib/turbo/train/broadcasts.rb', line 88 def broadcast_render_later_to(*streamables, **rendering) Turbo::Train::BroadcastJob.perform_later streamables, **rendering end |
#broadcast_render_to(*streamables, **rendering) ⇒ Object
23 24 25 |
# File 'lib/turbo/train/broadcasts.rb', line 23 def broadcast_render_to(*streamables, **rendering) broadcast(*streamables, content: render_format(:turbo_stream, **rendering)) end |
#broadcast_replace_later_to(*streamables, **opts) ⇒ Object
60 61 62 |
# File 'lib/turbo/train/broadcasts.rb', line 60 def broadcast_replace_later_to(*streamables, **opts) broadcast_action_later_to(*streamables, action: :replace, **opts) end |
#broadcast_replace_to(*streamables, **opts) ⇒ Object
31 32 33 |
# File 'lib/turbo/train/broadcasts.rb', line 31 def broadcast_replace_to(*streamables, **opts) broadcast_action_to(*streamables, action: :replace, **opts) end |
#broadcast_update_later_to(*streamables, **opts) ⇒ Object
68 69 70 |
# File 'lib/turbo/train/broadcasts.rb', line 68 def broadcast_update_later_to(*streamables, **opts) broadcast_action_later_to(*streamables, action: :update, **opts) end |
#broadcast_update_to(*streamables, **opts) ⇒ Object
35 36 37 |
# File 'lib/turbo/train/broadcasts.rb', line 35 def broadcast_update_to(*streamables, **opts) broadcast_action_to(*streamables, action: :update, **opts) end |