Skip to content
Browse files

Merge pull request #7 from kosmatov/master

Airbrake notifier
  • Loading branch information...
2 parents 1e97e05 + ef41a17 commit df4f146225252f69d88f36131b1bd438ef7dfeab @flyerhzm committed Sep 27, 2012
Showing with 43 additions and 4 deletions.
  1. +9 −2 README.md
  2. +3 −2 lib/uniform_notifier.rb
  3. +13 −0 lib/uniform_notifier/airbrake.rb
  4. +18 −0 spec/uniform_notifier/airbrake_spec.rb
View
11 README.md
@@ -1,7 +1,7 @@
UniformNotifier
===============
-uniform_notifier is extracted from [bullet][0], it gives you the ability to send notification through rails logger, customized logger, javascript alert, javascript console, growl, and xmpp.
+uniform_notifier is extracted from [bullet][0], it gives you the ability to send notification through rails logger, customized logger, javascript alert, javascript console, growl, xmpp and airbrake.
Install
-------
@@ -22,11 +22,15 @@ if you want to notify by xmpp, you should install xmpp4r first
gem install xmpp4r
+if you want to notify by airbrake, you should install airbrake first
+
+ gem install airbrake
+
### add it into Gemfile (Bundler)
gem "uniform_notifier"
- you should add ruby-growl, ruby_gntp, or xmpp4r gem if you want.
+ you should add ruby-growl, ruby_gntp, xmpp4r, airbrake gem if you want.
Usage
-----
@@ -46,6 +50,9 @@ By default, all notifiers are disabled, you should enable them first.
# rails logger
UniformNotifier.rails_logger = true
+ # airbrake
+ UniformNotifier.airbrake = true
+
# customized logger
logger = File.open('notify.log', 'a+')
logger.sync = true
View
5 lib/uniform_notifier.rb
@@ -5,14 +5,15 @@
require 'uniform_notifier/xmpp'
require 'uniform_notifier/rails_logger'
require 'uniform_notifier/customized_logger'
+require 'uniform_notifier/airbrake'
module UniformNotifier
class NotificationError < StandardError; end
class <<self
- attr_accessor :alert, :console, :growl, :rails_logger, :xmpp
+ attr_accessor :alert, :console, :growl, :rails_logger, :xmpp, :airbrake
- NOTIFIERS = [JavascriptAlert, JavascriptConsole, Growl, Xmpp, RailsLogger, CustomizedLogger]
+ NOTIFIERS = [JavascriptAlert, JavascriptConsole, Growl, Xmpp, RailsLogger, CustomizedLogger, AirbrakeNotifier]
def active_notifiers
NOTIFIERS.select { |notifier| notifier.active? }
View
13 lib/uniform_notifier/airbrake.rb
@@ -0,0 +1,13 @@
+module UniformNotifier
+ class AirbrakeNotifier < Base
+ def self.active?
+ UniformNotifier.airbrake
+ end
+
+ def self.out_of_channel_notify(message)
+ return unless active?
+ exception = Exception.new(message)
+ Airbrake.notify(exception)
+ end
+ end
+end
View
18 spec/uniform_notifier/airbrake_spec.rb
@@ -0,0 +1,18 @@
+require "spec_helper"
+
+class Airbrake
+ # mock Airbrake
+end
+
+describe UniformNotifier::AirbrakeNotifier do
+ it "should not notify airbrake" do
+ UniformNotifier::AirbrakeNotifier.out_of_channel_notify("notify airbrake").should be_nil
+ end
+
+ it "should notify airbrake" do
+ Airbrake.should_receive(:notify).with(Exception.new("notify airbrake"))
+
+ UniformNotifier.airbrake = true
+ UniformNotifier::AirbrakeNotifier.out_of_channel_notify("notify airbrake")
+ end
+end

0 comments on commit df4f146

Please sign in to comment.
Something went wrong with that request. Please try again.