cooperator 0.2.0 → 0.2.1
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 +4 -4
- data/lib/cooperator/version.rb +1 -1
- data/lib/cooperator.rb +18 -0
- data/spec/rollback.rb +67 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1840d5e84fd43296da1b4460ca7b48115e8dc75b
|
4
|
+
data.tar.gz: 82673faac1bd47f7f6462c59780298bac5dbc2c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 492360064a627fc2e44907a469eb97c980f8ea31d6019d90075d8c1fd2ccac36956d818c661b255a263edce14c0b1e7be152e2a78a6a9a039ecc68c0380c13a0
|
7
|
+
data.tar.gz: b3b84a56b62387e8bc9b88b762ecc9eed0d47b607572dfc9c862c5162fcad56ef612fc5b7dc6e4606641946dff33e84500e02a0c8e4e437bb21dd6df50790859
|
data/lib/cooperator/version.rb
CHANGED
data/lib/cooperator.rb
CHANGED
@@ -62,6 +62,14 @@ module Cooperator
|
|
62
62
|
|
63
63
|
action.context
|
64
64
|
end
|
65
|
+
|
66
|
+
def rollback(context = {})
|
67
|
+
action = new context
|
68
|
+
|
69
|
+
action.rollback if action.respond_to? :rollback
|
70
|
+
|
71
|
+
action.context
|
72
|
+
end
|
65
73
|
end
|
66
74
|
|
67
75
|
def context
|
@@ -77,10 +85,20 @@ module Cooperator
|
|
77
85
|
end
|
78
86
|
|
79
87
|
def cooperate(*actions)
|
88
|
+
done = []
|
89
|
+
|
80
90
|
actions.each do |action|
|
81
91
|
action.perform context
|
82
92
|
|
83
93
|
break if context.failure?
|
94
|
+
|
95
|
+
done << action
|
96
|
+
end
|
97
|
+
|
98
|
+
if context.failure?
|
99
|
+
done.reverse.each do |action|
|
100
|
+
action.rollback context
|
101
|
+
end
|
84
102
|
end
|
85
103
|
end
|
86
104
|
|
data/spec/rollback.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'cooperator'
|
2
|
+
|
3
|
+
class First
|
4
|
+
prepend Cooperator
|
5
|
+
|
6
|
+
def perform
|
7
|
+
end
|
8
|
+
|
9
|
+
def rollback
|
10
|
+
$first = true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Second
|
15
|
+
prepend Cooperator
|
16
|
+
|
17
|
+
def perform
|
18
|
+
end
|
19
|
+
|
20
|
+
def rollback
|
21
|
+
$second = true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Third
|
26
|
+
prepend Cooperator
|
27
|
+
|
28
|
+
def perform
|
29
|
+
failure!
|
30
|
+
end
|
31
|
+
|
32
|
+
def rollback
|
33
|
+
$third = true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Interactor
|
38
|
+
prepend Cooperator
|
39
|
+
|
40
|
+
def perform
|
41
|
+
cooperate First, Second, Third
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
prepare do
|
46
|
+
$first = false
|
47
|
+
$second = false
|
48
|
+
$third = false
|
49
|
+
end
|
50
|
+
|
51
|
+
spec 'third rollback is not called when a failure is encountered' do
|
52
|
+
Interactor.perform
|
53
|
+
|
54
|
+
refute $third
|
55
|
+
end
|
56
|
+
|
57
|
+
spec 'second rollback is called when a failure is encountered' do
|
58
|
+
Interactor.perform
|
59
|
+
|
60
|
+
assert $second
|
61
|
+
end
|
62
|
+
|
63
|
+
spec 'first rollback is called when a failure is encountered' do
|
64
|
+
Interactor.perform
|
65
|
+
|
66
|
+
assert $first
|
67
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cooperator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erol Fornoles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- spec/perform.rb
|
61
61
|
- spec/predicates.rb
|
62
62
|
- spec/properties.rb
|
63
|
+
- spec/rollback.rb
|
63
64
|
- spec/success.rb
|
64
65
|
homepage: ''
|
65
66
|
licenses:
|
@@ -92,4 +93,5 @@ test_files:
|
|
92
93
|
- spec/perform.rb
|
93
94
|
- spec/predicates.rb
|
94
95
|
- spec/properties.rb
|
96
|
+
- spec/rollback.rb
|
95
97
|
- spec/success.rb
|