yogi_berra 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/Gemfile.lock +1 -1
- data/README.md +19 -1
- data/lib/yogi_berra/catcher.rb +8 -8
- data/lib/yogi_berra/data.rb +0 -1
- data/lib/yogi_berra/version.rb +1 -1
- data/spec/fixtures/config/yogi.yml +10 -0
- data/spec/fixtures/rails.rb +8 -0
- data/spec/fixtures/test.yml +10 -0
- data/spec/spec_helper.rb +3 -6
- data/spec/yogi_berra_catcher_spec.rb +0 -0
- data/spec/yogi_berra_data_spec.rb +0 -0
- data/spec/yogi_berra_exception_middleware_spec.rb +52 -0
- data/spec/yogi_berra_logger_spec.rb +0 -0
- data/spec/yogi_berra_spec.rb +35 -0
- metadata +16 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -27,13 +27,31 @@ Create a yogi.yml file in rails root config/ folder. Here is a sample:
|
|
27
27
|
defaults: &defaults
|
28
28
|
username: yogi
|
29
29
|
password: berra
|
30
|
+
project: yogi_project
|
30
31
|
|
31
32
|
development:
|
32
33
|
<<: *defaults
|
33
34
|
database: yogi_berra
|
34
35
|
host: localhost
|
35
36
|
port: 27017
|
36
|
-
|
37
|
+
|
38
|
+
Without Rails
|
39
|
+
-------------
|
40
|
+
|
41
|
+
Set `YOGI_ENV` variable to tell yogi which environment you would like to use.
|
42
|
+
For instance given the previous yaml file, one could use `YOGI_ENV=development`.
|
43
|
+
|
44
|
+
Use `YogiBerra::Catcher.load_db_settings("location_to_some_yaml_file.yml")` to load your database settings.
|
45
|
+
|
46
|
+
Finally store a rescued exception:
|
47
|
+
|
48
|
+
YogiBerra::Catcher.quick_connection
|
49
|
+
begin
|
50
|
+
raise Exception
|
51
|
+
rescue => raised
|
52
|
+
YogiBerra.exceptionize(raised, environment, YogiBerra::Catcher.connection)
|
53
|
+
end
|
54
|
+
|
37
55
|
View
|
38
56
|
----
|
39
57
|
To view the exceptions you check them in the database or install this rails app.
|
data/lib/yogi_berra/catcher.rb
CHANGED
@@ -19,13 +19,13 @@ module YogiBerra
|
|
19
19
|
begin
|
20
20
|
File.open(database_config, 'r') do |f|
|
21
21
|
yaml_file = YAML.load(f)
|
22
|
-
environment = ENV["
|
23
|
-
YogiBerra::Logger.log("I get here! #{environment.inspect}", :info)
|
22
|
+
environment = (ENV["YOGI_ENV"] || ENV["RAILS_ENV"] || "test")
|
24
23
|
@@settings = yaml_file["#{environment}"] if yaml_file
|
25
24
|
end
|
26
25
|
rescue
|
27
26
|
YogiBerra::Logger.log("No such file: #{database_config}", :error)
|
28
27
|
end
|
28
|
+
@@settings
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -39,21 +39,21 @@ module YogiBerra
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def quick_connection
|
42
|
-
|
43
|
-
settings = @@settings || load_db_settings
|
42
|
+
load_db_settings
|
44
43
|
|
45
|
-
if settings
|
46
|
-
host = settings["host"]
|
47
|
-
port = settings["port"]
|
44
|
+
if @@settings
|
45
|
+
host = @@settings["host"]
|
46
|
+
port = @@settings["port"]
|
48
47
|
client = db_client(host, port)
|
49
48
|
if client
|
50
|
-
@@connection = client[settings["database"]]
|
49
|
+
@@connection = client[@@settings["database"]]
|
51
50
|
else
|
52
51
|
YogiBerra::Logger.log("Couldn't connect to the mongo database on host: #{host} port: #{port}.", :error)
|
53
52
|
end
|
54
53
|
else
|
55
54
|
YogiBerra::Logger.log("Couldn't load the yogi.yml file.", :error)
|
56
55
|
end
|
56
|
+
@@connection
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
data/lib/yogi_berra/data.rb
CHANGED
data/lib/yogi_berra/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
# Configure Rails Envinronment
|
2
|
-
ENV["RAILS_ENV"] = "test"
|
3
|
-
|
4
1
|
# Load support files
|
5
|
-
|
2
|
+
SPEC_FOLDER = File.dirname(__FILE__)
|
3
|
+
require 'yaml'
|
6
4
|
require 'yogi_berra'
|
7
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
8
|
-
|
9
5
|
# Helper methods
|
10
6
|
|
7
|
+
|
11
8
|
# Creates RunTimeError
|
12
9
|
def build_exception
|
13
10
|
raise
|
File without changes
|
File without changes
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe YogiBerra::ExceptionMiddleware do
|
4
|
+
before(:each) do
|
5
|
+
YogiBerra::Logger.stub(:log)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should call the upstream app with the environment" do
|
9
|
+
environment = { 'key' => 'value' }
|
10
|
+
app = lambda { |env| ['response', {}, env] }
|
11
|
+
stack = YogiBerra::ExceptionMiddleware.new(app)
|
12
|
+
|
13
|
+
response = stack.call(environment)
|
14
|
+
|
15
|
+
response[0].should == 'response'
|
16
|
+
response[1].should == {}
|
17
|
+
response[2].instance_variable_get("@response").should == { 'key' => 'value' }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "deliver an exception raised while calling an upstream app" do
|
21
|
+
exception = build_exception
|
22
|
+
environment = { 'key' => 'value' }
|
23
|
+
app = lambda do |env|
|
24
|
+
raise exception
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
stack = YogiBerra::ExceptionMiddleware.new(app)
|
29
|
+
stack.call(environment)
|
30
|
+
rescue Exception => raised
|
31
|
+
raised.should == exception
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should deliver an exception in rack.exception" do
|
36
|
+
exception = build_exception
|
37
|
+
environment = { 'key' => 'value' }
|
38
|
+
|
39
|
+
response = [200, {}, ['okay']]
|
40
|
+
app = lambda do |env|
|
41
|
+
env['rack.exception'] = exception
|
42
|
+
response
|
43
|
+
end
|
44
|
+
stack = YogiBerra::ExceptionMiddleware.new(app)
|
45
|
+
|
46
|
+
actual_response = stack.call(environment)
|
47
|
+
|
48
|
+
actual_response[0].should == 200
|
49
|
+
actual_response[1].should == {}
|
50
|
+
actual_response[2].instance_variable_get("@response").should == ["okay"]
|
51
|
+
end
|
52
|
+
end
|
File without changes
|
data/spec/yogi_berra_spec.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe YogiBerra do
|
4
|
+
before(:all) do
|
5
|
+
@test_yaml = "#{SPEC_FOLDER}/fixtures/test.yml"
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
YogiBerra::Logger.stub(:log)
|
10
|
+
end
|
4
11
|
|
5
12
|
it "should call the upstream app with the environment" do
|
6
13
|
environment = { 'key' => 'value' }
|
@@ -47,4 +54,32 @@ describe YogiBerra do
|
|
47
54
|
actual_response[2].instance_variable_get("@response").should == ["okay"]
|
48
55
|
end
|
49
56
|
|
57
|
+
it "should load a yaml file without rails" do
|
58
|
+
lambda { YogiBerra::Catcher.load_db_settings(@test_yaml) }.should_not raise_error
|
59
|
+
YogiBerra::Catcher.settings.should_not == nil
|
60
|
+
YogiBerra::Catcher.settings["project"].should == "test_yogi_project"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should load a yaml file with rails" do
|
64
|
+
ENV["YOGI_ENV"] = nil
|
65
|
+
require 'fixtures/rails'
|
66
|
+
lambda { YogiBerra::Catcher.load_db_settings }.should_not raise_error
|
67
|
+
YogiBerra::Catcher.settings.should_not == nil
|
68
|
+
YogiBerra::Catcher.settings["project"].should == "rails_yogi_project"
|
69
|
+
Object.send(:remove_const, :Rails)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should grab a connection using the settings file" do
|
73
|
+
connection = nil
|
74
|
+
YogiBerra::Catcher.load_db_settings(@test_yaml)
|
75
|
+
connection = YogiBerra::Catcher.quick_connection
|
76
|
+
connection.should_not == nil
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should grab a connection to mongodb" do
|
80
|
+
yaml = nil
|
81
|
+
yaml = YogiBerra::Catcher.load_db_settings(@test_yaml)
|
82
|
+
db_client = YogiBerra::Catcher.db_client(YogiBerra::Catcher.settings["host"], YogiBerra::Catcher.settings["port"])
|
83
|
+
db_client.should_not == nil
|
84
|
+
end
|
50
85
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yogi_berra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -115,7 +115,14 @@ files:
|
|
115
115
|
- LICENSE
|
116
116
|
- Rakefile
|
117
117
|
- README.md
|
118
|
+
- spec/fixtures/config/yogi.yml
|
119
|
+
- spec/fixtures/rails.rb
|
120
|
+
- spec/fixtures/test.yml
|
118
121
|
- spec/spec_helper.rb
|
122
|
+
- spec/yogi_berra_catcher_spec.rb
|
123
|
+
- spec/yogi_berra_data_spec.rb
|
124
|
+
- spec/yogi_berra_exception_middleware_spec.rb
|
125
|
+
- spec/yogi_berra_logger_spec.rb
|
119
126
|
- spec/yogi_berra_spec.rb
|
120
127
|
homepage: http://github.com/earlonrails/yogi_berra
|
121
128
|
licenses: []
|
@@ -142,5 +149,12 @@ signing_key:
|
|
142
149
|
specification_version: 3
|
143
150
|
summary: Catches errors in your rails app and doesn't get in the way.
|
144
151
|
test_files:
|
152
|
+
- spec/fixtures/config/yogi.yml
|
153
|
+
- spec/fixtures/rails.rb
|
154
|
+
- spec/fixtures/test.yml
|
145
155
|
- spec/spec_helper.rb
|
156
|
+
- spec/yogi_berra_catcher_spec.rb
|
157
|
+
- spec/yogi_berra_data_spec.rb
|
158
|
+
- spec/yogi_berra_exception_middleware_spec.rb
|
159
|
+
- spec/yogi_berra_logger_spec.rb
|
146
160
|
- spec/yogi_berra_spec.rb
|