retryable 1.2

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 +19 -0
  2. data/test/tests.rb +1 -0
  3. metadata +57 -0
@@ -0,0 +1,19 @@
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
+ return nil if opts[:tries] == 0
9
+
10
+ retry_exception, tries = [ opts[:on] ].flatten, opts[:tries]
11
+
12
+ begin
13
+ return yield
14
+ rescue *retry_exception
15
+ retry if (tries -= 1) > 0
16
+ end
17
+
18
+ yield
19
+ end
@@ -0,0 +1 @@
1
+ # nothing to see here yet, move along
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: retryable
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.2"
5
+ platform: ruby
6
+ authors:
7
+ - Carlo Zottmann
8
+ - Chu Yeow
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-11-20 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Kernel#retryable, allow for retrying of code blocks.
18
+ email: carlo@zottmann.org
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - lib/retryable.rb
27
+ - test/tests.rb
28
+ has_rdoc: true
29
+ homepage: http://github.com/carlo/retryable
30
+ licenses: []
31
+
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.3.5
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Kernel#retryable, allow for retrying of code blocks.
56
+ test_files:
57
+ - test/tests.rb