carlo-retryable 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.
Files changed (3) hide show
  1. data/lib/retryable.rb +18 -0
  2. data/test/tests.rb +1 -0
  3. metadata +54 -0
data/lib/retryable.rb ADDED
@@ -0,0 +1,18 @@
1
+ # Code originally by Chu Yeow, see
2
+ # http://blog.codefront.net/2008/01/14/retrying-code-blocks-in-ruby-on-exceptions-whatever/
3
+ # Slightly rewritten to allow for passing of more than just type of exception.
4
+
5
+ def retryable( options = {}, &block )
6
+ opts = { :tries => 1, :on => Exception }.merge(options)
7
+
8
+ retry_exception, retries = [ opts[:on] ].flatten, opts[:tries]
9
+
10
+ begin
11
+ return yield
12
+ rescue *retry_exception
13
+ retry if (retries -= 1) > 0
14
+ end
15
+
16
+ yield
17
+ end
18
+
data/test/tests.rb ADDED
@@ -0,0 +1 @@
1
+ # nothing to see here yet, move along
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carlo-retryable
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - Carlo Zottmann, Chu Yeow
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-22 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: carlo@zottmann.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/retryable.rb
26
+ - test/tests.rb
27
+ has_rdoc: false
28
+ homepage: http://github.com/carlo/retryable/tree/master
29
+ post_install_message:
30
+ rdoc_options: []
31
+
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: "0"
39
+ version:
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 1.2.0
50
+ signing_key:
51
+ specification_version: 2
52
+ summary: Kernel#retryable, allow for retrying of code blocks.
53
+ test_files:
54
+ - test/tests.rb