net_http_timeout_errors 0.0.2 → 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.
data/README.md CHANGED
@@ -4,6 +4,19 @@ Tired of having to rescue an ever-growing list of Net::HTTP timeout error types?
4
4
 
5
5
  Just include this gem and then do:
6
6
 
7
+ ``` ruby
8
+ begin
9
+ NetHttpTimeoutErrors.conflate do
10
+ uri = URI.parse("http://google.com/")
11
+ response = Net::HTTP.get_response(uri)
12
+ end
13
+ rescue NetHttpTimeoutError
14
+ puts "It timed out some way or other!"
15
+ end
16
+ ```
17
+
18
+ Or if you like:
19
+
7
20
  ``` ruby
8
21
  begin
9
22
  uri = URI.parse("http://google.com/")
@@ -15,7 +28,7 @@ rescue AnotherError, *NetHttpTimeoutErrors.all
15
28
  end
16
29
  ```
17
30
 
18
- Did we miss an exception? Please add it!
31
+ Did we miss an error? Please add it!
19
32
 
20
33
 
21
34
  ## Installation
@@ -1,7 +1,15 @@
1
1
  require "net_http_timeout_errors/version"
2
2
  require "net/http"
3
3
 
4
- module NetHttpTimeoutErrors
4
+ class NetHttpTimeoutError < StandardError
5
+ attr_reader :original_error
6
+
7
+ def initialize(original_error)
8
+ @original_error = original_error
9
+ end
10
+ end
11
+
12
+ class NetHttpTimeoutErrors
5
13
  def self.all
6
14
  [
7
15
  Errno::ECONNREFUSED,
@@ -12,4 +20,10 @@ module NetHttpTimeoutErrors
12
20
  Timeout::Error,
13
21
  ]
14
22
  end
23
+
24
+ def self.conflate
25
+ yield
26
+ rescue *all => e
27
+ raise NetHttpTimeoutError.new(e)
28
+ end
15
29
  end
@@ -1,3 +1,3 @@
1
- module NetHttpTimeoutErrors
2
- VERSION = "0.0.2"
1
+ class NetHttpTimeoutErrors
2
+ VERSION = "0.1.0"
3
3
  end
@@ -9,8 +9,40 @@ describe NetHttpTimeoutErrors, ".all" do
9
9
  # No assertions; more like runnable documentation.
10
10
  it "works splatted" do
11
11
  begin
12
- raise Timeout::Error
12
+ raise an_error
13
13
  rescue ZeroDivisionError, *NetHttpTimeoutErrors.all
14
14
  end
15
15
  end
16
16
  end
17
+
18
+ describe NetHttpTimeoutErrors, ".conflate" do
19
+ it "turns any handled error into a NetHttpTimeoutError" do
20
+ assert_raises(NetHttpTimeoutError) do
21
+ NetHttpTimeoutErrors.conflate do
22
+ raise an_error
23
+ end
24
+ end
25
+ end
26
+
27
+ it "leaves other errors alone" do
28
+ assert_raises(StandardError) do
29
+ NetHttpTimeoutErrors.conflate do
30
+ raise StandardError
31
+ end
32
+ end
33
+ end
34
+
35
+ it "keeps the original error" do
36
+ begin
37
+ NetHttpTimeoutErrors.conflate do
38
+ raise an_error
39
+ end
40
+ rescue => e
41
+ assert_instance_of Timeout::Error, e.original_error
42
+ end
43
+ end
44
+ end
45
+
46
+ def an_error
47
+ Timeout::Error
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net_http_timeout_errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
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: 2012-10-31 00:00:00.000000000 Z
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: