1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actioncable/test/stubs/test_adapter.rb
Zhang Kang 96b74fe433 Introduce ActionCable::Channel#stop_stream_from/for to unsubscribe specific streams (#37171)
* Like `ActionCable::Channel#stop_all_streams`, but for specific streams
2020-01-17 13:39:06 -08:00

21 lines
650 B
Ruby

# frozen_string_literal: true
class SuccessAdapter < ActionCable::SubscriptionAdapter::Base
def broadcast(channel, payload)
end
def subscribe(channel, callback, success_callback = nil)
subscriber_map[channel] << callback
@@subscribe_called = { channel: channel, callback: callback, success_callback: success_callback }
end
def unsubscribe(channel, callback)
subscriber_map[channel].delete(callback)
subscriber_map.delete(channel) if subscriber_map[channel].empty?
@@unsubscribe_called = { channel: channel, callback: callback }
end
def subscriber_map
@subscribers ||= Hash.new { |h, k| h[k] = [] }
end
end