Class: NitroRails::Broadcast
- Inherits:
-
Object
- Object
- NitroRails::Broadcast
- Includes:
- Turbo::Streams::Broadcasts
- Defined in:
- app/models/nitro_rails/broadcast.rb
Overview
Maybe call Stream instead of Broadcast
Class Method Summary collapse
Instance Method Summary collapse
- #action(action) ⇒ Object
- #attributes(**attributes) ⇒ Object
- #build {|_self| ... } ⇒ Object
-
#initialize(streamables, action = nil) ⇒ Broadcast
constructor
A new instance of Broadcast.
- #perform ⇒ Object
- #perform_later ⇒ Object
- #stream ⇒ Object
- #stream_attributes ⇒ Object
- #target(target) ⇒ Object
- #targets(targets) ⇒ Object
- #template(content = nil, **rendering) ⇒ Object
Constructor Details
#initialize(streamables, action = nil) ⇒ Broadcast
Returns a new instance of Broadcast.
15 16 17 18 |
# File 'app/models/nitro_rails/broadcast.rb', line 15 def initialize(streamables, action = nil) @streamables = streamables @action = action end |
Class Method Details
.build(*streamables, action, &block) ⇒ Object
6 7 8 |
# File 'app/models/nitro_rails/broadcast.rb', line 6 def self.build(*streamables, action, &block) new(*streamables, action).build(&block) end |
Instance Method Details
#action(action) ⇒ Object
20 21 22 |
# File 'app/models/nitro_rails/broadcast.rb', line 20 def action(action) @action = action end |
#attributes(**attributes) ⇒ Object
24 25 26 |
# File 'app/models/nitro_rails/broadcast.rb', line 24 def attributes(**attributes) @attributes = attributes end |
#build {|_self| ... } ⇒ Object
10 11 12 13 |
# File 'app/models/nitro_rails/broadcast.rb', line 10 def build yield(self) return self end |
#perform ⇒ Object
48 49 50 |
# File 'app/models/nitro_rails/broadcast.rb', line 48 def perform broadcast_stream_to(@streamables, content: stream) end |
#perform_later ⇒ Object
52 53 54 |
# File 'app/models/nitro_rails/broadcast.rb', line 52 def perform_later broadcast_stream_later_to(@streamables, content: stream) end |
#stream ⇒ Object
44 45 46 |
# File 'app/models/nitro_rails/broadcast.rb', line 44 def stream turbo_stream_action_tag(@action, **stream_attributes) end |
#stream_attributes ⇒ Object
40 41 42 |
# File 'app/models/nitro_rails/broadcast.rb', line 40 def stream_attributes (@attributes || {}).merge(targets: @targets, target: @target, template: @template) end |
#target(target) ⇒ Object
28 29 30 |
# File 'app/models/nitro_rails/broadcast.rb', line 28 def target(target) @target = "#{target}:not([data-reject-broadcasts])" end |
#targets(targets) ⇒ Object
32 33 34 |
# File 'app/models/nitro_rails/broadcast.rb', line 32 def targets(targets) @targets = "#{targets}:not([data-reject-broadcasts])" end |
#template(content = nil, **rendering) ⇒ Object
36 37 38 |
# File 'app/models/nitro_rails/broadcast.rb', line 36 def template(content = nil, **rendering) @template = content || render_format(:html, **rendering) end |