yogi_berra 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/yogi_berra/action_controller_catcher.rb +0 -1
- data/lib/yogi_berra/catcher.rb +8 -3
- data/lib/yogi_berra/version.rb +1 -1
- data/spec/spec_helper.rb +18 -10
- data/spec/yogi_berra_catcher_spec.rb +24 -4
- data/spec/yogi_berra_data_spec.rb +1 -1
- data/spec/yogi_berra_exception_middleware_spec.rb +3 -3
- metadata +110 -80
- checksums.yaml +0 -15
data/lib/yogi_berra/catcher.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'mongo'
|
2
2
|
require 'facets'
|
3
3
|
require 'yaml'
|
4
|
+
require 'timeout'
|
4
5
|
|
5
6
|
module YogiBerra
|
6
7
|
class Catcher
|
@@ -44,12 +45,16 @@ module YogiBerra
|
|
44
45
|
def db_client(host, port, replica_set = nil)
|
45
46
|
# :w => 0 set the default write concern to 0, this allows writes to be non-blocking
|
46
47
|
# by not waiting for a response from mongodb
|
48
|
+
# :connect_timeout set to 5 will only wait 5 seconds failing to connect
|
47
49
|
if replica_set
|
48
|
-
@@mongo_client = Mongo::MongoReplicaSetClient.new(replica_set, :w => 0)
|
50
|
+
@@mongo_client = Mongo::MongoReplicaSetClient.new(replica_set, :w => 0, :connect_timeout => 5)
|
49
51
|
else
|
50
|
-
@@mongo_client = Mongo::MongoClient.new(host, port, :w => 0)
|
52
|
+
@@mongo_client = Mongo::MongoClient.new(host, port, :w => 0, :connect_timeout => 5)
|
51
53
|
end
|
52
|
-
rescue
|
54
|
+
rescue Timeout::Error => error
|
55
|
+
YogiBerra::Logger.log("Couldn't connect to the mongo database timeout on host: #{host} port: #{port}.\n #{error}", :error)
|
56
|
+
nil
|
57
|
+
rescue => error
|
53
58
|
YogiBerra::Logger.log("Couldn't connect to the mongo database on host: #{host} port: #{port}.", :error)
|
54
59
|
nil
|
55
60
|
end
|
data/lib/yogi_berra/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -20,17 +20,25 @@ def build_session
|
|
20
20
|
}
|
21
21
|
end
|
22
22
|
|
23
|
-
def mock_mongo_client(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
def mock_mongo_client(opts)
|
24
|
+
if opts[:timeout]
|
25
|
+
Timeout.should_receive(:timeout).and_raise(Timeout::Error)
|
26
|
+
else
|
27
|
+
mongo_client = double('mongo client')
|
28
|
+
mongo_connection = double('mongo connection')
|
29
|
+
Mongo::MongoClient.should_receive(:new) { mongo_client }
|
30
|
+
mongo_client.should_receive(:[]) { mongo_connection } if opts[:client_should]
|
31
|
+
if opts[:auth] == :error
|
32
|
+
mongo_connection.should_receive(:authenticate).and_raise
|
33
|
+
elsif opts[:auth].nil? || opts[:auth]
|
34
|
+
mongo_connection.should_receive(:authenticate)
|
35
|
+
end
|
36
|
+
|
37
|
+
if opts[:connection_should]
|
38
|
+
mongo_connection.should_receive(:[]) { mongo_connection }
|
39
|
+
mongo_connection.should_receive(:insert)
|
40
|
+
end
|
32
41
|
end
|
33
|
-
mongo_connection
|
34
42
|
end
|
35
43
|
|
36
44
|
def reset_if_rails
|
@@ -25,7 +25,7 @@ describe YogiBerra::Catcher do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should grab a connection using the settings file" do
|
28
|
-
mock_mongo_client(true)
|
28
|
+
mock_mongo_client(:client_should => true)
|
29
29
|
connection = nil
|
30
30
|
YogiBerra::Catcher.load_db_settings(@test_yaml)
|
31
31
|
connection = YogiBerra::Catcher.quick_connection
|
@@ -33,10 +33,30 @@ describe YogiBerra::Catcher do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should grab a connection to mongodb" do
|
36
|
-
mock_mongo_client(
|
37
|
-
|
38
|
-
yaml = YogiBerra::Catcher.load_db_settings(@test_yaml)
|
36
|
+
mock_mongo_client(:auth => false)
|
37
|
+
YogiBerra::Catcher.load_db_settings(@test_yaml)
|
39
38
|
db_client = YogiBerra::Catcher.db_client(YogiBerra::Catcher.settings["host"], YogiBerra::Catcher.settings["port"])
|
40
39
|
db_client.should_not == nil
|
41
40
|
end
|
41
|
+
|
42
|
+
it "should grab a connection and fail to connect after 5 seconds" do
|
43
|
+
mock_mongo_client(:timeout => true)
|
44
|
+
YogiBerra::Catcher.load_db_settings(@test_yaml)
|
45
|
+
client = YogiBerra::Catcher.db_client(YogiBerra::Catcher.settings["host"], YogiBerra::Catcher.settings["port"])
|
46
|
+
client.should == nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should grab a connection and authenticate" do
|
50
|
+
mock_mongo_client(:client_should => true)
|
51
|
+
YogiBerra::Catcher.load_db_settings(@test_yaml)
|
52
|
+
connection = YogiBerra::Catcher.quick_connection
|
53
|
+
connection.should_not == nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should grab a connection and fail to authenticate" do
|
57
|
+
mock_mongo_client(:client_should => true, :auth => :error)
|
58
|
+
YogiBerra::Catcher.load_db_settings(@test_yaml)
|
59
|
+
connection = YogiBerra::Catcher.quick_connection
|
60
|
+
connection.should_not == nil
|
61
|
+
end
|
42
62
|
end
|
@@ -8,7 +8,7 @@ describe YogiBerra::Data do
|
|
8
8
|
|
9
9
|
it "should store an exception" do
|
10
10
|
exception = build_exception
|
11
|
-
mock_mongo_client(true, true)
|
11
|
+
mock_mongo_client(:client_should => true, :connection_should => true)
|
12
12
|
YogiBerra::Catcher.quick_connection
|
13
13
|
YogiBerra::Data.store!(exception)
|
14
14
|
end
|
@@ -7,7 +7,7 @@ describe YogiBerra::ExceptionMiddleware do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should call the upstream app with the environment" do
|
10
|
-
mock_mongo_client(true)
|
10
|
+
mock_mongo_client(:client_should => true)
|
11
11
|
environment = { 'key' => 'value' }
|
12
12
|
app = lambda { |env| ['response', {}, env] }
|
13
13
|
stack = YogiBerra::ExceptionMiddleware.new(app)
|
@@ -20,7 +20,7 @@ describe YogiBerra::ExceptionMiddleware do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "deliver an exception raised while calling an upstream app" do
|
23
|
-
mock_mongo_client(true, true)
|
23
|
+
mock_mongo_client(:client_should => true, :connection_should => true)
|
24
24
|
exception = build_exception
|
25
25
|
environment = { 'key' => 'value' }
|
26
26
|
app = lambda do |env|
|
@@ -36,7 +36,7 @@ describe YogiBerra::ExceptionMiddleware do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should deliver an exception in rack.exception" do
|
39
|
-
mock_mongo_client(true, true)
|
39
|
+
mock_mongo_client(:client_should => true, :connection_should => true)
|
40
40
|
exception = build_exception
|
41
41
|
environment = { 'key' => 'value' }
|
42
42
|
|
metadata
CHANGED
@@ -1,92 +1,112 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: yogi_berra
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 1
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 15
|
10
|
+
version: 0.0.15
|
5
11
|
platform: ruby
|
6
|
-
authors:
|
12
|
+
authors:
|
7
13
|
- Kevin Earl Krauss
|
8
14
|
autorequire:
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
17
|
+
|
18
|
+
date: 2013-12-09 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
14
22
|
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 10.0.4
|
20
|
-
type: :development
|
21
23
|
prerelease: false
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 71
|
30
|
+
segments:
|
31
|
+
- 10
|
32
|
+
- 0
|
33
|
+
- 4
|
26
34
|
version: 10.0.4
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 2.13.0
|
34
35
|
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
35
39
|
prerelease: false
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - "="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 59
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 13
|
49
|
+
- 0
|
40
50
|
version: 2.13.0
|
41
|
-
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
42
54
|
name: bson
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 1.8.3
|
48
|
-
type: :runtime
|
49
55
|
prerelease: false
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
- !ruby/object:Gem::Version
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - "="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 49
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 8
|
65
|
+
- 3
|
61
66
|
version: 1.8.3
|
62
67
|
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bson_ext
|
63
71
|
prerelease: false
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
- !ruby/object:Gem::Version
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - "="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 49
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 8
|
81
|
+
- 3
|
75
82
|
version: 1.8.3
|
76
83
|
type: :runtime
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: mongo
|
77
87
|
prerelease: false
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - "="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 49
|
94
|
+
segments:
|
95
|
+
- 1
|
96
|
+
- 8
|
97
|
+
- 3
|
82
98
|
version: 1.8.3
|
83
|
-
|
84
|
-
|
99
|
+
type: :runtime
|
100
|
+
version_requirements: *id005
|
101
|
+
description: If the world were perfect, it wouldn't be. So you need the best error catcher of all time!
|
85
102
|
email: earlkrauss@gmail.com
|
86
103
|
executables: []
|
104
|
+
|
87
105
|
extensions: []
|
106
|
+
|
88
107
|
extra_rdoc_files: []
|
89
|
-
|
108
|
+
|
109
|
+
files:
|
90
110
|
- lib/facets.rb
|
91
111
|
- lib/yogi_berra/action_controller_catcher.rb
|
92
112
|
- lib/yogi_berra/backtrace.rb
|
@@ -111,31 +131,41 @@ files:
|
|
111
131
|
- spec/yogi_berra_data_spec.rb
|
112
132
|
- spec/yogi_berra_exception_middleware_spec.rb
|
113
133
|
- spec/yogi_berra_logger_spec.rb
|
134
|
+
has_rdoc: true
|
114
135
|
homepage: http://github.com/earlonrails/yogi_berra
|
115
|
-
licenses:
|
136
|
+
licenses:
|
116
137
|
- MIT
|
117
|
-
metadata: {}
|
118
138
|
post_install_message:
|
119
139
|
rdoc_options: []
|
120
|
-
|
140
|
+
|
141
|
+
require_paths:
|
121
142
|
- lib
|
122
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
hash: 3
|
149
|
+
segments:
|
150
|
+
- 0
|
151
|
+
version: "0"
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
hash: 3
|
158
|
+
segments:
|
159
|
+
- 0
|
160
|
+
version: "0"
|
132
161
|
requirements: []
|
162
|
+
|
133
163
|
rubyforge_project:
|
134
|
-
rubygems_version:
|
164
|
+
rubygems_version: 1.3.7
|
135
165
|
signing_key:
|
136
|
-
specification_version:
|
166
|
+
specification_version: 3
|
137
167
|
summary: Catches errors in your rails app and doesn't get in the way.
|
138
|
-
test_files:
|
168
|
+
test_files:
|
139
169
|
- spec/fixtures/config/yogi.yml
|
140
170
|
- spec/fixtures/rails.rb
|
141
171
|
- spec/fixtures/test.yml
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
NDllMDIyZTlmZjdiOGFkZDY3MWFmMGNlZTc5NTBjNmRiMTNiNWJmNQ==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZTcyMDg3Njc1YzAzYWExMGMwNDAzMDAzYWU2MjBmMTEyMDhhMGVkYg==
|
7
|
-
SHA512:
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MjRjYjgwZmFkMDU5ODY2OGI4YWE0MjlkZDU4ZThiNmVmOTRhZDI3Yzg2ZDk0
|
10
|
-
NGE3NTU1YmUzMDQ1NTNhY2ZmYzlkOThjMzQ1MjYyNmMyZDA2NWIwMjk0MWZm
|
11
|
-
ZmQ1YzhmNGYwNjg3ZWRlZmNiZGQ1YzE0YzU4YzlhNTc5NDY4OWM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NTU5MGY2MTNkNDhlM2VkZTgzNmRjMzcwY2RhMzk5MDAzNDM2NWU3MDRhZmE0
|
14
|
-
ZDU0ODhmZWZkYWEyMDNkMTdhZTZlMmViYTM3MzFlZWE3ODMwNDhkZTVjMWEy
|
15
|
-
NzEwMjQ3ZDhkNWM0MWQxMzcyZDQyMzgzMTcwZTc5Yzg5YTQ1Yzc=
|