easy_retry 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c38067f87c684be6a9f709ec44bd993a6ac511998f0c946747143256d88fbe7c
4
- data.tar.gz: a2ffb08ccca6d6a9abea4b4ba962b1fad80f356ec848e468523240edea2cf56c
3
+ metadata.gz: b1628eebabfc2dd25f53d106aa0c665b20c2cc804ee7ff66a7372e784b02594d
4
+ data.tar.gz: 0a1c561a8b510b25c580f4a6df1e3d2af2b913459c30c8c44d30d7985203bb96
5
5
  SHA512:
6
- metadata.gz: bd8bd03df3327dc40e163bdb594e06e1b5d35da04ec569699a5ded179515ab7e1e2757ab2e204d3bcaa53dff77601dc0924fee4e9e40b195c495f07dd91c9ae1
7
- data.tar.gz: fcaae7e8ddfa04c0e58e7511e751feb67c699300b77d1cd52d5f94c3fae18fe872e1b10543d54480ecfe380cbcceb8f20eb708f53b700ee5b32bf8ac78d0b7ef
6
+ metadata.gz: 8ace3d6f0a2e94bcc8e29cf04c9bf1b93a8e5e6d17a45c6b21d50d191a3279d50815f7f805aa21665aa114724ea6d064a9ade21e2939582464798ba6d01bf5d9
7
+ data.tar.gz: 839d5afade1c5e160fb2c7c181f7b952f30bd147246c3956b268ad0039e3343bab1ba8b4a90b197e3cc0565cc193cdce77780c94ec6b8c7147d4ed3eaeda3652
data/.rubocop.yml CHANGED
@@ -4,11 +4,9 @@ AllCops:
4
4
 
5
5
  Style/StringLiterals:
6
6
  Enabled: true
7
- EnforcedStyle: double_quotes
8
7
 
9
8
  Style/StringLiteralsInInterpolation:
10
9
  Enabled: true
11
- EnforcedStyle: double_quotes
12
10
 
13
11
  Layout/LineLength:
14
12
  Max: 120
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.6] - TBD
4
+
5
+ - Allow configuration of logger
6
+
7
+ ## [Released]
8
+
9
+ ## [1.0.5] - 2022-11-22
10
+
11
+ - Raise before sleeping to not sleep for try^2 seconds before raising on the last try.
12
+ - Allow passing of single error
13
+ - Expand ReadMe
14
+
3
15
  ## [1.0.4] - 2022-11-17
4
16
 
5
17
  - Bugfix for EasyRetry to work in Rails _and_ non-Rails projects
data/Gemfile CHANGED
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in easy_retry.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem 'rake', '~> 13.0'
9
9
 
10
- gem "rspec", "~> 3.0"
10
+ gem 'rspec', '~> 3.0'
11
11
 
12
- gem "rubocop", "~> 1.21"
12
+ gem 'rubocop', '~> 1.21'
13
13
 
14
- gem "pry"
14
+ gem 'pry'
15
15
 
16
- gem "simplecov", require: false
16
+ gem 'simplecov', require: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy_retry (1.0.4)
4
+ easy_retry (1.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ![Specs](https://github.com/goudekettingrm/easy_retry/actions/workflows/main.yml/badge.svg)
2
2
 
3
+ <a href="https://www.buymeacoffee.com/goudekettingrm" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-blue.png" alt="Buy Me A Coffee" height="41" width="174"></a>
4
+
3
5
  # EasyRetry
4
6
 
5
7
  <i>Easily retry a block of code a predetermined number of times.</i>
@@ -67,6 +69,38 @@ The code above will not rescue from the `ActiveRecord::RecordInvalid` error and
67
69
  from (pry):16:in `block in __pry__'
68
70
  ```
69
71
 
72
+ Passing an array is not necessary if you need to only rescue from a single error
73
+
74
+ ```rb
75
+ 4.tries(rescue_from: ZeroDivisionError) do |try|
76
+ raise ZeroDivisionError if try < 2
77
+ raise ActiveRecord::RecordInvalid if try < 4
78
+ puts "Success!"
79
+ end
80
+ ```
81
+
82
+ This will generate the same output.
83
+
84
+ ## Block results
85
+
86
+ EasyRetry gives you back the result of the first time the block you passed successfully runs. This can be useful when you need to use the result of the block for other tasks that you do not necessarily want to place in the block.
87
+
88
+ ```rb
89
+ result = 2.tries do |try|
90
+ raise 'Woops' if try < 2
91
+ "This is try number #{try}"
92
+ end
93
+
94
+ puts result
95
+ ```
96
+
97
+ The code above will produce the following output.
98
+
99
+ ```
100
+ Error: Woops (1/2)
101
+ => "This is try number 2"
102
+ ```
103
+
70
104
  ## Retry delay
71
105
 
72
106
  The delay for each retry is based on the iteration count. The delay after each failed attempt is _n^2_, where _n_ is the current iteration that failed. E.g. after the first try, EasyRetry waits 1 second, after the second try it waits 4 seconds, then 9, then 16, then 25, then 36, etc.
@@ -79,7 +113,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
79
113
 
80
114
  ## Contributing
81
115
 
82
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/easy_retry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/easy_retry/blob/main/CODE_OF_CONDUCT.md).
116
+ Bug reports and pull requests are welcome on GitHub at https://github.com/GoudekettingRM/easy_retry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/GoudekettingRM/easy_retry/blob/main/CODE_OF_CONDUCT.md).
83
117
 
84
118
  ## License
85
119
 
@@ -87,4 +121,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
87
121
 
88
122
  ## Code of Conduct
89
123
 
90
- Everyone interacting in the EasyRetry project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/easy_retry/blob/main/CODE_OF_CONDUCT.md).
124
+ Everyone interacting in the EasyRetry project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/GoudekettingRM/easy_retry/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require "rubocop/rake_task"
8
+ require 'rubocop/rake_task'
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/easy_retry/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'easy_retry'
7
+ spec.version = EasyRetry::VERSION
8
+ spec.authors = ['Robin Goudeketting, Peter Duijnstee']
9
+ spec.email = ['robin@goudeketting.nl']
10
+
11
+ spec.summary = 'Easily retry a block of code a predetermined number of times'
12
+ spec.description = 'Easily retry a block of code a predetermined number of times'
13
+ spec.homepage = 'https://github.com/GoudekettingRM/easy_retry'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.6.0'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/GoudekettingRM/easy_retry'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/GoudekettingRM/easy_retry/blob/main/CHANGELOG.md'
20
+ spec.metadata['rubygems_mfa_required'] = 'true'
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasyRetry
4
- VERSION = "1.0.4"
4
+ VERSION = '1.0.5'
5
5
  end
data/lib/easy_retry.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "easy_retry/version"
3
+ require_relative 'easy_retry/version'
4
4
 
5
5
  # Extend the Numeric class with a #tries method
6
6
  class Numeric
7
7
  # rubocop:disable Metrics/MethodLength
8
8
  def tries(rescue_from: [StandardError])
9
- raise ArgumentError, "No block given" unless block_given?
9
+ raise ArgumentError, 'No block given' unless block_given?
10
10
 
11
+ rescue_from = Array(rescue_from)
11
12
  max_retry = self
12
13
  current_try = 1
13
14
  result = nil
@@ -23,11 +24,11 @@ class Numeric
23
24
  puts "Error: #{e.message} (#{current_try}/#{max_retry})"
24
25
  end
25
26
 
27
+ raise if current_try >= max_retry
28
+
26
29
  sleep current_try * current_try
27
30
 
28
31
  current_try += 1
29
-
30
- raise e if current_try > max_retry
31
32
  end
32
33
 
33
34
  result
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Goudeketting, Peter Duijnstee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-17 00:00:00.000000000 Z
11
+ date: 2022-11-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Easily retry a block of code a predetermined number of times
14
14
  email:
@@ -19,6 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - ".rspec"
21
21
  - ".rubocop.yml"
22
+ - ".ruby-version"
22
23
  - CHANGELOG.md
23
24
  - CODE_OF_CONDUCT.md
24
25
  - Gemfile
@@ -26,6 +27,7 @@ files:
26
27
  - LICENSE.txt
27
28
  - README.md
28
29
  - Rakefile
30
+ - easy_retry.gemspec
29
31
  - lib/easy_retry.rb
30
32
  - lib/easy_retry/version.rb
31
33
  - sig/easy_retry.rbs