Class: NitroRails::Broadcast

Inherits:
Object
  • Object
show all
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

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

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
# File 'app/models/nitro_rails/broadcast.rb', line 10

def build
  yield(self)
  return self
end

#performObject



48
49
50
# File 'app/models/nitro_rails/broadcast.rb', line 48

def perform 
  broadcast_stream_to(@streamables, content: stream)
end

#perform_laterObject



52
53
54
# File 'app/models/nitro_rails/broadcast.rb', line 52

def perform_later
  broadcast_stream_later_to(@streamables, content: stream)
end

#streamObject



44
45
46
# File 'app/models/nitro_rails/broadcast.rb', line 44

def stream 
  turbo_stream_action_tag(@action, **stream_attributes)
end

#stream_attributesObject



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