Sha256: 1f0dd614af763425d24b681bec20170502aee86cdeec3e6d50503126c788b560

Contents?: true

Size: 1.24 KB

Versions: 75

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require "active_support/core_ext/object/to_param"

module ActionCable
  module Channel
    module Broadcasting
      extend ActiveSupport::Concern

      delegate :broadcasting_for, :broadcast_to, to: :class

      module ClassMethods
        # Broadcast a hash to a unique broadcasting for this <tt>model</tt> in this channel.
        def broadcast_to(model, message)
          ActionCable.server.broadcast(broadcasting_for(model), message)
        end

        # Returns a unique broadcasting identifier for this <tt>model</tt> in this channel:
        #
        #    CommentsChannel.broadcasting_for("all") # => "comments:all"
        #
        # You can pass any object as a target (e.g. Active Record model), and it
        # would be serialized into a string under the hood.
        def broadcasting_for(model)
          serialize_broadcasting([ channel_name, model ])
        end

        def serialize_broadcasting(object) #:nodoc:
          case
          when object.is_a?(Array)
            object.map { |m| serialize_broadcasting(m) }.join(":")
          when object.respond_to?(:to_gid_param)
            object.to_gid_param
          else
            object.to_param
          end
        end
      end
    end
  end
end

Version data entries

75 entries across 75 versions & 7 rubygems

Version Path
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/actioncable-6.0.2.1/lib/action_cable/channel/broadcasting.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/actioncable-6.0.2.1/lib/action_cable/channel/broadcasting.rb
actioncable-6.0.2.1 lib/action_cable/channel/broadcasting.rb
actioncable-6.0.2 lib/action_cable/channel/broadcasting.rb
actioncable-6.0.2.rc2 lib/action_cable/channel/broadcasting.rb
actioncable-6.0.2.rc1 lib/action_cable/channel/broadcasting.rb
actioncable-6.0.1 lib/action_cable/channel/broadcasting.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/actioncable-6.0.0/lib/action_cable/channel/broadcasting.rb
actioncable-6.0.1.rc1 lib/action_cable/channel/broadcasting.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/actioncable-6.0.0/lib/action_cable/channel/broadcasting.rb
actioncable-6.0.0 lib/action_cable/channel/broadcasting.rb
actioncable-6.0.0.rc2 lib/action_cable/channel/broadcasting.rb
actioncable-6.0.0.rc1 lib/action_cable/channel/broadcasting.rb
actioncable-6.0.0.beta3 lib/action_cable/channel/broadcasting.rb
actioncable-6.0.0.beta2 lib/action_cable/channel/broadcasting.rb