class FayeRails::Controller

Attributes

channels[RW]

Public Class Methods

channel(channel, endpoint=nil, &block) click to toggle source

Bind a number of events to a specific channel.

# File lib/faye-rails/controller.rb, line 32
def self.channel(channel, endpoint=nil, &block)
  channel = Channel.new(channel, endpoint)
  channel.instance_eval(&block)
  (@channels ||= []) << channel
end
observe(model_klass, action = :after_create, &block) click to toggle source

Observe a model for any of the ActiveRecord::Callbacks as of v3.2.6 they are: before_validation after_validation before_save before_create after_create after_save after_commit api.rubyonrails.org/classes/ActiveRecord/Callbacks.html action defaults to after_create

# File lib/faye-rails/controller.rb, line 21
def self.observe(model_klass, action = :after_create, &block)
  # Dynamically create a new observe class
  ObserverFactory.define(model_klass, action, &block)
end
publish(channel, message, endpoint=nil) click to toggle source
# File lib/faye-rails/controller.rb, line 44
def self.publish(channel, message, endpoint=nil)
  FayeRails.client(endpoint).publish(channel, message)
end

Public Instance Methods

channel(channel, endpoint=nil, &block) click to toggle source
# File lib/faye-rails/controller.rb, line 38
def channel(channel, endpoint=nil, &block)
  channel = Channel.new(channel, endpoint)
  channel.instance_eval(&block)
  (@channels ||= []) << channel
end
observe(model_klass, action = :after_create, &block) click to toggle source
# File lib/faye-rails/controller.rb, line 26
def observe(model_klass, action = :after_create, &block)
  # Dynamically create a new observe class
  ObserverFactory.define(model_klass, action, &block)
end
publish(channel, message, endpoint=nil) click to toggle source
# File lib/faye-rails/controller.rb, line 48
def publish(channel, message, endpoint=nil)
  self.class.publish(channel, message, endpoint)
end