stud 0.0.19 → 0.0.20

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stud/try.rb +8 -4
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a4b79f1e9525c9b5a8920995914b03ab592eae5
4
- data.tar.gz: 69aa0f87e438be09646bb70735deab7182b0854c
3
+ metadata.gz: 043d894e086db497a69acd64b79959ff1d499094
4
+ data.tar.gz: 718d29583632e07330fb566c2ca989c85005937a
5
5
  SHA512:
6
- metadata.gz: 7cf9c02aaff8a6e09611a961dcc6ee1f8955130c9b7102ea1a582d5b46a358c20fcb48d9c4fce9a661000ead4e567c560249efb781e516bf341dfc9d7a02909f
7
- data.tar.gz: 4ed206e65a84d4416280094d42fc235fc2c8828d53d6b80a175fb77fe7f5358775d4cba0b392666e1d559e3995a6c458584f1b17bd86603c6a8fd370bae3eaad
6
+ metadata.gz: 1f03605eaf45f0794aec60bb9db10ba5166a98fa23cca18538a64fc2e95e98a75c84a9e2cd5fc599e9528809689fcfe9575ffa36ff508db3c024c3344f9d09ce
7
+ data.tar.gz: 9a921cdf385d9cc2bc137ba5e7fc11e544a651370181bb21cb6ed050b795065bf3e929be09bd97dbb4b641f7b7b32969a6b4f4e2b097d388092ca78121ba3f9a
@@ -25,6 +25,8 @@ module Stud
25
25
 
26
26
  BACKOFF_SCHEDULE = [0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.0]
27
27
 
28
+ DEFAULT_CATCHABLE_EXCEPTIONS = [StandardError]
29
+
28
30
  # Log a failure.
29
31
  #
30
32
  # You should override this method if you want a better logger.
@@ -51,6 +53,8 @@ module Stud
51
53
  # that number of times. If this value is omitted or nil, we will try until
52
54
  # success with no limit on the number of tries.
53
55
  #
56
+ # exceptions - the type of exceptions to retry, we use `StandardError` by default.
57
+ #
54
58
  # Returns the return value of the block once the block succeeds.
55
59
  # Raises the last seen exception if we run out of tries.
56
60
  #
@@ -69,7 +73,7 @@ module Stud
69
73
  #
70
74
  # # Try forever
71
75
  # return_value = try { ... }
72
- def try(enumerable=FOREVER, &block)
76
+ def try(enumerable=FOREVER, exceptions=DEFAULT_CATCHABLE_EXCEPTIONS, &block)
73
77
  if block.arity == 0
74
78
  # If the block takes no arguments, give none
75
79
  procedure = lambda { |val| return block.call }
@@ -92,7 +96,7 @@ module Stud
92
96
  rescue NoMethodError, NameError
93
97
  # Abort immediately on exceptions that are unlikely to recover.
94
98
  raise
95
- rescue => exception
99
+ rescue *exceptions => exception
96
100
  last_exception = exception
97
101
  fail_count += 1
98
102
 
@@ -115,8 +119,8 @@ module Stud
115
119
 
116
120
  TRY = Try.new
117
121
  # A simple try method for the common case.
118
- def try(enumerable=Stud::Try::FOREVER, &block)
119
- return TRY.try(enumerable, &block)
122
+ def try(enumerable=Stud::Try::FOREVER, exceptions=Try::DEFAULT_CATCHABLE_EXCEPTIONS, &block)
123
+ return TRY.try(enumerable, exceptions, &block)
120
124
  end # def try
121
125
 
122
126
  extend self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Sissel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-30 00:00:00.000000000 Z
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -77,8 +77,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubyforge_project:
80
- rubygems_version: 2.4.3
80
+ rubygems_version: 2.4.6
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: stud - common code techniques
84
84
  test_files: []
85
+ has_rdoc: