class FayeRails::Controller::Channel

Attributes

channel[R]
endpoint[R]

Public Class Methods

new(channel, endpoint=nil) click to toggle source
# File lib/faye-rails/controller/channel.rb, line 7
def initialize(channel, endpoint=nil)
  @channel = channel
  @endpoint = endpoint
end

Public Instance Methods

client() click to toggle source
# File lib/faye-rails/controller/channel.rb, line 12
def client
  FayeRails.client(endpoint)
end
filter(direction=:any, &block) click to toggle source
# File lib/faye-rails/controller/channel.rb, line 33
def filter(direction=:any, &block)
  filter = FayeRails::Filter.new(channel, direction, block)
  server = FayeRails.server(endpoint)
  server.add_extension(filter)
  filter.server = server
  filter
end
monitor(event, &block) click to toggle source
# File lib/faye-rails/controller/channel.rb, line 20
def monitor(event, &block)
  raise ArgumentError, "Unknown event #{event.inspect}" unless [:subscribe,:unsubscribe,:publish].member? event

  FayeRails.server(endpoint).bind(event) do |*args|
    Monitor.new.tap do |m|
      m.client_id = args.shift
      m.channel = args.shift
      m.data = args.shift
      m.instance_eval(&block) if FayeRails::Matcher.match? channel, m.channel
    end
  end
end
publish(message) click to toggle source
# File lib/faye-rails/controller/channel.rb, line 16
def publish(message)
  client.publish(channel, message)
end
subscribe(&block) click to toggle source
# File lib/faye-rails/controller/channel.rb, line 41
def subscribe(&block)
  EM.schedule do
    FayeRails.client(endpoint).subscribe(channel) do |message|
      Message.new.tap do |m|
        m.message = message
        m.channel = channel
        m.instance_eval(&block)
      end
    end
  end
end
unsubscribe() click to toggle source
# File lib/faye-rails/controller/channel.rb, line 53
def unsubscribe
  EM.schedule do
    FayeRails.client(endpoint).unsubscribe(channel)
  end
end