hatchet-airbrake 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,45 @@
1
+ module Hatchet
2
+ class AirbrakeAppender
3
+ include LevelManager
4
+
5
+ # Public: The name to post the messages as (default: Hatchet).
6
+ #
7
+ attr_accessor :name
8
+
9
+ # Public: The formatter used to format messages before sending them to Airbrake
10
+ #
11
+ attr_accessor :formatter
12
+
13
+ # Public: Creates a new instance.
14
+ #
15
+ # By default the appender is created with a SimpleFormatter.
16
+ #
17
+ # block - Optional block that can be used to customize the appender. The
18
+ # appender itself is passed to the block.
19
+ #
20
+ def initialize
21
+ @name = 'Hatchet-Airbrake'
22
+ @formatter = SimpleFormatter.new
23
+ yield self if block_given?
24
+ end
25
+
26
+ # Internal: Sends an error to Airbrake.
27
+ #
28
+ # level - The level of the message.
29
+ # context - The context of the message.
30
+ # message - The unformatted message.
31
+ #
32
+ # Returns nothing.
33
+ #
34
+ def add(level, context, message)
35
+ if message.error
36
+ opts = {
37
+ :error_message => message.to_s,
38
+ :backtrace => message.error.backtrace
39
+ }
40
+ ::Airbrake.notify message.error, opts
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module HatchetAirbrake
2
+ VERSION = "0.0.1".freeze
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'airbrake'
2
+ require 'hatchet'
3
+ require 'hatchet_airbrake/version'
4
+ require 'hatchet_airbrake/airbrake_appender'
@@ -0,0 +1,37 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe "AirbrakeAppender" do
4
+ describe "#add" do
5
+ before(:each) do
6
+ @appender = Hatchet::AirbrakeAppender.new
7
+ @level = random_string
8
+ @context = random_string
9
+ @error = StandardError.new
10
+ @backtrace = [random_string, random_string]
11
+ @error.stub(:backtrace) { @backtrace }
12
+
13
+ @message = Hatchet::Message.new(@error_message = random_string, @error)
14
+ end
15
+
16
+ subject { @appender.add(@level, @context, @message) }
17
+
18
+ it "should notify airbrake" do
19
+ expected_options = {
20
+ :error_message => @error_message,
21
+ :backtrace => @backtrace
22
+ }
23
+ ::Airbrake.should_receive(:notify).with(@error, expected_options)
24
+ subject
25
+ end
26
+
27
+ context "when error is not present" do
28
+ before(:each) do
29
+ @message = Hatchet::Message.new(random_string)
30
+ end
31
+ it "should not notify airbrake" do
32
+ ::Airbrake.should_not_receive(:notify)
33
+ subject
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ require_relative '../lib/hatchet_airbrake'
2
+ require 'rspec'
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ end
7
+
8
+ def random_string
9
+ (0...24).map{ ('a'..'z').to_a[rand(26)] }.join
10
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hatchet-airbrake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Bird
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: airbrake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.6
30
+ - !ruby/object:Gem::Dependency
31
+ name: hatchet
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.17
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.17
46
+ description: Hatchet appender for posting errors to airbrake
47
+ email: adam.bird@gmail.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - lib/hatchet_airbrake/airbrake_appender.rb
53
+ - lib/hatchet_airbrake/version.rb
54
+ - lib/hatchet_airbrake.rb
55
+ - spec/airbrake_appender_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: http://github.com/adambird/hatchet-airbrake
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.24
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Hatchet appender for posting errors to airbrake
81
+ test_files:
82
+ - spec/airbrake_appender_spec.rb
83
+ - spec/spec_helper.rb