tries 0.3.2 → 0.4.0

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
- SHA1:
3
- metadata.gz: 61181357d15ed1c01e9fff117ef6e64d5c6d4ae1
4
- data.tar.gz: 06dd565ca5158e5102d00e972b777863d3dc361c
2
+ SHA256:
3
+ metadata.gz: d193d0d7a484d18a5547a11721670dbf6f84bdd9fafcf6969ec98f4fc114c6ac
4
+ data.tar.gz: faae79f6f420ff3a2d4a08aa5c2daadb78fc71ddb37f82feaf22c7e4b29f4ef1
5
5
  SHA512:
6
- metadata.gz: 4434eb20bb7e2ca1bcdabf9dbfd2c4b26f48d53727c8f0aefde1d6d84e6dc3e851e7a598f3dbc37622842c0ab334f95bd6c8a3cdf229b9e7f65610546d63729f
7
- data.tar.gz: 1d54e37a1a3625af236d0b4d7f7685018062cd4e6d4f40fa33d4a3185b4cfe4302734b0b41fce134276ece4a9cba1ddb3002f42661b583ee9fc012cbcdfda2d5
6
+ metadata.gz: 91a392538f78b1524f258e7890b6d0b26890f663d12decf2477f6f33940a91dd8e03a8f0d767580baa0448be5c0b832441f5eef8bde3a29aa7021c90ee6839ae
7
+ data.tar.gz: 13695ccfd9c78d735a3b95971cafe23c909e1a983be8a3ea4d1344ba5132c0f29e453f8fc10468368fa64ba286e7d6f487481db5f324ae041d8d9bec21396d75
@@ -1,7 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.0
7
- - jruby
3
+ - 2.2.7
4
+ - 2.3.4
5
+ - 2.4.1
6
+ before_install:
7
+ - gem update --system
8
+ - gem update bundler
9
+ sudo: false
data/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- guard 'rspec', cli: '--drb --profile', all_after_pass: false do
1
+ guard 'rspec', all_on_start: true, all_after_pass: true do
2
2
  # Specs
3
3
  watch(%r(^spec/.+_spec\.rb$))
4
4
  watch('spec/spec_helper.rb') { 'spec' }
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  # Tries
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/tries.png)](http://badge.fury.io/rb/tries)
4
- [![Build Status](https://secure.travis-ci.org/krautcomputing/tries.png)](http://travis-ci.org/krautcomputing/tries)
5
- [![Dependency Status](https://gemnasium.com/krautcomputing/tries.png)](https://gemnasium.com/krautcomputing/tries)
6
- [![Code Climate](https://codeclimate.com/github/krautcomputing/tries.png)](https://codeclimate.com/github/krautcomputing/tries)
4
+ [![Build Status](https://secure.travis-ci.org/manuelmeurer/tries.png)](http://travis-ci.org/manuelmeurer/tries)
7
5
 
8
6
  Solidify your code and retry on petty exceptions.
9
7
 
@@ -11,8 +9,6 @@ Tries lets you retry a block of code multiple times, which is convenient for exa
11
9
 
12
10
  You can specify exactly how often the block of code is retried and which exceptions are caught.
13
11
 
14
- Read the accompanying [blog post](http://www.krautcomputing.com/blog/2012/12/19/new-gem-tries/).
15
-
16
12
  ## Requirements
17
13
 
18
14
  Ruby >= 1.9.2
@@ -54,8 +50,8 @@ def method_that_raises_exception
54
50
  puts "Counter is #{@error_counter}"
55
51
 
56
52
  case @error_counter
57
- when 1 then raise FooError
58
- when 2 then raise FooError
53
+ when 1 then raise FooError, 'retry'
54
+ when 2 then raise FooError, 'retry'
59
55
  when 3 then raise BarError
60
56
  when 4 then raise StandardError
61
57
  end
@@ -106,6 +102,19 @@ end
106
102
  # => StandardError
107
103
  ```
108
104
 
105
+ ### Rescue error on condition
106
+
107
+ ```ruby
108
+ 3.tries if: ->(error) { error.message == 'retry' } do
109
+ method_that_raises_exception
110
+ end
111
+
112
+ # => Counter is 1
113
+ # => Counter is 2
114
+ # => Counter is 3
115
+ # => BarError
116
+ ```
117
+
109
118
  ### Delay execution after error
110
119
 
111
120
  `delay` is in seconds, fractions are possible
@@ -231,3 +240,7 @@ end
231
240
  3. Commit your changes (`git commit -am 'Add some feature'`)
232
241
  4. Push to the branch (`git push origin my-new-feature`)
233
242
  5. Create new Pull Request
243
+
244
+ ## Support
245
+
246
+ If you like this project, consider [buying me a coffee](https://www.buymeacoffee.com/279lcDtbF)! :)
@@ -15,13 +15,16 @@ class Integer
15
15
  exception_classes = Array(options[:on] || StandardError)
16
16
  delay = options[:delay]
17
17
  incremental = options[:incremental]
18
+ condition = options[:if]
18
19
 
19
20
  begin
20
21
  return yield
21
22
  rescue *exception_classes => exception
23
+ raise exception if condition && !condition.call(exception)
22
24
  next_delay = calculate_delay(delay, attempts, incremental) if delay
23
- Tries.configuration.on_error.call(exception, attempts, next_delay) if Tries.configuration.on_error
24
- options[:on_error].call(exception, attempts, next_delay) if options[:on_error]
25
+ [Tries.configuration.on_error, options[:on_error]].compact.each do |on_error_callback|
26
+ on_error_callback.call(exception, attempts, next_delay)
27
+ end
25
28
  Kernel.sleep next_delay if delay
26
29
  retry if (attempts += 1) <= self
27
30
  end
@@ -30,8 +33,9 @@ class Integer
30
33
  end
31
34
 
32
35
  private
33
- def calculate_delay(delay, attempts, incremental)
34
- return delay unless incremental
35
- (delay * attempts * 100).round.to_f / 100
36
- end
36
+
37
+ def calculate_delay(delay, attempts, incremental)
38
+ return delay unless incremental
39
+ (delay * attempts * 100).round.to_f / 100
40
+ end
37
41
  end
@@ -1,3 +1,3 @@
1
1
  module Tries
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -1,7 +1,6 @@
1
1
  require 'tries'
2
2
 
3
3
  RSpec.configure do |config|
4
- config.treat_symbols_as_metadata_keys_with_true_values = true
5
4
  config.run_all_when_everything_filtered = true
6
5
  config.filter_run :focus
7
6
  config.order = 'random'
@@ -64,7 +64,7 @@ describe Tries do
64
64
 
65
65
  context 'static delay' do
66
66
  it 'sleeps the specified delay' do
67
- Kernel.should_receive(:sleep).with(0.1).exactly(2).times
67
+ expect(Kernel).to receive(:sleep).with(0.1).exactly(2).times
68
68
 
69
69
  begin
70
70
  3.tries on: FooError, delay: delay do
@@ -77,9 +77,9 @@ describe Tries do
77
77
 
78
78
  context 'incremental delay' do
79
79
  it 'sleeps incrementally' do
80
- Kernel.should_receive(:sleep).with(0.1).ordered
81
- Kernel.should_receive(:sleep).with(0.2).ordered
82
- Kernel.should_receive(:sleep).with(0.3).ordered
80
+ expect(Kernel).to receive(:sleep).with(0.1).ordered
81
+ expect(Kernel).to receive(:sleep).with(0.2).ordered
82
+ expect(Kernel).to receive(:sleep).with(0.3).ordered
83
83
 
84
84
  begin
85
85
  3.tries on: [FooError, BarError], delay: delay, incremental: true do
@@ -98,9 +98,9 @@ describe Tries do
98
98
  Tries.configure do |config|
99
99
  config.on_error = global_on_error
100
100
  end
101
- global_on_error.should_receive(:call).with(an_instance_of(FooError), 1, 0.1).ordered
102
- global_on_error.should_receive(:call).with(an_instance_of(FooError), 2, 0.2).ordered
103
- global_on_error.should_receive(:call).with(an_instance_of(BarError), 3, 0.3).ordered
101
+ expect(global_on_error).to receive(:call).with(an_instance_of(FooError), 1, 0.1).ordered
102
+ expect(global_on_error).to receive(:call).with(an_instance_of(FooError), 2, 0.2).ordered
103
+ expect(global_on_error).to receive(:call).with(an_instance_of(BarError), 3, 0.3).ordered
104
104
  begin
105
105
  3.tries on: [FooError, BarError], delay: 0.1, incremental: true do
106
106
  raise_foo_foo_bar_bar_standard
@@ -113,9 +113,9 @@ describe Tries do
113
113
  context 'when a local callback is set' do
114
114
  it 'calls the local callback with the correct parameters' do
115
115
  local_on_error = Proc.new {}
116
- local_on_error.should_receive(:call).with(an_instance_of(FooError), 1, 0.1).ordered
117
- local_on_error.should_receive(:call).with(an_instance_of(FooError), 2, 0.2).ordered
118
- local_on_error.should_receive(:call).with(an_instance_of(BarError), 3, 0.3).ordered
116
+ expect(local_on_error).to receive(:call).with(an_instance_of(FooError), 1, 0.1).ordered
117
+ expect(local_on_error).to receive(:call).with(an_instance_of(FooError), 2, 0.2).ordered
118
+ expect(local_on_error).to receive(:call).with(an_instance_of(BarError), 3, 0.3).ordered
119
119
  begin
120
120
  3.tries on: [FooError, BarError], delay: 0.1, incremental: true, on_error: local_on_error do
121
121
  raise_foo_foo_bar_bar_standard
@@ -128,12 +128,12 @@ describe Tries do
128
128
  context 'when both a global and a local callback are set' do
129
129
  it 'calls both callbacks with the correct parameters in the correct order' do
130
130
  local_on_error, global_on_error = Proc.new {}, Proc.new {}
131
- global_on_error.should_receive(:call).with(an_instance_of(FooError), 1, 0.1).ordered
132
- local_on_error.should_receive(:call).with(an_instance_of(FooError), 1, 0.1).ordered
133
- global_on_error.should_receive(:call).with(an_instance_of(FooError), 2, 0.2).ordered
134
- local_on_error.should_receive(:call).with(an_instance_of(FooError), 2, 0.2).ordered
135
- global_on_error.should_receive(:call).with(an_instance_of(BarError), 3, 0.3).ordered
136
- local_on_error.should_receive(:call).with(an_instance_of(BarError), 3, 0.3).ordered
131
+ expect(global_on_error).to receive(:call).with(an_instance_of(FooError), 1, 0.1).ordered
132
+ expect(local_on_error).to receive(:call).with(an_instance_of(FooError), 1, 0.1).ordered
133
+ expect(global_on_error).to receive(:call).with(an_instance_of(FooError), 2, 0.2).ordered
134
+ expect(local_on_error).to receive(:call).with(an_instance_of(FooError), 2, 0.2).ordered
135
+ expect(global_on_error).to receive(:call).with(an_instance_of(BarError), 3, 0.3).ordered
136
+ expect(local_on_error).to receive(:call).with(an_instance_of(BarError), 3, 0.3).ordered
137
137
  Tries.configure do |config|
138
138
  config.on_error = global_on_error
139
139
  end
@@ -9,11 +9,11 @@ Gem::Specification.new do |gem|
9
9
  gem.name = 'tries'
10
10
  gem.version = Tries::VERSION
11
11
  gem.platform = Gem::Platform::RUBY
12
- gem.authors = ['Manuel Meurer']
12
+ gem.author = 'Manuel Meurer'
13
13
  gem.email = 'manuel@krautcomputing.com'
14
14
  gem.summary = 'Solidify your code and retry on petty exceptions'
15
15
  gem.description = 'Solidify your code and retry on petty exceptions'
16
- gem.homepage = 'https://github.com/krautcomputing/tries'
16
+ gem.homepage = ''
17
17
  gem.license = 'MIT'
18
18
 
19
19
  gem.files = `git ls-files`.split($/)
@@ -22,9 +22,9 @@ Gem::Specification.new do |gem|
22
22
  gem.require_paths = ['lib']
23
23
 
24
24
  gem.add_development_dependency 'rake', '>= 0.9.0'
25
- gem.add_development_dependency 'rspec', '~> 2.13.0'
26
- gem.add_development_dependency 'rb-fsevent', '~> 0.9.2'
27
- gem.add_development_dependency 'guard-rspec', '~> 2.5.0'
25
+ gem.add_development_dependency 'rspec', '~> 3.0'
26
+ gem.add_development_dependency 'rb-fsevent', '~> 0.9'
27
+ gem.add_development_dependency 'guard-rspec', '~> 4.2'
28
28
  # Listen >= 2.0.0 only works with Ruby >= 1.9.3
29
29
  gem.add_development_dependency 'listen', '< 2.0.0' if RUBY_VERSION < '1.9.3'
30
30
  gem.add_runtime_dependency 'gem_config', '~> 0.2'
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tries
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-18 00:00:00.000000000 Z
11
+ date: 2020-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.9.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.9.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.13.0
33
+ version: '3.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.13.0
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rb-fsevent
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.9.2
47
+ version: '0.9'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.9.2
54
+ version: '0.9'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: guard-rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 2.5.0
61
+ version: '4.2'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 2.5.0
68
+ version: '4.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: gem_config
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.2'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.2'
83
83
  description: Solidify your code and retry on petty exceptions
@@ -86,8 +86,8 @@ executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
88
88
  files:
89
- - .gitignore
90
- - .travis.yml
89
+ - ".gitignore"
90
+ - ".travis.yml"
91
91
  - Gemfile
92
92
  - Guardfile
93
93
  - LICENSE.txt
@@ -98,7 +98,7 @@ files:
98
98
  - spec/spec_helper.rb
99
99
  - spec/tries/tries_spec.rb
100
100
  - tries.gemspec
101
- homepage: https://github.com/krautcomputing/tries
101
+ homepage: ''
102
102
  licenses:
103
103
  - MIT
104
104
  metadata: {}
@@ -108,21 +108,19 @@ require_paths:
108
108
  - lib
109
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - '>='
111
+ - - ">="
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - '>='
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.2.0
120
+ rubygems_version: 3.1.2
122
121
  signing_key:
123
122
  specification_version: 4
124
123
  summary: Solidify your code and retry on petty exceptions
125
124
  test_files:
126
125
  - spec/spec_helper.rb
127
126
  - spec/tries/tries_spec.rb
128
- has_rdoc: