def_retry 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: b8135d8dde0024aa8f7c3fae3dc94d24090069a8
4
- data.tar.gz: 34676cab8df574cd252696df1eedb1ecaa7c1735
3
+ metadata.gz: d35fdb197f95fa60911086e999f70e25d327c6c9
4
+ data.tar.gz: fa7195d2881db3c9ff1a392d771166ea4731ed68
5
5
  SHA512:
6
- metadata.gz: 25d6cd7b5542f9fd097efdd70235eb9d15d7665dbde15b652366fbe5c29c17e3f383bf52058d894f6f7efc27d282f0c21bfd89c83bd80eaa00996c3e4ac0f4d0
7
- data.tar.gz: 403d871e8ff226d1e41d8168db1888f999d7699707d744d7525b89955f6a92b30426cfd4d9c26e76806c2541abc9c433144bfa0165ee14d20824b789da267060
6
+ metadata.gz: dd716852f0c4ed1db2d49827c2eb5b06579270d09bf51d6a7433f58f786c516fa503e4898677fb6014e338146203e8d45d9c91809e5bf1efa864c8738a2a4127
7
+ data.tar.gz: acca16ef89d89f276093c66d158f05f1c142684adbf433fbe84bb87d75433659da79a1c4976d77fef14e55dc58dbfadb3e00ebd411b72fb2aef6ef09aea3f52f
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/def_retry.svg)](http://badge.fury.io/rb/def_retry)
2
2
 
3
-
3
+ [![Build Status](https://travis-ci.org/DiegoSalazar/DefRetry.svg?branch=master)](https://travis-ci.org/DiegoSalazar/DefRetry)
4
4
 
5
5
  # DefRetry
6
6
 
data/Rakefile CHANGED
@@ -1,2 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
2
3
 
4
+ RSpec::Core::RakeTask.new :spec
5
+ task default: :spec
@@ -7,11 +7,11 @@ module DefRetry
7
7
  exponential: ->(n) { n**2 }
8
8
  }
9
9
 
10
- def initialize(options, block)
11
- @block = block
10
+ def initialize(options)
12
11
  @tries = options.fetch :tries, DEFAULT_TRIES
13
12
  @on_retry = options.fetch :on_retry, ->(e, n) {}
14
13
  @on_ensure = options.fetch :on_ensure, ->(r, n) {}
14
+ @re_raise = options.fetch :re_raise, true
15
15
  @sleep = options.fetch :sleep, false
16
16
 
17
17
  begin
@@ -27,18 +27,22 @@ module DefRetry
27
27
  end
28
28
  end
29
29
 
30
- def run
30
+ def run(&block)
31
31
  @try_count = 0
32
32
  @return = nil
33
33
 
34
34
  begin
35
- @return = @block.call
35
+ @return = block.call
36
36
  rescue *@exceptions => e
37
37
  @try_count += 1
38
38
  sleep @sleep.call(@try_count) if @sleep
39
39
  @on_retry.call e, @try_count
40
40
 
41
- retry if @try_count < @tries
41
+ if @try_count < @tries
42
+ retry
43
+ elsif @re_raise
44
+ raise e
45
+ end
42
46
  ensure
43
47
  @on_ensure.call @return, @try_count
44
48
  @return
@@ -1,3 +1,3 @@
1
1
  module DefRetry
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/def_retry.rb CHANGED
@@ -9,7 +9,7 @@ module DefRetry
9
9
  end
10
10
 
11
11
  def self.retry(options, &block)
12
- Retrier.new(options, block).run
12
+ Retrier.new(options).run &block
13
13
  end
14
14
 
15
15
  module ClassMethods
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: def_retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Salazar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-02 00:00:00.000000000 Z
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler