work_list 0.1.0 → 0.2.0

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: 96b3b0ca7c32449972268dd1ac7ecbdb83470af3
4
- data.tar.gz: f4ec1a43794472d222e00a32c1a98313e5e1337a
3
+ metadata.gz: f0b76f7f951d3892ed1fc494199469f9376ffbe7
4
+ data.tar.gz: 73403e93932e6b35da01db314e471d390930c67a
5
5
  SHA512:
6
- metadata.gz: b82f98c0b49335f845ffaddb905aeb012a9a32015c2e7b59455a02efdeab9ed4f944d6b0c878da537a7686d39d529939581df03721eb7744926a1995fe0ad86a
7
- data.tar.gz: 821004816722e56fa7d21f14e09d76ccad9adbbb35457fff4f3a2c8561aa472592cefa1d86ede742586d979a05eb6109ac7cc605a59fb2352a280e8a85d20c1b
6
+ metadata.gz: 2352bd104ca8ab8bd4a55f4fd3b2d623c236845441ab730132fadc44c27cf0df1d9b875c85e74b65faf7e8f4ffbda47aa3eb2fed0daa3a56d88c70573953b150
7
+ data.tar.gz: f5069a2a9b4841e78dd271737b49791866a2186a7c4ce871e28b06e9d4722b8a69354c5cfb8a4f3852f0cf14d54ac4d8c4c5ee481d26be7023456b33ba23df89
@@ -8,7 +8,7 @@ module WorkList
8
8
  @failures = 0
9
9
  end
10
10
 
11
- def success(result)
11
+ def record_success(result)
12
12
  @successes += 1
13
13
  @items << {
14
14
  result: result,
@@ -17,7 +17,7 @@ module WorkList
17
17
  }
18
18
  end
19
19
 
20
- def failure(exception)
20
+ def record_failure(exception)
21
21
  @failures += 1
22
22
  @items << {
23
23
  result: nil,
@@ -43,11 +43,39 @@ module WorkList
43
43
  end
44
44
 
45
45
  def failure?
46
- !success? && !noop?
46
+ @failures > 0
47
47
  end
48
48
 
49
49
  def noop?
50
50
  @items.empty?
51
51
  end
52
+
53
+ def all_failures?
54
+ failure_rate == 1.0
55
+ end
56
+
57
+ def failure_rate
58
+ if noop?
59
+ 0
60
+ else
61
+ Rational(@failures, @items.count)
62
+ end
63
+ end
64
+
65
+ def raise_if_failure
66
+ raise_exception if failure?
67
+ end
68
+
69
+ def raise_if_all_failures
70
+ raise_exception if all_failures?
71
+ end
72
+
73
+ def raise_if_failure_rate(threshold)
74
+ raise_exception if failure_rate >= threshold
75
+ end
76
+
77
+ def raise_exception
78
+ raise exceptions.first
79
+ end
52
80
  end
53
81
  end
@@ -1,3 +1,3 @@
1
1
  module WorkList
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/work_list.rb CHANGED
@@ -7,17 +7,12 @@ module WorkList
7
7
 
8
8
  items.each do |item|
9
9
  begin
10
- results.success(block.call(item))
10
+ results.record_success(block.call(item))
11
11
  rescue => exception
12
- results.failure(exception)
12
+ results.record_failure(exception)
13
13
  end
14
14
  end
15
15
 
16
- if results.failure?
17
- # Raise the first exception, as if we weren't rescuing them.
18
- raise results.exceptions.first
19
- else
20
- results
21
- end
16
+ results
22
17
  end
23
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: work_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory Kaufman-Schofield
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-10 00:00:00.000000000 Z
11
+ date: 2018-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.6.13
94
+ rubygems_version: 2.6.14
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Better exception handling for operating on arrays