class RailsGrip

Public Class Methods

get_wscontext(request) click to toggle source
# File lib/rails_grip.rb, line 45
def self.get_wscontext(request)
  if request.env.key?('grip_wscontext')
    return request.env['grip_wscontext']
  end
  return nil
end
is_grip_proxied(request) click to toggle source
# File lib/rails_grip.rb, line 38
def self.is_grip_proxied(request)
  if request.env.key?('grip_proxied')
    return request.env['grip_proxied']
  end
  return false
end
publish(channel, formats, id=nil, prev_id=nil) click to toggle source
# File lib/rails_grip.rb, line 15
def self.publish(channel, formats, id=nil, prev_id=nil)
  pub = RailsGrip.get_pubcontrol
  pub.publish(RailsSettings.get_prefix + channel, Item.new(
      formats, id, prev_id))
end
publish_async(channel, formats, id=nil, prev_id=nil, callback=nil) click to toggle source
# File lib/rails_grip.rb, line 21
def self.publish_async(channel, formats, id=nil, prev_id=nil, callback=nil)
  pub = RailsGrip.get_pubcontrol
  pub.publish_async(RailsSettings.get_prefix + channel, 
      Item.new(formats, id, prev_id), callback)
end
set_hold_longpoll(request, channels, timeout=nil) click to toggle source
# File lib/rails_grip.rb, line 27
def self.set_hold_longpoll(request, channels, timeout=nil)
  request.env['grip_hold'] = 'response'
  request.env['grip_channels'] = RailsGrip.convert_channels(channels)
  request.env['grip_timeout'] = timeout
end
set_hold_stream(request, channels) click to toggle source
# File lib/rails_grip.rb, line 33
def self.set_hold_stream(request, channels)
  request.env['grip_hold'] = 'stream'
  request.env['grip_channels'] = RailsGrip.convert_channels(channels)
end
verify_is_websocket(request) click to toggle source
# File lib/rails_grip.rb, line 52
def self.verify_is_websocket(request)
  if !RailsGrip.get_wscontext(request)
    raise NonWebSocketRequestError
  end
end

Private Class Methods

convert_channels(channels) click to toggle source
# File lib/rails_grip.rb, line 77
def self.convert_channels(channels)
  if channels.is_a?(Channel) or channels.is_a?(String)
    channels = [channels]
  end
  out = []
  channels.each do |channel|
    if channel.is_a?(String)
      channel = Channel.new(channel)
    end
    out.push(channel)
  end
  return out
end
get_pubcontrol() click to toggle source
# File lib/rails_grip.rb, line 60
def self.get_pubcontrol
  if Thread.current['pubcontrol'].nil?
    pub = GripPubControl.new
    grip_proxies = RailsSettings.get_grip_proxies
    publish_servers = RailsSettings.get_publish_servers
    if !grip_proxies.nil?
      pub.apply_grip_config(grip_proxies)
    end
    if !publish_servers.nil?
      pub.apply_config(publish_servers)
    end
    at_exit { pub.finish }
    Thread.current['pubcontrol'] = pub
  end
  return Thread.current['pubcontrol']
end