class EventMachine::WebSocket::Connection

Attributes

browser_id[RW]

Public Instance Methods

[]( name = nil ) click to toggle source
# File lib/nali/connection.rb, line 29
def []( name = nil )
  name ? ( storage[ name ] or nil ) : storage
end
[]=( name, value ) click to toggle source
# File lib/nali/connection.rb, line 33
def []=( name, value )
  storage[ name ] = value
end
all_tabs() { |client| ... } click to toggle source
# File lib/nali/connection.rb, line 7
def all_tabs
  Nali::Clients.list
    .select { |client| client.browser_id == self.browser_id }
    .each{ |client| yield( client ) if block_given? }
end
app_run( method, params = nil ) click to toggle source
# File lib/nali/connection.rb, line 106
def app_run( method, params = nil )
  send_json action: :_appRun, method: method, params: params
  self
end
call_method( method, model, params = nil ) click to toggle source
# File lib/nali/connection.rb, line 80
def call_method( method, model, params = nil )
  model = "#{ model.class.name }.#{ model.id }" if model.is_a?( ActiveRecord::Base )
  send_json action: :_callMethod, model: model, method: method, params: params
  self
end
error( params ) click to toggle source
# File lib/nali/connection.rb, line 101
def error( params )
  notice :error, params
  self
end
info( params ) click to toggle source
# File lib/nali/connection.rb, line 91
def info( params )
  notice :info, params
  self
end
notice( method, params = nil ) click to toggle source
# File lib/nali/connection.rb, line 86
def notice( method, params = nil )
  call_method method, :Notice, params
  self
end
other_tabs() { |client| ... } click to toggle source
# File lib/nali/connection.rb, line 13
def other_tabs
  Nali::Clients.list
    .select { |client| client != self and client.browser_id == self.browser_id }
    .each{ |client| yield( client ) if block_given? }
end
reset() click to toggle source
# File lib/nali/connection.rb, line 19
def reset
  @storage = {} 
  @watches = {} 
  self
end
send_json( hash ) click to toggle source
# File lib/nali/connection.rb, line 61
def send_json( hash )
  send hash.to_json
  self
end
storage() click to toggle source
# File lib/nali/connection.rb, line 25
def storage
  @storage ||= {} 
end
sync( *models ) click to toggle source
# File lib/nali/connection.rb, line 66
def sync( *models )
  models.flatten.compact.each do |model|
    if watch_time( model ) < model.updated_at.to_f or model.destroyed?
      params, relations = model.get_sync_params( self )
      unless params.empty?
        if model.destroyed? then unwatch( model ) else watch_time_up model end
        relations.each { |relation| sync relation }
        send_json action: :_sync, params: params
      end
    end
  end
  self
end
unwatch( model ) click to toggle source
# File lib/nali/connection.rb, line 45
def unwatch( model )
  watches.delete model.class.name + model.id.to_s
end
warning( params ) click to toggle source
# File lib/nali/connection.rb, line 96
def warning( params )
  notice :warning, params
  self
end
watch( model ) click to toggle source
# File lib/nali/connection.rb, line 41
def watch( model )
  watches[ model.class.name + model.id.to_s ] ||= 0
end
watch?( model ) click to toggle source
# File lib/nali/connection.rb, line 49
def watch?( model )
  if watches[ model.class.name + model.id.to_s ] then true else false end
end
watch_time( model ) click to toggle source
# File lib/nali/connection.rb, line 53
def watch_time( model )
  watches[ model.class.name + model.id.to_s ] or 0
end
watch_time_up( model ) click to toggle source
# File lib/nali/connection.rb, line 57
def watch_time_up( model )
  watches[ model.class.name + model.id.to_s ] = model.updated_at.to_f
end
watches() click to toggle source
# File lib/nali/connection.rb, line 37
def watches
  @watches ||= {} 
end