rb_tryagain 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.
@@ -0,0 +1,30 @@
1
+ require "rb_tryagain/version"
2
+
3
+ module RbTryagain
4
+ module_function
5
+ def try_again(args = {}, &block)
6
+ max_tries = args[:tries] || 5
7
+ on_error = args[:on_error] || :raise
8
+ print_errors = args[:print_errors] || false
9
+ current_tries = 0
10
+
11
+ success = false
12
+ until current_tries >= max_tries or success
13
+ begin
14
+ block.call
15
+ rescue Exception => ex
16
+ if print_errors
17
+ STDERR.puts ex.message
18
+ STDERR.puts ex.backtrace
19
+ end
20
+ current_tries += 1
21
+
22
+ if current_tries >= max_tries and on_error == :raise
23
+ raise ex
24
+ end
25
+ else
26
+ success = true
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Kernel
2
+ def try_again(args = {}, &block)
3
+ RbTryagain.try_again(args, &block)
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module RbTryagain
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb_tryagain
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Joshua Levinson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-11 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email:
24
+ - jlevinson@raybeam.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - lib/rb_tryagain.rb
33
+ - lib/rb_tryagain/toplevel_function.rb
34
+ - lib/rb_tryagain/version.rb
35
+ has_rdoc: true
36
+ homepage: http://www.raybeam.com
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.6.2
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: A simple retry library
69
+ test_files: []
70
+