Sha256: fe120e61a95f3088eaf2c625690c5a37718a15085d3d889bb98e246c01c6f905

Contents?: true

Size: 984 Bytes

Versions: 12

Compression:

Stored size: 984 Bytes

Contents

module Futurism
  class Channel < ActionCable::Channel::Base
    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

12 entries across 12 versions & 1 rubygems

Version Path
futurism-1.2.0.pre9 lib/futurism/channel.rb
futurism-1.2.0.pre8 lib/futurism/channel.rb
futurism-1.2.0.pre7 lib/futurism/channel.rb
futurism-1.2.0.pre6 lib/futurism/channel.rb
futurism-1.2.0.pre5 lib/futurism/channel.rb
futurism-1.2.0.pre4 lib/futurism/channel.rb
futurism-1.2.0.pre3 lib/futurism/channel.rb
futurism-1.2.0.pre2 lib/futurism/channel.rb
futurism-1.2.0.pre1 lib/futurism/channel.rb
futurism-1.1.0 lib/futurism/channel.rb
futurism-1.0.1 lib/futurism/channel.rb
futurism-1.0.0 lib/futurism/channel.rb