Sha256: 76abde12db96891bec86b97a41223bceafcbf950969feef2eded19dc2d0357c3

Contents?: true

Size: 1.42 KB

Versions: 34

Compression:

Stored size: 1.42 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

  module ClassMethods
    # Can be used by custom turbo stream channels to obtain signed stream name from <tt>params</tt>
    def verified_stream_name_from_params
      self.class.verified_stream_name(params[:signed_stream_name])
    end
  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

34 entries across 34 versions & 2 rubygems

Version Path
turbo-rails-2.0.11 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.10 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.9 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.8 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.7 app/channels/turbo/streams/stream_name.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/turbo-rails-2.0.5/app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.6 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.5 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.4 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.3 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.2 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.1 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.0 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.0.pre.rc.3 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.0.pre.rc.2 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.0.pre.rc.1 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.0.pre.beta.4 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.0.pre.beta.3 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.0.pre.beta.2 app/channels/turbo/streams/stream_name.rb
turbo-rails-2.0.0.pre.beta.1 app/channels/turbo/streams/stream_name.rb