reraises 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/lib/reraises/version.rb +3 -0
- data/lib/reraises.rb +46 -0
- data/reraises.gemspec +24 -0
- data/spec/reraises_spec.rb +21 -0
- data/spec/spec_helper.rb +1 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 105751568081291ced07b39ac446a66788c1e0af
|
4
|
+
data.tar.gz: 6ea7b8c6633ec410109be2c3cd567a9182f56f31
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e8b7401c239cf7972fffe6d89745aedd4ebafe5a30b6f355eb96171f3f739d70f7fb02704bc178495395f8bb16f11700d6c15de61c0dc948c356a3360031d99
|
7
|
+
data.tar.gz: d1b05bd653c515aa8fc227285e8a8760abafbed8559f9424825a2c6d5f2aa9555e75f34a40a31e702ed556ebdcb4779ae759a5d787f16548288e3c4dba1b8f3e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Johannes Gorset
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Reraises
|
2
|
+
|
3
|
+
It's a good idea to reraise exceptions from third-party libraries as your own so
|
4
|
+
you're not leaking implementation details all over your codebase. For example,
|
5
|
+
I would rather deal with my own `Facebook::Page::Inaccessible` exception than
|
6
|
+
`FbGraph::NotFound` outside of my Facebook adapter.
|
7
|
+
|
8
|
+
If your adapter has lots of places that could leak exceptions, however, reraising
|
9
|
+
them everywhere gets old really fast. That's where reraises comes in.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
class Foo
|
15
|
+
extend Reraises
|
16
|
+
|
17
|
+
reraise FbGraph::NotFound, as: Facebook::Page::Inaccessible, in: "bar"
|
18
|
+
|
19
|
+
def bar
|
20
|
+
raise FbGraph::NotFound, "This will be reraised as Facebook::Page::Inaccessible"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
Add this line to your application's Gemfile:
|
28
|
+
|
29
|
+
gem 'reraises'
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
$ bundle
|
34
|
+
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
$ gem install reraises
|
38
|
+
|
39
|
+
## I love you
|
40
|
+
|
41
|
+
Johannes Gorset made this. You should [tweet me](http://twitter.com/jgorset) if you can't get
|
42
|
+
it to work. In fact, you should tweet me anyway.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/reraises.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "reraises/version"
|
2
|
+
|
3
|
+
# Rescue exceptions and raise them as others.
|
4
|
+
#
|
5
|
+
# Usage example:
|
6
|
+
#
|
7
|
+
# class Adapter
|
8
|
+
# extend Reraises
|
9
|
+
#
|
10
|
+
# reraise UglyException, as: PrettyException, in: "bar"
|
11
|
+
#
|
12
|
+
# def query
|
13
|
+
# raise UglyException, "This exception will be reraised as a PrettyException"
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
module Reraises
|
17
|
+
|
18
|
+
# Rescue a given exception and raise another.
|
19
|
+
#
|
20
|
+
# old_exception - The Exception to rescue.
|
21
|
+
# options - A Hash of options:
|
22
|
+
# :as - The Exception class to raise.
|
23
|
+
# :in - A String or Array of Strings describing affected methods.
|
24
|
+
def reraise old_exception, options
|
25
|
+
new_exception = options.fetch :as
|
26
|
+
methods = options.fetch :in
|
27
|
+
|
28
|
+
methods = [methods] unless methods.respond_to? :each
|
29
|
+
|
30
|
+
proxy = Module.new do
|
31
|
+
methods.each do |method|
|
32
|
+
define_method method do |*args|
|
33
|
+
begin
|
34
|
+
super *args
|
35
|
+
rescue old_exception => exception
|
36
|
+
raise new_exception, exception
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class_eval do
|
43
|
+
prepend proxy
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/reraises.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'reraises/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "reraises"
|
8
|
+
spec.version = Reraises::VERSION
|
9
|
+
spec.authors = ["Johannes Gorset"]
|
10
|
+
spec.email = ["jgorset@gmail.com"]
|
11
|
+
spec.description = "Reraise bad exceptions as good exceptions"
|
12
|
+
spec.summary = "Reraise bad exceptions as good exceptions"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class Double
|
4
|
+
extend Reraises
|
5
|
+
|
6
|
+
reraise KeyError, as: ArgumentError, in: "raise_key_error"
|
7
|
+
|
8
|
+
def raise_key_error
|
9
|
+
raise KeyError, "message"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Reraises do
|
14
|
+
describe "#reraise" do
|
15
|
+
|
16
|
+
it "reraises an exception as another" do
|
17
|
+
expect{Double.new.raise_key_error}.to raise_error ArgumentError, "message"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "reraises"
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reraises
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Johannes Gorset
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Reraise bad exceptions as good exceptions
|
56
|
+
email:
|
57
|
+
- jgorset@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/reraises.rb
|
68
|
+
- lib/reraises/version.rb
|
69
|
+
- reraises.gemspec
|
70
|
+
- spec/reraises_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Reraise bad exceptions as good exceptions
|
96
|
+
test_files:
|
97
|
+
- spec/reraises_spec.rb
|
98
|
+
- spec/spec_helper.rb
|