Sha256: 40dae897be595c8b4aeb917f4492931914aaef65531d912592af3799c8e408f5

Contents?: true

Size: 1.18 KB

Versions: 31

Compression:

Stored size: 1.18 KB

Contents

# Stream names are how we identify which updates should go to which users. All streams run over the same
# <tt>Turbo::StreamsChannel</tt>, but each with their own subscription. Since stream names are exposed directly to the user
# via the HTML stream subscription tags, we need to ensure that the name isn't tampered with, so the names are signed
# upon generation and verified upon receipt. All verification happens through the <tt>Turbo.signed_stream_verifier</tt>.
module Turbo::Streams::StreamName
  # Used by <tt>Turbo::StreamsChannel</tt> to verify a signed stream name.
  def verified_stream_name(signed_stream_name)
    Turbo.signed_stream_verifier.verified signed_stream_name
  end

  # Used by <tt>Turbo::StreamsHelper#turbo_stream_from(*streamables)</tt> to generate a signed stream name.
  def signed_stream_name(streamables)
    Turbo.signed_stream_verifier.generate stream_name_from(streamables)
  end

  private
    def stream_name_from(streamables)
      if streamables.is_a?(Array)
        streamables.map  { |streamable| stream_name_from(streamable) }.join(":")
      else
        streamables.then { |streamable| streamable.try(:to_gid_param) || streamable.to_param }
      end
    end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
turbo-rails-0.8.1 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.8.0 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.15 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.14 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.13 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.12 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.11 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.10 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.9 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.8 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.7 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.6 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.5 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.4 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.2 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.1 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.7.0 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.6.0 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.5.12 app/channels/turbo/streams/stream_name.rb
turbo-rails-0.5.11 app/channels/turbo/streams/stream_name.rb