class WebsocketRails::UserManager::RemoteConnection
Attributes
user[R]
user_identifier[R]
Public Class Methods
new(identifier, user_hash)
click to toggle source
# File lib/websocket_rails/user_manager.rb, line 195 def initialize(identifier, user_hash) @user_identifier = identifier.to_s @user_hash = user_hash end
Public Instance Methods
connected?()
click to toggle source
# File lib/websocket_rails/user_manager.rb, line 200 def connected? true end
send_message(event_name, data = {}, options = {})
click to toggle source
# File lib/websocket_rails/user_manager.rb, line 208 def send_message(event_name, data = {}, options = {}) options.merge! :user_id => @user_identifier options[:data] = data event = Event.new(event_name, options) # If the user is connected to this worker, trigger the event # immediately as the event will be ignored by the Synchronization ## dispatcher since the server_token will match. if connection = WebsocketRails.users.users[@user_identifier] connection.trigger event end # Still publish the event in case the user is connected to # other workers as well. # # No need to check for Synchronization being enabled here. # If a RemoteConnection has been fetched, Synchronization # must be enabled. Synchronization.publish event true end
Private Instance Methods
load_user()
click to toggle source
# File lib/websocket_rails/user_manager.rb, line 233 def load_user user = WebsocketRails.config.user_class.new set_user_attributes user, @user_hash user end
set_user_attributes(user, attr)
click to toggle source
# File lib/websocket_rails/user_manager.rb, line 239 def set_user_attributes(user, attr) attr.each do |k, v| user.send "#{k}=", v end user.instance_variable_set(:@new_record, false) user.instance_variable_set(:@destroyed, false) end