Sha256: 4bc2ecd81de25f8896737caad2c08ec65596f851167a26e200cee2130bfd7d90

Contents?: true

Size: 901 Bytes

Versions: 13

Compression:

Stored size: 901 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") { |_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|
        cable_ready[stream_name].outer_html(
          selector: selector,
          html: html
        )
      end

      cable_ready.broadcast
    end
  end
end

Version data entries

13 entries across 13 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~
futurism-0.8.0 lib/futurism/channel.rb