ztk 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'coveralls', :require => false
4
-
5
3
  gemspec
@@ -114,6 +114,8 @@ module ZTK
114
114
  # instead of performing retry on all exceptions.
115
115
  # @option options [Float,Integer] :delay (1) How long to sleep for between
116
116
  # each retry.
117
+ # @option options [Lambda,Proc] :on_retry (nil) A proc or lambda to call
118
+ # when we catch an exception and retry.
117
119
  #
118
120
  # @yield Block should execute the tasks to be rescued and retried if
119
121
  # needed.
@@ -133,10 +135,15 @@ module ZTK
133
135
  rescue options.on => e
134
136
  if ((options.tries -= 1) > 0)
135
137
  options.ui.logger.warn { "Caught #{e.inspect}, we will give it #{options.tries} more tr#{options.tries > 1 ? 'ies' : 'y'}." }
138
+
136
139
  sleep(options.delay)
140
+
141
+ options.on_retry and options.on_retry.call(e)
142
+
137
143
  retry
138
144
  else
139
145
  options.ui.logger.fatal { "Caught #{e.inspect} and we have no more tries left, sorry, we have to give up now." }
146
+
140
147
  raise e
141
148
  end
142
149
  end
data/lib/ztk/version.rb CHANGED
@@ -21,6 +21,6 @@
21
21
  module ZTK
22
22
 
23
23
  # ZTK Version String
24
- VERSION = "1.4.1"
24
+ VERSION = "1.4.2"
25
25
 
26
26
  end
@@ -73,6 +73,19 @@ describe ZTK::RescueRetry do
73
73
  $counter.should == 1
74
74
  end
75
75
 
76
+ it "should call our lambda when it catches an exception and retries" do
77
+ $counter = 0
78
+ on_retry_m = lambda { |exception|
79
+ $counter +=1
80
+ }
81
+ lambda {
82
+ ZTK::RescueRetry.try(:tries => 3, :on => EOFError, :on_retry => on_retry_m) do
83
+ raise EOFError
84
+ end
85
+ }.should raise_error EOFError
86
+ $counter.should == 2
87
+ end
88
+
76
89
  end
77
90
 
78
91
  end
data/ztk.gemspec CHANGED
@@ -46,4 +46,5 @@ Gem::Specification.new do |spec|
46
46
  spec.add_development_dependency("rspec")
47
47
  spec.add_development_dependency("yard")
48
48
  spec.add_development_dependency("redcarpet")
49
+ spec.add_development_dependency("coveralls")
49
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ztk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-29 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: erubis
@@ -155,6 +155,22 @@ dependencies:
155
155
  - - ! '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: coveralls
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
158
174
  description: Zachary's (DevOp) Tool Kit
159
175
  email:
160
176
  - zachary@jovelabs.com
@@ -247,7 +263,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
247
263
  version: '0'
248
264
  segments:
249
265
  - 0
250
- hash: -4161660178397173415
266
+ hash: -568917063704352555
251
267
  required_rubygems_version: !ruby/object:Gem::Requirement
252
268
  none: false
253
269
  requirements:
@@ -256,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
272
  version: '0'
257
273
  segments:
258
274
  - 0
259
- hash: -4161660178397173415
275
+ hash: -568917063704352555
260
276
  requirements: []
261
277
  rubyforge_project:
262
278
  rubygems_version: 1.8.25