-
-
Save lwille/338650 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Just save it to config/initializers/.
Then start script/console and run SQLGrowler::enable/disable.
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
Where should this file live? Can you give an example of then starting and stopping it?