bullhorn 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +2 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bullhorn.gemspec +5 -3
- data/lib/bullhorn.rb +20 -6
- data/lib/bullhorn/plugin.rb +1 -1
- data/lib/bullhorn/sender.rb +2 -2
- data/test/test_bullhorn.rb +80 -1
- data/test/test_ignore_exceptions.rb +5 -0
- metadata +5 -3
data/README.rdoc
CHANGED
@@ -33,7 +33,7 @@ See http://bullhorn.it and signup for a free account!
|
|
33
33
|
:filters => %w(password password_confirmation credit_card)
|
34
34
|
|
35
35
|
== Rails 2.3.5 backward compatibility
|
36
|
-
|
36
|
+
|
37
37
|
# in config/environment.rb
|
38
38
|
|
39
39
|
config.gem 'bullhorn'
|
@@ -61,4 +61,4 @@ See http://bullhorn.it and signup for a free account!
|
|
61
61
|
|
62
62
|
== Copyright
|
63
63
|
|
64
|
-
Copyright (c) 2010 Cyril David. See LICENSE for details.
|
64
|
+
Copyright (c) 2010 Cyril David. See LICENSE for details.
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/bullhorn.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bullhorn}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Cyril David"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-17}
|
13
13
|
s.description = %q{drop in rack middleware for bullhorn.it}
|
14
14
|
s.email = %q{cyx.ucron@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -81,7 +81,8 @@ Gem::Specification.new do |s|
|
|
81
81
|
"lib/bullhorn/sender.rb",
|
82
82
|
"test/helper.rb",
|
83
83
|
"test/test_bullhorn.rb",
|
84
|
-
"test/test_bullhorn_plugin.rb"
|
84
|
+
"test/test_bullhorn_plugin.rb",
|
85
|
+
"test/test_ignore_exceptions.rb"
|
85
86
|
]
|
86
87
|
s.homepage = %q{http://github.com/sinefunc/bullhorn}
|
87
88
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -92,6 +93,7 @@ Gem::Specification.new do |s|
|
|
92
93
|
"test/helper.rb",
|
93
94
|
"test/test_bullhorn.rb",
|
94
95
|
"test/test_bullhorn_plugin.rb",
|
96
|
+
"test/test_ignore_exceptions.rb",
|
95
97
|
"examples/foobar/app/controllers/application_controller.rb",
|
96
98
|
"examples/foobar/app/controllers/raiser_controller.rb",
|
97
99
|
"examples/foobar/app/helpers/application_helper.rb",
|
data/lib/bullhorn.rb
CHANGED
@@ -18,14 +18,16 @@ class Bullhorn
|
|
18
18
|
attr :filters
|
19
19
|
attr :api_key
|
20
20
|
attr :url
|
21
|
+
attr :ignore_exceptions
|
21
22
|
|
22
23
|
include Sender
|
23
24
|
|
24
25
|
def initialize(app, options = {})
|
25
|
-
@app
|
26
|
-
@api_key
|
27
|
-
@filters
|
28
|
-
@url
|
26
|
+
@app = app
|
27
|
+
@api_key = options[:api_key] || raise(ArgumentError, ":api_key is required")
|
28
|
+
@filters = Array(options[:filters])
|
29
|
+
@url = options[:url] || URL
|
30
|
+
@ignore_exceptions = Array(options[:ignore_exceptions] || default_ignore_exceptions)
|
29
31
|
end
|
30
32
|
|
31
33
|
def call(env)
|
@@ -33,10 +35,22 @@ class Bullhorn
|
|
33
35
|
begin
|
34
36
|
@app.call(env)
|
35
37
|
rescue Exception => ex
|
36
|
-
|
38
|
+
unless ignore_exceptions.include?(ex.class)
|
39
|
+
notify ex, env
|
40
|
+
end
|
41
|
+
|
37
42
|
raise ex
|
38
43
|
end
|
39
44
|
|
40
45
|
[status, headers, body]
|
41
46
|
end
|
42
|
-
|
47
|
+
|
48
|
+
protected
|
49
|
+
def default_ignore_exceptions
|
50
|
+
[].tap do |exceptions|
|
51
|
+
exceptions << ActiveRecord::RecordNotFound if defined? ActiveRecord
|
52
|
+
exceptions << AbstractController::ActionNotFound if defined? AbstractController
|
53
|
+
exceptions << ActionController::RoutingError if defined? ActionController
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/bullhorn/plugin.rb
CHANGED
@@ -25,7 +25,7 @@ class Bullhorn
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def notify_with_bullhorn!(exception)
|
28
|
-
unless Bullhorn::Plugin.ignored_exceptions.include?(exception)
|
28
|
+
unless Bullhorn::Plugin.ignored_exceptions.include?(exception.class)
|
29
29
|
bullhorn = Bullhorn.new(self, Bullhorn::Plugin.options)
|
30
30
|
bullhorn.notify(exception, request.env)
|
31
31
|
end
|
data/lib/bullhorn/sender.rb
CHANGED
data/test/test_bullhorn.rb
CHANGED
@@ -103,4 +103,83 @@ class TestBullhorn < Test::Unit::TestCase
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
|
+
context "given ignore_exceptions" do
|
108
|
+
IgnoredError = Class.new(StandardError)
|
109
|
+
RaisedError = Class.new(StandardError)
|
110
|
+
|
111
|
+
setup do
|
112
|
+
@app = lambda { |env| raise IgnoredError, "Ignored!" }
|
113
|
+
|
114
|
+
@bullhorn = Bullhorn.new(@app, :api_key => "_key_",
|
115
|
+
:ignore_exceptions => [IgnoredError])
|
116
|
+
|
117
|
+
FakeWeb.allow_net_connect = false
|
118
|
+
end
|
119
|
+
|
120
|
+
should "not notify the server of the exception" do
|
121
|
+
assert_raise IgnoredError do
|
122
|
+
@bullhorn.call({})
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
should "notify when raising RaisedError" do
|
127
|
+
@app = lambda { |env| raise RaisedError, "Raised!" }
|
128
|
+
|
129
|
+
@bullhorn = Bullhorn.new(@app, :api_key => "_key_",
|
130
|
+
:ignore_exceptions => [IgnoredError])
|
131
|
+
|
132
|
+
assert_raise RaisedError, FakeWeb::NetConnectNotAllowedError do
|
133
|
+
@bullhorn.call({})
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "when ActiveRecord exists" do
|
139
|
+
module ::ActiveRecord
|
140
|
+
RecordNotFound = Class.new(StandardError)
|
141
|
+
end
|
142
|
+
|
143
|
+
teardown do
|
144
|
+
Object.send :remove_const, :ActiveRecord
|
145
|
+
end
|
146
|
+
|
147
|
+
should "include it in the default ignore_exceptions by default" do
|
148
|
+
bullhorn = Bullhorn.new(lambda {}, :api_key => "_key")
|
149
|
+
|
150
|
+
assert bullhorn.ignore_exceptions.include?(ActiveRecord::RecordNotFound)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "when AbstractController exists" do
|
155
|
+
module ::AbstractController
|
156
|
+
ActionNotFound = Class.new(StandardError)
|
157
|
+
end
|
158
|
+
|
159
|
+
teardown do
|
160
|
+
Object.send :remove_const, :AbstractController
|
161
|
+
end
|
162
|
+
|
163
|
+
should "include it in the default ignore_exceptions" do
|
164
|
+
bh = Bullhorn.new(lambda {}, :api_key => "_key")
|
165
|
+
|
166
|
+
assert bh.ignore_exceptions.include?(AbstractController::ActionNotFound)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context "when ActionController exists" do
|
171
|
+
module ::ActionController
|
172
|
+
RoutingError = Class.new(StandardError)
|
173
|
+
end
|
174
|
+
|
175
|
+
teardown do
|
176
|
+
Object.send :remove_const, :ActionController
|
177
|
+
end
|
178
|
+
|
179
|
+
should "include it in the default ignored_exceptions" do
|
180
|
+
bh = Bullhorn.new(lambda {}, :api_key => "_key")
|
181
|
+
|
182
|
+
assert bh.ignore_exceptions.include?(ActionController::RoutingError)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Cyril David
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-17 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- test/helper.rb
|
141
141
|
- test/test_bullhorn.rb
|
142
142
|
- test/test_bullhorn_plugin.rb
|
143
|
+
- test/test_ignore_exceptions.rb
|
143
144
|
has_rdoc: true
|
144
145
|
homepage: http://github.com/sinefunc/bullhorn
|
145
146
|
licenses: []
|
@@ -174,6 +175,7 @@ test_files:
|
|
174
175
|
- test/helper.rb
|
175
176
|
- test/test_bullhorn.rb
|
176
177
|
- test/test_bullhorn_plugin.rb
|
178
|
+
- test/test_ignore_exceptions.rb
|
177
179
|
- examples/foobar/app/controllers/application_controller.rb
|
178
180
|
- examples/foobar/app/controllers/raiser_controller.rb
|
179
181
|
- examples/foobar/app/helpers/application_helper.rb
|