Sha256: 07f9f758de5f8ae79f1db256b8c5d9b3eb2f211fff18c2ad9ac1b6d08e20def9

Contents?: true

Size: 819 Bytes

Versions: 1

Compression:

Stored size: 819 Bytes

Contents

require "cable_ready"

module Cubism
  class Broadcaster
    include CableReady::Broadcaster
    include CableReady::StreamIdentifier

    attr_reader :resource

    def initialize(resource:)
      @resource = resource
    end

    def broadcast
      resource.cubicle_element_ids.to_a.each do |element_id|
        /cubicle-(?<block_key>.+)/ =~ element_id
        store_item = Cubism.store[block_key]

        next if store_item.blank?

        html = ApplicationController.render(inline: store_item.block_source, locals: {users: resource.present_users_for_element_id(element_id)})

        cable_ready[element_id].inner_html(
          selector: "cubicle-element##{element_id}[identifier='#{signed_stream_identifier(resource.to_global_id.to_s)}']",
          html: html
        ).broadcast
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cubism-0.1.0.pre10 lib/cubism/broadcaster.rb