exception_resource 0.0.1
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/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/exception_resource.gemspec +24 -0
- data/lib/exception_resource.rb +32 -0
- data/lib/exception_resource/version.rb +3 -0
- data/spec/exception_resource_spec.rb +35 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/exception_app.rb +15 -0
- data/spec/support/helpers.rb +11 -0
- metadata +106 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "exception_resource/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "exception_resource"
|
|
7
|
+
s.version = ExceptionResource::VERSION
|
|
8
|
+
s.authors = ["Rafael Souza"]
|
|
9
|
+
s.email = ["me@rafaelss.com"]
|
|
10
|
+
s.homepage = "http://github.com/rafaelss/exception_resource"
|
|
11
|
+
s.summary = %q{Save your exceptions}
|
|
12
|
+
s.description = %q{Save your exceptions}
|
|
13
|
+
|
|
14
|
+
s.files = `git ls-files`.split("\n")
|
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
17
|
+
s.require_paths = ["lib"]
|
|
18
|
+
|
|
19
|
+
s.add_runtime_dependency "exception-hashify", "~> 0.0.1"
|
|
20
|
+
s.add_development_dependency "rspec", "~> 2.6.0"
|
|
21
|
+
s.add_development_dependency "artifice", "~> 0.6"
|
|
22
|
+
s.add_development_dependency "rack", ">= 1.0"
|
|
23
|
+
end
|
|
24
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "exception_resource/version"
|
|
2
|
+
require "exception-hashify"
|
|
3
|
+
|
|
4
|
+
module ExceptionResource
|
|
5
|
+
def self.site=(value)
|
|
6
|
+
@site = value
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.site
|
|
10
|
+
@site
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module Base
|
|
14
|
+
def save
|
|
15
|
+
url = URI.parse(ExceptionResource.site).merge("/exceptions") rescue nil
|
|
16
|
+
if url
|
|
17
|
+
response = Net::HTTP.post_form(url, to_hash)
|
|
18
|
+
response.code == "201"
|
|
19
|
+
else
|
|
20
|
+
false
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def save!
|
|
25
|
+
save
|
|
26
|
+
raise self
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
Exception.send(:include, ExceptionResource::Base)
|
|
32
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe ExceptionResource do
|
|
4
|
+
before :each do
|
|
5
|
+
ExceptionResource.site = "http://localhost:3000"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "should send the exception to configured url" do
|
|
9
|
+
with_exception do |ex|
|
|
10
|
+
Artifice.activate_with(ExceptionApp.new) do
|
|
11
|
+
ex.save.should == true
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should re-raise itself" do
|
|
17
|
+
ExceptionResource.site = "http://google.com"
|
|
18
|
+
|
|
19
|
+
with_exception do |ex|
|
|
20
|
+
Artifice.activate_with(ExceptionApp.new) do
|
|
21
|
+
lambda { ex.save! }.should raise_error(ex)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should do nothing if site is not configured or invalid" do
|
|
27
|
+
ExceptionResource.site = nil
|
|
28
|
+
Net::HTTP.should_receive(:post_form).never
|
|
29
|
+
|
|
30
|
+
with_exception do |ex|
|
|
31
|
+
ex.save.should == false
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class ExceptionApp
|
|
2
|
+
|
|
3
|
+
def call(env)
|
|
4
|
+
request = Rack::Request.new(env)
|
|
5
|
+
response = if request.post? && request.host == "localhost" && request.path_info =~ /^\/exceptions/
|
|
6
|
+
if request.params["class_name"] && request.params["message"] && request.params["backtrace"]
|
|
7
|
+
[ 201, { "Content-Type" => "application/json" }, [ "OK" ]]
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
response ||= [ 406, { "Content-Type" => "application/json" }, [ "Not Acceptable" ]]
|
|
12
|
+
response
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
metadata
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: exception_resource
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Rafael Souza
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2011-07-27 00:00:00.000000000 -03:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: exception-hashify
|
|
17
|
+
requirement: &2156938880 !ruby/object:Gem::Requirement
|
|
18
|
+
none: false
|
|
19
|
+
requirements:
|
|
20
|
+
- - ~>
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 0.0.1
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: *2156938880
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rspec
|
|
28
|
+
requirement: &2156938380 !ruby/object:Gem::Requirement
|
|
29
|
+
none: false
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 2.6.0
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: *2156938380
|
|
37
|
+
- !ruby/object:Gem::Dependency
|
|
38
|
+
name: artifice
|
|
39
|
+
requirement: &2156937920 !ruby/object:Gem::Requirement
|
|
40
|
+
none: false
|
|
41
|
+
requirements:
|
|
42
|
+
- - ~>
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: '0.6'
|
|
45
|
+
type: :development
|
|
46
|
+
prerelease: false
|
|
47
|
+
version_requirements: *2156937920
|
|
48
|
+
- !ruby/object:Gem::Dependency
|
|
49
|
+
name: rack
|
|
50
|
+
requirement: &2156937460 !ruby/object:Gem::Requirement
|
|
51
|
+
none: false
|
|
52
|
+
requirements:
|
|
53
|
+
- - ! '>='
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '1.0'
|
|
56
|
+
type: :development
|
|
57
|
+
prerelease: false
|
|
58
|
+
version_requirements: *2156937460
|
|
59
|
+
description: Save your exceptions
|
|
60
|
+
email:
|
|
61
|
+
- me@rafaelss.com
|
|
62
|
+
executables: []
|
|
63
|
+
extensions: []
|
|
64
|
+
extra_rdoc_files: []
|
|
65
|
+
files:
|
|
66
|
+
- .gitignore
|
|
67
|
+
- .rspec
|
|
68
|
+
- Gemfile
|
|
69
|
+
- Rakefile
|
|
70
|
+
- exception_resource.gemspec
|
|
71
|
+
- lib/exception_resource.rb
|
|
72
|
+
- lib/exception_resource/version.rb
|
|
73
|
+
- spec/exception_resource_spec.rb
|
|
74
|
+
- spec/spec_helper.rb
|
|
75
|
+
- spec/support/exception_app.rb
|
|
76
|
+
- spec/support/helpers.rb
|
|
77
|
+
has_rdoc: true
|
|
78
|
+
homepage: http://github.com/rafaelss/exception_resource
|
|
79
|
+
licenses: []
|
|
80
|
+
post_install_message:
|
|
81
|
+
rdoc_options: []
|
|
82
|
+
require_paths:
|
|
83
|
+
- lib
|
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
|
+
none: false
|
|
86
|
+
requirements:
|
|
87
|
+
- - ! '>='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
|
+
none: false
|
|
92
|
+
requirements:
|
|
93
|
+
- - ! '>='
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
requirements: []
|
|
97
|
+
rubyforge_project:
|
|
98
|
+
rubygems_version: 1.6.2
|
|
99
|
+
signing_key:
|
|
100
|
+
specification_version: 3
|
|
101
|
+
summary: Save your exceptions
|
|
102
|
+
test_files:
|
|
103
|
+
- spec/exception_resource_spec.rb
|
|
104
|
+
- spec/spec_helper.rb
|
|
105
|
+
- spec/support/exception_app.rb
|
|
106
|
+
- spec/support/helpers.rb
|