Sha256: fc5a60d0633e9156c6a8d3204d3e0411a0650c81c88f908a294fc50ebb050dce

Contents?: true

Size: 492 Bytes

Versions: 10

Compression:

Stored size: 492 Bytes

Contents

class JuggernautObserver < ActiveRecord::Observer
  observe :activity, :user
  
  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.sync_clients).map {|c| "/sync/#{c}" }, 
        {:type => type, :id => rec.id, 
         :klass => rec.class.name, :record => rec}
      )
    end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
juggernaut-kafka-2.1.2 examples/juggernaut_observer.rb
juggernaut-2.1.1 examples/juggernaut_observer.rb
juggernaut-2.1.0 examples/juggernaut_observer.rb
juggernaut-2.0.4 examples/juggernaut_observer.rb
juggernaut-2.0.3 examples/juggernaut_observer.rb
juggernaut-2.0.2 examples/juggernaut_observer.rb
juggernaut-2.0.1 examples/juggernaut_observer.rb
juggernaut-2.0.0 examples/juggernaut_observer.rb
juggernaut-2.0.0.beta3 examples/juggernaut_observer.rb
juggernaut-2.0.0.beta2 examples/juggernaut_observer.rb