Sha256: 757def212740b9cdef09a5a8477fd6797ac7a7715eba67c6a1e0b30eb1eb1c13

Contents?: true

Size: 1007 Bytes

Versions: 9

Compression:

Stored size: 1007 Bytes

Contents

module Futurism
  class Channel < Futurism.configuration.parent_channel.constantize
    include CableReady::Broadcaster

    def stream_name
      ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
      [
        params[:channel],
        ids.select(&:present?).join(";")
      ].select(&:present?).join(":")
    end

    def subscribed
      stream_from stream_name
    end

    def receive(data)
      resources = data.fetch_values("signed_params", "sgids", "signed_controllers", "urls", "broadcast_each") { |_key| Array.new(data["signed_params"].length, nil) }.transpose

      resolver = Resolver::Resources.new(resource_definitions: resources, connection: connection, params: @params)
      resolver.resolve do |selector, html, broadcast_each|
        cable_ready[stream_name].outer_html(
          selector: selector,
          html: html
        )

        cable_ready.broadcast if broadcast_each
      end

      cable_ready.broadcast
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
futurism-1.4.2 app/channels/futurism/channel.rb
futurism-1.4.1 app/channels/futurism/channel.rb
futurism-1.4.0 app/channels/futurism/channel.rb
futurism-1.3.0 app/channels/futurism/channel.rb
futurism-1.2.0 app/channels/futurism/channel.rb
futurism-1.2.0.rc2 app/channels/futurism/channel.rb
futurism-1.2.0.rc1 app/channels/futurism/channel.rb
futurism-1.2.0.pre11 app/channels/futurism/channel.rb
futurism-1.2.0.pre10 app/channels/futurism/channel.rb