dirty_pipeline 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dirty_pipeline/base.rb +0 -1
- data/lib/dirty_pipeline/transition.rb +18 -15
- data/lib/dirty_pipeline/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6871bd0a1aaa3608ff81749b66157171ea26d1881774fa8ba221cd0ce3f88b4b
|
4
|
+
data.tar.gz: 81c5a14ab2bb2f4437175171e7afe65dbe75006d7f4a48bf2fd8fc3b2e947721
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f896cc7c517490b1f0a942f17f7df16a0e27ff67bb87f64e46dd0665c3b6444aebd58e0ca7d0d882af5ab7708f411b1caf1904ab229693b5785690ab97779aa1
|
7
|
+
data.tar.gz: 5ff0a159e5b00963a1685ff94c425090d4f8aecaf855fff6e588e85f40e6aadbb199b41be26adcab512027727839ad968c3355a9302dd6709d8b75b5f34cc1da
|
data/lib/dirty_pipeline/base.rb
CHANGED
@@ -1,45 +1,48 @@
|
|
1
1
|
module DirtyPipeline
|
2
2
|
class Transition
|
3
|
-
def
|
3
|
+
def Failure(error)
|
4
|
+
railway.switch_to(:undo)
|
4
5
|
throw :fail_transition, error
|
5
6
|
end
|
6
7
|
|
7
8
|
def Success(changes = nil)
|
9
|
+
case railway.active
|
10
|
+
when "call"
|
11
|
+
railway.switch_to(:finalize) if respond_to?(:finalize)
|
12
|
+
when "finalize"
|
13
|
+
railway.switch_to(:call)
|
14
|
+
end
|
8
15
|
throw :success, changes.to_h
|
9
16
|
end
|
10
|
-
|
11
17
|
def self.finalize(*args, **kwargs)
|
12
18
|
event, pipeline, *args = args
|
13
|
-
instance = new(event, *args, **kwargs)
|
19
|
+
instance = new(event, pipeline.railway, *args, **kwargs)
|
14
20
|
return unless instance.respond_to?(:finalize)
|
15
|
-
pipeline.railway.switch_to(:call)
|
16
21
|
instance.finalize(pipeline.subject)
|
17
22
|
end
|
18
23
|
|
19
24
|
def self.undo(*args, **kwargs)
|
20
25
|
event, pipeline, *args = args
|
21
|
-
instance = new(event, *args, **kwargs)
|
26
|
+
instance = new(event, pipeline.railway, *args, **kwargs)
|
22
27
|
return unless instance.respond_to?(:undo)
|
23
28
|
instance.undo(pipeline.subject)
|
24
29
|
end
|
25
30
|
|
26
31
|
def self.call(*args, **kwargs)
|
27
32
|
event, pipeline, *args = args
|
28
|
-
instance = new(event, *args, **kwargs)
|
29
|
-
pipeline.railway[:undo] << event
|
30
|
-
|
31
|
-
|
32
|
-
pipeline.railway.switch_to(:finalize)
|
33
|
-
end
|
34
|
-
new(event, *args, **kwargs).call(pipeline.subject)
|
33
|
+
instance = new(event, pipeline.railway, *args, **kwargs)
|
34
|
+
pipeline.railway[:undo] << event
|
35
|
+
pipeline.railway[:finalize] << event
|
36
|
+
instance.call(pipeline.subject)
|
35
37
|
end
|
36
38
|
|
37
|
-
attr_reader :event
|
38
|
-
def initialize(event, *, **)
|
39
|
+
attr_reader :event, :railway
|
40
|
+
def initialize(event, railway, *, **)
|
39
41
|
@event = event
|
42
|
+
@railway = railway
|
40
43
|
end
|
41
44
|
|
42
|
-
def
|
45
|
+
def cache(key)
|
43
46
|
event.cache.fetch(key) { event.cache[key] = yield }
|
44
47
|
end
|
45
48
|
end
|