method_decorators 0.9.4 → 0.9.5
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed79ca8949f564d8260a8e2f3d6ca6c25a4c6087
|
4
|
+
data.tar.gz: e300b088390c17c198cf7a22ba105dd547fde0ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc6ef5fd815700115771f75782619fb7ea726dcc9ab60e155c68e1deeb6fa3e2aea6f8f831413541bd39c63a6a9676d9b60a2ea9fee4702594dfaaf4ce483264
|
7
|
+
data.tar.gz: 75c088d37f52ea4c695f5da57b71bd8674912b8e615fab19f3089639716b11fadb6da5dca66a8e162f096f3ecd181ed72a5163ec40ad3f923f2a1d73102c9395
|
@@ -2,8 +2,9 @@ require "method_decorators"
|
|
2
2
|
|
3
3
|
module MethodDecorators
|
4
4
|
class Retry < Decorator
|
5
|
-
def initialize(max)
|
5
|
+
def initialize(max, options = {})
|
6
6
|
@max = max
|
7
|
+
@options = options
|
7
8
|
end
|
8
9
|
|
9
10
|
def call(orig, this, *args, &blk)
|
@@ -12,7 +13,10 @@ module MethodDecorators
|
|
12
13
|
attempts += 1
|
13
14
|
orig.call(*args, &blk)
|
14
15
|
rescue
|
15
|
-
|
16
|
+
if attempts < @max
|
17
|
+
sleep(@options[:sleep]) if @options[:sleep]
|
18
|
+
retry
|
19
|
+
end
|
16
20
|
raise
|
17
21
|
end
|
18
22
|
end
|
@@ -17,6 +17,16 @@ describe MethodDecorators::Retry do
|
|
17
17
|
method.should_receive(:call).once.and_return(3)
|
18
18
|
subject.call(method, nil).should == 3
|
19
19
|
end
|
20
|
+
|
21
|
+
context 'when :sleep is given to #initialize' do
|
22
|
+
subject { MethodDecorators::Retry.new(3, :sleep => 5) }
|
23
|
+
|
24
|
+
it 'sleeps after failures before retrying' do
|
25
|
+
method.stub(:call) { raise ArgumentError }
|
26
|
+
subject.should_receive(:sleep).with(5).exactly(2).times
|
27
|
+
expect { subject.call(method, nil) }.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
end
|
20
30
|
end
|
21
31
|
|
22
32
|
describe "acceptance" do
|
@@ -33,7 +43,7 @@ describe MethodDecorators::Retry do
|
|
33
43
|
end
|
34
44
|
subject { klass.new }
|
35
45
|
|
36
|
-
it
|
46
|
+
it 'retries calls to the method' do
|
37
47
|
subject.do_it(1).should == 2
|
38
48
|
end
|
39
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_decorators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Fairley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -68,7 +68,7 @@ files:
|
|
68
68
|
- lib/method_decorators/version.rb
|
69
69
|
- lib/method_decorators/within.rb
|
70
70
|
- method_decorators.gemspec
|
71
|
-
- spec/decorators/
|
71
|
+
- spec/decorators/deprecated_spec.rb
|
72
72
|
- spec/decorators/memoize_spec.rb
|
73
73
|
- spec/decorators/precondition_spec.rb
|
74
74
|
- spec/decorators/retry_spec.rb
|
@@ -102,7 +102,7 @@ signing_key:
|
|
102
102
|
specification_version: 4
|
103
103
|
summary: Python's function decorators for Ruby
|
104
104
|
test_files:
|
105
|
-
- spec/decorators/
|
105
|
+
- spec/decorators/deprecated_spec.rb
|
106
106
|
- spec/decorators/memoize_spec.rb
|
107
107
|
- spec/decorators/precondition_spec.rb
|
108
108
|
- spec/decorators/retry_spec.rb
|