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: 6785de47236233823f549e66f287ee890f124a26
4
- data.tar.gz: 4ecf3e013b9f697ae331f0b437141527a8cf9d09
3
+ metadata.gz: ed79ca8949f564d8260a8e2f3d6ca6c25a4c6087
4
+ data.tar.gz: e300b088390c17c198cf7a22ba105dd547fde0ad
5
5
  SHA512:
6
- metadata.gz: 20d7254686c1318bf47f5c652c2ca58fbfcd00beb215beebaa506997a0c36c4428e3c5074cec2783ba7a344a30aff039395fc24143e8ba1a5bd65148b7526bce
7
- data.tar.gz: da3881d7736c32a1ecc9412b1fcacef497f7668d0d34a412bb5a758dbc1ab4f3f738b35aaf6858950600e0bcd3a766cc76dc60ee4194bdf0b79abaa22d82f05b
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
- retry if attempts < @max
16
+ if attempts < @max
17
+ sleep(@options[:sleep]) if @options[:sleep]
18
+ retry
19
+ end
16
20
  raise
17
21
  end
18
22
  end
@@ -1,3 +1,3 @@
1
1
  module MethodDecorators
2
- VERSION = "0.9.4"
2
+ VERSION = "0.9.5"
3
3
  end
@@ -53,6 +53,10 @@ describe MethodDecorators::Deprecated do
53
53
  $stderr.rewind
54
54
  end
55
55
 
56
+ after do
57
+ $stderr = STDERR
58
+ end
59
+
56
60
  let(:klass) {
57
61
  Class.new Base do
58
62
  +MethodDecorators::Deprecated
@@ -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 "memoizes calls to the method" do
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
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-01-29 00:00:00.000000000 Z
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/deprecated.rb
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/deprecated.rb
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