Sha256: 21cf8b586da54be33de616aa76fa5ab2c33223e6895fbf5ca41a3a9f1a8993dc

Contents?: true

Size: 1.74 KB

Versions: 13

Compression:

Stored size: 1.74 KB

Contents

module FayeRails
  class Controller
    autoload :Channel, File.join(FayeRails::ROOT, 'faye-rails', 'controller', 'channel')
    autoload :Monitor, File.join(FayeRails::ROOT, 'faye-rails', 'controller', 'monitor')
    autoload :Message, File.join(FayeRails::ROOT, 'faye-rails', 'controller', 'message')
    autoload :ObserverFactory, File.join(FayeRails::ROOT, 'faye-rails', 'controller', 'observer_factory')

    attr :channels, :model

    # 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
    # http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
    # action defaults to after_create
    def self.observe(model_klass, action = :after_create, &block)
      # Dynamically create a new observe class
      ObserverFactory.define(model_klass, action, &block)
    end

    def observe(model_klass, action = :after_create, &block)
      # Dynamically create a new observe class
      ObserverFactory.define(model_klass, action, &block)
    end

    # Bind a number of events to a specific channel.
    def self.channel(channel, endpoint=nil, &block)
      channel = Channel.new(channel, endpoint)
      channel.instance_eval(&block)
      (@channels ||= []) << channel
    end

    def channel(channel, endpoint=nil, &block)
      channel = Channel.new(channel, endpoint)
      channel.instance_eval(&block)
      (@channels ||= []) << channel
    end

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

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

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
faye-rails-2.0.3 lib/faye-rails/controller.rb
faye-rails-2.0.1 lib/faye-rails/controller.rb
faye-rails-2.0.0 lib/faye-rails/controller.rb
faye-rails-1.0.10 lib/faye-rails/controller.rb
faye-rails-1.0.8 lib/faye-rails/controller.rb
faye-rails-1.0.7 lib/faye-rails/controller.rb
faye-rails-1.0.6 lib/faye-rails/controller.rb
faye-rails-1.0.5 lib/faye-rails/controller.rb
faye-rails-1.0.4 lib/faye-rails/controller.rb
faye-rails-1.0.3 lib/faye-rails/controller.rb
faye-rails-1.0.2 lib/faye-rails/controller.rb
faye-rails-1.0.1 lib/faye-rails/controller.rb
faye-rails-1.0.0 lib/faye-rails/controller.rb