1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/action_cable/remote_connection.rb

34 lines
802 B
Ruby
Raw Normal View History

module ActionCable
class RemoteConnection
class InvalidIdentifiersError < StandardError; end
include Connection::Identification, Connection::InternalChannel
def initialize(server, ids)
@server = server
set_identifier_instance_vars(ids)
end
def disconnect
server.broadcast_without_logging internal_redis_channel, type: 'disconnect'
end
def identifiers
server.connection_identifiers
end
private
attr_reader :server
def set_identifier_instance_vars(ids)
raise InvalidIdentifiersError unless valid_identifiers?(ids)
ids.each { |k,v| instance_variable_set("@#{k}", v) }
end
def valid_identifiers?(ids)
keys = ids.keys
identifiers.all? { |id| keys.include?(id) }
end
end
end