Skip to content

Instantly share code, notes, and snippets.

@lwille
Forked from gstark/sqlgrowler.rb
Created March 20, 2010 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lwille/338650 to your computer and use it in GitHub Desktop.
Save lwille/338650 to your computer and use it in GitHub Desktop.
module SQLGrowler
class Subscriber < ActiveRecord::Railties::Subscriber
attr :prev_subscriber
def initialize prev
@prev_subscriber = prev
@g = Growl.new("localhost", "ruby-growl", ["ruby-growl Notification"], ["ruby-growl Notification"], nil)
end
def sql(event)
super
@g.notify('ruby-growl Notification',Rails.application.root.split().last.to_s.capitalize,'%s (%.1fms) %s' % [event.payload[:name], event.duration, event.payload[:sql].squeeze(' ')],1,true)
end
end
def self.enable
if Growl
Rails::Subscriber.add :active_record, SQLGrowler::Subscriber.new(Rails::Subscriber.subscribers[:active_record])
end
end
def self.disable
if Rails::Subscriber.subscribers[:active_record].instance_of? SQLGrowler::Subscriber
Rails::Subscriber.add :active_record, Rails::Subscriber.subscribers[:active_record].prev_subscriber
end
end
end
@dwormuth
Copy link

Where should this file live? Can you give an example of then starting and stopping it?

@lwille
Copy link
Author

lwille commented Jul 23, 2010

Just save it to config/initializers/.
Then start script/console and run SQLGrowler::enable/disable.

@dwormuth
Copy link

Not so sure this still works in Rails 3.0.1. Doesn't seem to like ActiveRecord::Railties::Subscriber and Rails::Subscriber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment