yogi_berra 0.0.15 → 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MmQ2Y2I5NjhiYTY0Yzk3MzEyMTYwNDQ5MzRmNTMyOTg4MTgxYmM1Nw==
5
+ data.tar.gz: !binary |-
6
+ M2Y0NTBjZmYwMmE3ZWVjZDc1MDA1YmFkMWUyYTdmOTBlYTE5M2QyNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTg0ZGJjOWJlODgwYTZmMzgyNDZiYTdiMjIzMzUyYzNjNzY1NDIwZTBkODRj
10
+ MWIyODU1MWNhNWIwNzAwY2JlMjMwM2QzOGYzNDEyYjdmZWNmZjhiNTFmNGFh
11
+ NWY2MWE0OTIwMmVjYzU0NDI4OTg0ZDZkN2I4MjdiZDQzOTNiYjY=
12
+ data.tar.gz: !binary |-
13
+ MmUyN2Q5ZjNlMjEyMDIyMmU0NjY1OTEwOGFjYWIwY2ViMGQzNTU1ZDlmMDky
14
+ YTJiYjE1M2ZhMzk4ZGIxZGJjNWE0MTdmMWM1YTIwYjAwMTJjNmViMzcyMDk1
15
+ MGEzZWFlM2Q1OWM1MGVkMzIwNTlhZTVkZTZjODllNzdjODZlNTA=
data/README.md CHANGED
@@ -45,7 +45,7 @@ Use `YogiBerra::Catcher.load_db_settings("location_to_some_yaml_file.yml")` to l
45
45
 
46
46
  Finally store a rescued exception:
47
47
 
48
- YogiBerra::Catcher.quick_connection
48
+ YogiBerra::Catcher.connect
49
49
  begin
50
50
  raise Exception
51
51
  rescue => raised
@@ -42,46 +42,47 @@ module YogiBerra
42
42
  end
43
43
  end
44
44
 
45
- def db_client(host, port, replica_set = nil)
45
+ def fork_database
46
+ host = @@settings["host"]
47
+ port = @@settings["port"]
48
+ database = @@settings["database"]
49
+ username = @@settings["username"]
50
+ password = @@settings["password"]
51
+ replica_set = @@settings["replica_set"]
52
+
46
53
  # :w => 0 set the default write concern to 0, this allows writes to be non-blocking
47
54
  # by not waiting for a response from mongodb
48
- # :connect_timeout set to 5 will only wait 5 seconds failing to connect
49
- if replica_set
50
- @@mongo_client = Mongo::MongoReplicaSetClient.new(replica_set, :w => 0, :connect_timeout => 5)
51
- else
52
- @@mongo_client = Mongo::MongoClient.new(host, port, :w => 0, :connect_timeout => 5)
55
+ Thread.new do
56
+ begin
57
+ if replica_set
58
+ @@mongo_client = Mongo::MongoReplicaSetClient.new(replica_set, :w => 0, :connect_timeout => 10)
59
+ else
60
+ @@mongo_client = Mongo::MongoClient.new(host, port, :w => 0, :connect_timeout => 10)
61
+ end
62
+ rescue Timeout::Error => timeout_error
63
+ YogiBerra::Logger.log("Couldn't connect to the mongo database timeout on host: #{host} port: #{port}.\n #{timeout_error.inspect}", :error)
64
+ retry
65
+ rescue => error
66
+ YogiBerra::Logger.log("Couldn't connect to the mongo database on host: #{host} port: #{port}.\n #{error.inspect}", :error)
67
+ retry
68
+ end
69
+
70
+ @@connection = @@mongo_client[database]
71
+ if username && password
72
+ begin
73
+ @@connection.authenticate(username, password)
74
+ rescue
75
+ YogiBerra::Logger.log("Couldn't authenticate with user #{username} to mongo database on host: #{host} port: #{port} database: #{database}.", :warn)
76
+ end
77
+ end
53
78
  end
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
58
- YogiBerra::Logger.log("Couldn't connect to the mongo database on host: #{host} port: #{port}.", :error)
59
- nil
60
79
  end
61
80
 
62
- def quick_connection(load_settings = false)
81
+ def connect(load_settings = false)
63
82
  load_db_settings if load_settings
64
83
 
65
84
  if @@settings
66
- host = @@settings["host"]
67
- port = @@settings["port"]
68
- database = @@settings["database"]
69
- username = @@settings["username"]
70
- password = @@settings["password"]
71
- replica_set = @@settings["replica_set"]
72
- client = db_client(host, port, replica_set)
73
- if client
74
- @@connection = client[database]
75
- if @@connection && username && password
76
- begin
77
- @@connection.authenticate(username, password)
78
- rescue
79
- YogiBerra::Logger.log("Couldn't authenticate with user #{username} to mongo database on host: #{host} port: #{port} database: #{database}.", :warn)
80
- end
81
- end
82
- else
83
- YogiBerra::Logger.log("Couldn't connect to the mongo database on host: #{host} port: #{port}.", :error)
84
- end
85
+ fork_database
85
86
  else
86
87
  YogiBerra::Logger.log("Couldn't load the yogi.yml file.", :error) if load_settings
87
88
  end
@@ -2,14 +2,13 @@ module YogiBerra
2
2
  class ExceptionMiddleware
3
3
  def initialize(app)
4
4
  @app = app
5
- YogiBerra::Catcher.quick_connection(true)
5
+ YogiBerra::Catcher.connect(true)
6
6
  end
7
7
 
8
8
  def call(env)
9
9
  begin
10
10
  path_parameters = env['action_controller.request.path_parameters'] || {}
11
11
  query_hash = env['rack.request.query_hash'] || {}
12
- response = dup._call(env)
13
12
  environment = {
14
13
  :session => env['rack.session'],
15
14
  :params => path_parameters.merge(query_hash),
@@ -19,6 +18,7 @@ module YogiBerra
19
18
  :server_address => env['SERVER_ADDR'],
20
19
  :remote_address => env['REMOTE_ADDR']
21
20
  }
21
+ response = dup._call(env)
22
22
  rescue Exception => raised
23
23
  YogiBerra.exceptionize(raised, environment)
24
24
  raise raised
@@ -25,5 +25,5 @@ module YogiBerra
25
25
  end
26
26
  end
27
27
 
28
- YogiBerra::Catcher.quick_connection(true)
28
+ YogiBerra::Catcher.connect(true)
29
29
  YogiBerra.initialize
@@ -1,3 +1,3 @@
1
1
  module YogiBerra
2
- VERSION = "0.0.15"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -7,4 +7,4 @@ test:
7
7
  <<: *defaults
8
8
  database: yogi_berra
9
9
  host: localhost
10
- port: 27017
10
+ port: 22222
data/spec/spec_helper.rb CHANGED
@@ -2,8 +2,6 @@ SPEC_FOLDER = File.dirname(__FILE__)
2
2
  require 'yogi_berra'
3
3
  require 'rspec/mocks'
4
4
 
5
- # Helper methods
6
- # Creates RunTimeError
7
5
  def build_exception
8
6
  raise Exception
9
7
  rescue Exception => caught_exception
@@ -20,25 +18,30 @@ def build_session
20
18
  }
21
19
  end
22
20
 
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')
21
+ def mock_mongo(opts)
22
+ mongo_client = double('mongo client')
23
+ mongo_connection = double('mongo connection')
24
+
25
+ if opts[:mongo_client_stub]
29
26
  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
27
+ mongo_client.should_receive(:[]) { mongo_connection }
28
+ end
29
+
30
+ if opts[:authenticate_stub] == :error
31
+ mongo_connection.should_receive(:authenticate).and_raise
32
+ else
33
+ mongo_connection.should_receive(:authenticate)
41
34
  end
35
+
36
+ if opts[:connection_stub]
37
+ mongo_connection.should_receive(:[]) { mongo_connection }
38
+ mongo_connection.should_receive(:insert)
39
+ end
40
+ end
41
+
42
+ def mock_yogi_fork_database
43
+ client = YogiBerra::Catcher.fork_database.join
44
+ YogiBerra::Catcher.should_receive(:fork_database) { client }
42
45
  end
43
46
 
44
47
  def reset_if_rails
@@ -24,39 +24,33 @@ describe YogiBerra::Catcher do
24
24
  Object.send(:remove_const, :Rails)
25
25
  end
26
26
 
27
- it "should grab a connection using the settings file" do
28
- mock_mongo_client(:client_should => true)
29
- connection = nil
27
+ it "should try to grab a connection using the settings file" do
28
+ mock_mongo(:mongo_client_stub => true)
30
29
  YogiBerra::Catcher.load_db_settings(@test_yaml)
31
- connection = YogiBerra::Catcher.quick_connection
32
- connection.should_not == nil
30
+ mock_yogi_fork_database
31
+ lambda { YogiBerra::Catcher.connect }.should_not raise_error
32
+ YogiBerra::Catcher.connection.should_not == nil
33
33
  end
34
34
 
35
35
  it "should grab a connection to mongodb" do
36
- mock_mongo_client(:auth => false)
36
+ mock_mongo(:mongo_client_stub => true)
37
37
  YogiBerra::Catcher.load_db_settings(@test_yaml)
38
- db_client = YogiBerra::Catcher.db_client(YogiBerra::Catcher.settings["host"], YogiBerra::Catcher.settings["port"])
39
- db_client.should_not == nil
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
38
+ mock_yogi_fork_database
39
+ YogiBerra::Catcher.connect
40
+ YogiBerra::Catcher.mongo_client.should_not == nil
47
41
  end
48
42
 
49
43
  it "should grab a connection and authenticate" do
50
- mock_mongo_client(:client_should => true)
44
+ mock_mongo(:mongo_client_stub => true)
51
45
  YogiBerra::Catcher.load_db_settings(@test_yaml)
52
- connection = YogiBerra::Catcher.quick_connection
53
- connection.should_not == nil
46
+ mock_yogi_fork_database
47
+ lambda { YogiBerra::Catcher.connect }.should_not raise_error
54
48
  end
55
49
 
56
50
  it "should grab a connection and fail to authenticate" do
57
- mock_mongo_client(:client_should => true, :auth => :error)
51
+ mock_mongo(:mongo_client_stub => true, :authenticate_stub => :error)
58
52
  YogiBerra::Catcher.load_db_settings(@test_yaml)
59
- connection = YogiBerra::Catcher.quick_connection
60
- connection.should_not == nil
53
+ mock_yogi_fork_database
54
+ lambda { YogiBerra::Catcher.connect }.should_not raise_error
61
55
  end
62
56
  end
@@ -8,8 +8,9 @@ describe YogiBerra::Data do
8
8
 
9
9
  it "should store an exception" do
10
10
  exception = build_exception
11
- mock_mongo_client(:client_should => true, :connection_should => true)
12
- YogiBerra::Catcher.quick_connection
11
+ mock_mongo(:mongo_client_stub => true, :connection_stub => true)
12
+ mock_yogi_fork_database
13
+ YogiBerra::Catcher.connect
13
14
  YogiBerra::Data.store!(exception)
14
15
  end
15
16
 
@@ -7,7 +7,8 @@ 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(:client_should => true)
10
+ mock_mongo(:mongo_client_stub => true)
11
+ mock_yogi_fork_database
11
12
  environment = { 'key' => 'value' }
12
13
  app = lambda { |env| ['response', {}, env] }
13
14
  stack = YogiBerra::ExceptionMiddleware.new(app)
@@ -20,7 +21,8 @@ describe YogiBerra::ExceptionMiddleware do
20
21
  end
21
22
 
22
23
  it "deliver an exception raised while calling an upstream app" do
23
- mock_mongo_client(:client_should => true, :connection_should => true)
24
+ mock_mongo(:mongo_client_stub => true, :connection_stub => true)
25
+ mock_yogi_fork_database
24
26
  exception = build_exception
25
27
  environment = { 'key' => 'value' }
26
28
  app = lambda do |env|
@@ -36,7 +38,8 @@ describe YogiBerra::ExceptionMiddleware do
36
38
  end
37
39
 
38
40
  it "should deliver an exception in rack.exception" do
39
- mock_mongo_client(:client_should => true, :connection_should => true)
41
+ mock_mongo(:mongo_client_stub => true, :connection_stub => true)
42
+ mock_yogi_fork_database
40
43
  exception = build_exception
41
44
  environment = { 'key' => 'value' }
42
45
 
metadata CHANGED
@@ -1,112 +1,92 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: yogi_berra
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
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Kevin Earl Krauss
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-12-09 00:00:00 -08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2013-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: rake
23
- prerelease: false
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
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
34
19
  version: 10.0.4
35
20
  type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
21
  prerelease: false
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
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ 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
50
33
  version: 2.13.0
51
34
  type: :development
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: bson
55
35
  prerelease: false
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
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.13.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bson
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
66
47
  version: 1.8.3
67
48
  type: :runtime
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: bson_ext
71
49
  prerelease: false
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
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: bson_ext
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
82
61
  version: 1.8.3
83
62
  type: :runtime
84
- version_requirements: *id004
85
- - !ruby/object:Gem::Dependency
86
- name: mongo
87
63
  prerelease: false
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
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: mongo
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
98
75
  version: 1.8.3
99
76
  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!
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.8.3
83
+ description: If the world were perfect, it wouldn't be. So you need the best error
84
+ catcher of all time!
102
85
  email: earlkrauss@gmail.com
103
86
  executables: []
104
-
105
87
  extensions: []
106
-
107
88
  extra_rdoc_files: []
108
-
109
- files:
89
+ files:
110
90
  - lib/facets.rb
111
91
  - lib/yogi_berra/action_controller_catcher.rb
112
92
  - lib/yogi_berra/backtrace.rb
@@ -131,41 +111,31 @@ files:
131
111
  - spec/yogi_berra_data_spec.rb
132
112
  - spec/yogi_berra_exception_middleware_spec.rb
133
113
  - spec/yogi_berra_logger_spec.rb
134
- has_rdoc: true
135
114
  homepage: http://github.com/earlonrails/yogi_berra
136
- licenses:
115
+ licenses:
137
116
  - MIT
117
+ metadata: {}
138
118
  post_install_message:
139
119
  rdoc_options: []
140
-
141
- require_paths:
120
+ require_paths:
142
121
  - lib
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"
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
161
132
  requirements: []
162
-
163
133
  rubyforge_project:
164
- rubygems_version: 1.3.7
134
+ rubygems_version: 2.1.11
165
135
  signing_key:
166
- specification_version: 3
136
+ specification_version: 4
167
137
  summary: Catches errors in your rails app and doesn't get in the way.
168
- test_files:
138
+ test_files:
169
139
  - spec/fixtures/config/yogi.yml
170
140
  - spec/fixtures/rails.rb
171
141
  - spec/fixtures/test.yml