Class: FayeRails::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/faye-rails/controller.rb,
lib/faye-rails/controller/channel.rb,
lib/faye-rails/controller/message.rb,
lib/faye-rails/controller/monitor.rb,
lib/faye-rails/controller/observer_factory.rb

Defined Under Namespace

Modules: ObserverFactory Classes: Channel, Message, Monitor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



8
9
10
# File 'lib/faye-rails/controller.rb', line 8

def channels
  @channels
end

Class Method Details

.channel(channel, endpoint = nil, &block) ⇒ Object

Bind a number of events to a specific channel.



32
33
34
35
36
# 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) ⇒ Object

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



21
22
23
24
# 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) ⇒ Object



44
45
46
# File 'lib/faye-rails/controller.rb', line 44

def self.publish(channel, message, endpoint=nil)
  FayeRails.client(endpoint).publish(channel, message)
end

Instance Method Details

#channel(channel, endpoint = nil, &block) ⇒ Object



38
39
40
41
42
# 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) ⇒ Object



26
27
28
29
# 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) ⇒ Object



48
49
50
# File 'lib/faye-rails/controller.rb', line 48

def publish(channel, message, endpoint=nil)
  self.class.publish(channel, message, endpoint)
end