Class: Cubism::Broadcaster

Inherits:
Object
  • Object
show all
Includes:
CableReady::Broadcaster, CableReady::StreamIdentifier
Defined in:
lib/cubism/broadcaster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:) ⇒ Broadcaster

Returns a new instance of Broadcaster.



10
11
12
# File 'lib/cubism/broadcaster.rb', line 10

def initialize(resource:)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



8
9
10
# File 'lib/cubism/broadcaster.rb', line 8

def resource
  @resource
end

Instance Method Details

#broadcastObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cubism/broadcaster.rb', line 14

def broadcast
  resource.cubicle_element_ids.to_a.each do |element_id|
    block_container = Cubism.block_store[element_id]

    next if block_container.blank?

    present_users = resource.present_users_for_element_id_and_scope(element_id, block_container.scope)

    block_source = block_container.block_source

    html = ApplicationController.render(inline: block_source.source, locals: {"#{block_source.variable_name}": present_users})

    selector = "cubicle-element#cubicle-#{element_id}[identifier='#{signed_stream_identifier(resource.to_global_id.to_s)}']"

    cable_ready[element_id].inner_html(
      selector: selector,
      html: html
    )
  end

  cable_ready.broadcast
end