Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: original
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 36 lines (31 sloc) 0.865 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
class JuggernautObserver < ActiveModel::Observer
  observe :roster, :channel_activity
    
  def after_create(rec)
    publish(:create, rec)
  end
  
  def after_update(rec)
    publish(:update, rec)
  end
  
  def after_destroy(rec)
    publish(:destroy, rec)
  end
  
  protected
    def publish(type, rec)
      Juggernaut.publish(
        Array(rec.observer_clients).map {|c| "/observer/#{c}" },
        {
          :type => type, :id => rec.id,
          :klass => rec.class.name, :record => rec
        },
        :except => current_session_id
      )
    end
    
    # The client's current Juggernaut sessionID.
    # We don't want messages generated from clients
    # to be send back to those clients.
    def current_session_id
      return unless UserSession.activated?
      session = UserSession.find
      session && session.session_id
    end
end
Something went wrong with that request. Please try again.