rescue_up_to 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6e0f3734e2a5a0c718009d233322903e1f2a24f
4
+ data.tar.gz: f738a610df68520995be592bd3c211998aad7f08
5
+ SHA512:
6
+ metadata.gz: fc55c3a8baa7367ac5f73d2cb879330ba7592e3415b9fce8383a72d1c5915c874a60d7298da13b003104449ac23b2838edaaf03e8dfc8f2e19d85aeaadf5745d
7
+ data.tar.gz: 7a283b87ab8473f93ca928d44a5a05807822bd08188a45a85bb2bc83579d7948a3f891fa6504b35b1a8bc00f06b7fee72b7b654107cb0b543d7db6e18920bf40
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Samuel Rizzo
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,41 @@
1
+ # rescue\_up\_to
2
+
3
+ Rescues / retries a block, up to a number of times.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rescue_up_to'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rescue_up_to
18
+
19
+ ## Usage
20
+
21
+ # Rescue / retry something, up to 10 times
22
+ value = rescue_up_to(10.times) do
23
+ # do something, rescue StandardError and retry up to 10 times ...
24
+ end
25
+
26
+ # A more complex / useful example, fetch Google's home page
27
+ require 'open-uri'
28
+ contents = rescue_up_to(10.times, from: SocketError, with: ->(rescued_times){sleep rescued_times} ) do
29
+ open('http://www.google.com').read
30
+ end
31
+ # => "[...]"
32
+
33
+
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/srizzo/rescue_up_to/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ require "rdoc/task"
5
+
6
+ desc "Run tests"
7
+ task :default => :test
8
+
9
+ Rake::TestTask.new do |t|
10
+ t.libs << "test"
11
+ t.pattern = 'test/**/*_test.rb'
12
+ end
13
+
14
+
15
+
16
+ RDoc::Task.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'rescue_up_to'
19
+ rdoc.main = "README.md"
20
+ rdoc.options << '--line-numbers'
21
+ rdoc.rdoc_files.include('README.md')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ # require 'rubygems/package_task'
26
+ #
27
+ # spec = eval(File.read("rescue_up_to.gemspec"))
28
+ #
29
+ # Gem::PackageTask.new(spec) do |p|
30
+ # p.gem_spec = spec
31
+ # end
@@ -0,0 +1,3 @@
1
+ module RescueUpTo # :nodoc:
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,32 @@
1
+ require "rescue_up_to/version"
2
+
3
+ module Kernel
4
+
5
+ # Rescues / retries a block, up to +times+ times.
6
+ #
7
+ # ==== Examples
8
+ #
9
+ # # Rescue / retry something, up to 10 times
10
+ # value = rescue_up_to(10.times) do
11
+ # # do something, retry on StandardError...
12
+ # end
13
+ #
14
+ # # A more complex / useful example, fetch Google's home page
15
+ # require 'open-uri'
16
+ # contents = rescue_up_to(10.times, from: SocketError, with: ->(rescued_times){sleep rescued_times} ) do
17
+ # open('http://www.google.com').read
18
+ # end
19
+ # # => "[...]"
20
+ #
21
+ #
22
+ def rescue_up_to times, from: StandardError, with: nil # :yields: rescued_times
23
+ times.each do |rescued_times|
24
+ begin
25
+ return yield rescued_times
26
+ rescue *from => e
27
+ with.call(rescued_times) if with
28
+ end
29
+ end
30
+ yield (times.max + 1)
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rescue_up_to
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Rizzo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-05 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Rescues / retries a block, up to a number of times.
56
+ email:
57
+ - rizzolabs@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files:
61
+ - README.md
62
+ files:
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - lib/rescue_up_to.rb
67
+ - lib/rescue_up_to/version.rb
68
+ homepage: http://github.com/srizzo/rescue_up_to
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options:
74
+ - "--main"
75
+ - README.md
76
+ - "--line-numbers"
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Rescues / retries a block, up to a number of times.
95
+ test_files: []