decouplio 1.0.0alpha1 → 1.0.0alpha4
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/.circleci/config.yml +11 -1
- data/.rubocop.yml +7 -0
- data/README.md +12 -3
- data/benchmarks/Gemfile +2 -1
- data/benchmarks/multi_step_benchmark.rb +336 -0
- data/benchmarks/single_step_benchmark.rb +159 -0
- data/decouplio.gemspec +4 -4
- data/docker-compose.yml +13 -2
- data/lib/decouplio/action.rb +34 -3
- data/lib/decouplio/composer.rb +111 -22
- data/lib/decouplio/const/doby_aide_options.rb +15 -0
- data/lib/decouplio/const/error_messages.rb +9 -0
- data/lib/decouplio/const/reserved_methods.rb +13 -9
- data/lib/decouplio/const/results.rb +2 -0
- data/lib/decouplio/const/types.rb +19 -5
- data/lib/decouplio/const/validations/aide.rb +38 -0
- data/lib/decouplio/const/validations/doby.rb +36 -0
- data/lib/decouplio/const/validations/fail.rb +5 -1
- data/lib/decouplio/const/validations/octo.rb +2 -1
- data/lib/decouplio/errors/aide_can_not_be_first_step_error.rb +18 -0
- data/lib/decouplio/errors/aide_controversial_keys_error.rb +26 -0
- data/lib/decouplio/errors/aide_finish_him_error.rb +26 -0
- data/lib/decouplio/errors/doby_controversial_keys_error.rb +26 -0
- data/lib/decouplio/errors/doby_finish_him_error.rb +26 -0
- data/lib/decouplio/errors/execution_error.rb +20 -0
- data/lib/decouplio/errors/{fail_is_first_step_error.rb → fail_can_not_be_first_step_error.rb} +1 -1
- data/lib/decouplio/errors/step_is_not_defined_for_aide_error.rb +26 -0
- data/lib/decouplio/errors/step_is_not_defined_for_doby_error.rb +27 -0
- data/lib/decouplio/errors/step_is_not_defined_for_pass_error.rb +27 -0
- data/lib/decouplio/logic_dsl.rb +30 -3
- data/lib/decouplio/options_validator.rb +162 -13
- data/lib/decouplio/steps/aide.rb +37 -0
- data/lib/decouplio/steps/base_resq.rb +13 -3
- data/lib/decouplio/steps/doby.rb +14 -9
- data/lib/decouplio/steps/fail.rb +7 -22
- data/lib/decouplio/steps/inner_action_fail.rb +7 -22
- data/lib/decouplio/steps/inner_action_step.rb +7 -18
- data/lib/decouplio/steps/octo.rb +7 -2
- data/lib/decouplio/steps/service_fail.rb +11 -23
- data/lib/decouplio/steps/service_pass.rb +4 -1
- data/lib/decouplio/steps/service_step.rb +11 -19
- data/lib/decouplio/steps/shared/fail_resolver.rb +40 -0
- data/lib/decouplio/steps/shared/step_resolver.rb +43 -0
- data/lib/decouplio/steps/step.rb +7 -18
- data/lib/decouplio/steps/wrap.rb +7 -18
- data/lib/decouplio/validators/condition.rb +10 -0
- data/lib/decouplio/version.rb +1 -1
- metadata +30 -41
- data/benchmarks/benchmarks.rb +0 -527
- data/docs/_config.yml +0 -1
- data/docs/benchmarks.md +0 -1
- data/docs/context.md +0 -74
- data/docs/context.rb +0 -62
- data/docs/doby.md +0 -80
- data/docs/doby.rb +0 -38
- data/docs/error_store.md +0 -347
- data/docs/error_store.rb +0 -202
- data/docs/fail.md +0 -1016
- data/docs/fail.rb +0 -762
- data/docs/index.md +0 -25
- data/docs/inner_action.md +0 -63
- data/docs/inner_action.rb +0 -43
- data/docs/logic_block.md +0 -25
- data/docs/octo.md +0 -269
- data/docs/octo.rb +0 -164
- data/docs/pass.md +0 -309
- data/docs/pass.rb +0 -213
- data/docs/quick_start.md +0 -71
- data/docs/quick_start.rb +0 -38
- data/docs/resq.md +0 -263
- data/docs/resq.rb +0 -176
- data/docs/step.md +0 -737
- data/docs/step.rb +0 -526
- data/docs/step_as_a_service.md +0 -109
- data/docs/step_as_a_service.rb +0 -77
- data/docs/wrap.md +0 -232
- data/docs/wrap.rb +0 -137
data/docs/fail.rb
DELETED
@@ -1,762 +0,0 @@
|
|
1
|
-
require_relative '../lib/decouplio'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# Behavior
|
6
|
-
class SomeAction < Decouplio::Action
|
7
|
-
logic do
|
8
|
-
step :step_one
|
9
|
-
fail :fail_one
|
10
|
-
fail :fail_two
|
11
|
-
end
|
12
|
-
|
13
|
-
def step_one(param_for_step_one:, **)
|
14
|
-
param_for_step_one
|
15
|
-
end
|
16
|
-
|
17
|
-
def fail_one(**)
|
18
|
-
ctx[:action_failed] = true
|
19
|
-
end
|
20
|
-
|
21
|
-
def fail_two(**)
|
22
|
-
ctx[:fail_two] = 'Failure'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
success_action = SomeAction.call(param_for_step_one: true)
|
27
|
-
failure_action = SomeAction.call(param_for_step_one: false)
|
28
|
-
|
29
|
-
puts success_action # =>
|
30
|
-
# Result: success
|
31
|
-
|
32
|
-
# Railway Flow:
|
33
|
-
# step_one
|
34
|
-
|
35
|
-
# Context:
|
36
|
-
# {:param_for_step_one=>true}
|
37
|
-
|
38
|
-
# Errors:
|
39
|
-
# {}
|
40
|
-
|
41
|
-
|
42
|
-
puts failure_action # =>
|
43
|
-
# Result: failure
|
44
|
-
|
45
|
-
# Railway Flow:
|
46
|
-
# step_one -> fail_one -> fail_two
|
47
|
-
|
48
|
-
# Context:
|
49
|
-
# {:param_for_step_one=>false, :action_failed=>true, :fail_two=>"Failure"}
|
50
|
-
|
51
|
-
# Errors:
|
52
|
-
# {}
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# on_success: :finish_him
|
57
|
-
class SomeActionOnSuccessFinishHim < Decouplio::Action
|
58
|
-
logic do
|
59
|
-
step :step_one
|
60
|
-
fail :fail_one, on_success: :finish_him
|
61
|
-
fail :fail_two
|
62
|
-
end
|
63
|
-
|
64
|
-
def step_one(param_for_step_one:, **)
|
65
|
-
param_for_step_one
|
66
|
-
end
|
67
|
-
|
68
|
-
def fail_one(fail_one_param:, **)
|
69
|
-
ctx[:action_failed] = fail_one_param
|
70
|
-
end
|
71
|
-
|
72
|
-
def fail_two(**)
|
73
|
-
ctx[:fail_two] = 'Failure'
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
success_action = SomeActionOnSuccessFinishHim.call(
|
78
|
-
param_for_step_one: true
|
79
|
-
)
|
80
|
-
fail_step_success = SomeActionOnSuccessFinishHim.call(
|
81
|
-
param_for_step_one: false,
|
82
|
-
fail_one_param: true
|
83
|
-
)
|
84
|
-
fail_step_failure = SomeActionOnSuccessFinishHim.call(
|
85
|
-
param_for_step_one: false,
|
86
|
-
fail_one_param: false
|
87
|
-
)
|
88
|
-
|
89
|
-
puts success_action # =>
|
90
|
-
# Result: success
|
91
|
-
|
92
|
-
# Railway Flow:
|
93
|
-
# step_one
|
94
|
-
|
95
|
-
# Context:
|
96
|
-
# {:param_for_step_one=>true}
|
97
|
-
|
98
|
-
# Errors:
|
99
|
-
# {}
|
100
|
-
|
101
|
-
puts fail_step_success # =>
|
102
|
-
# Result: failure
|
103
|
-
|
104
|
-
# Railway Flow:
|
105
|
-
# step_one -> fail_one
|
106
|
-
|
107
|
-
# Context:
|
108
|
-
# {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true}
|
109
|
-
|
110
|
-
# Errors:
|
111
|
-
# {}
|
112
|
-
|
113
|
-
puts fail_step_failure # =>
|
114
|
-
# Result: failure
|
115
|
-
|
116
|
-
# Railway Flow:
|
117
|
-
# step_one -> fail_one -> fail_two
|
118
|
-
|
119
|
-
# Context:
|
120
|
-
# {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false, :fail_two=>"Failure"}
|
121
|
-
|
122
|
-
# Errors:
|
123
|
-
# {}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
# on_success: next success track step
|
128
|
-
class SomeActionOnSuccessToSuccessTrack < Decouplio::Action
|
129
|
-
logic do
|
130
|
-
step :step_one
|
131
|
-
fail :fail_one, on_success: :step_two
|
132
|
-
step :step_two
|
133
|
-
fail :fail_two
|
134
|
-
end
|
135
|
-
|
136
|
-
def step_one(param_for_step_one:, **)
|
137
|
-
param_for_step_one
|
138
|
-
end
|
139
|
-
|
140
|
-
def fail_one(fail_one_param:, **)
|
141
|
-
ctx[:action_failed] = fail_one_param
|
142
|
-
end
|
143
|
-
|
144
|
-
def step_two(**)
|
145
|
-
ctx[:step_two] = 'Success'
|
146
|
-
end
|
147
|
-
|
148
|
-
def fail_two(**)
|
149
|
-
ctx[:fail_two] = 'Failure'
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
success_action = SomeActionOnSuccessToSuccessTrack.call(
|
154
|
-
param_for_step_one: true
|
155
|
-
)
|
156
|
-
fail_step_success = SomeActionOnSuccessToSuccessTrack.call(
|
157
|
-
param_for_step_one: false,
|
158
|
-
fail_one_param: true
|
159
|
-
)
|
160
|
-
fail_step_failure = SomeActionOnSuccessToSuccessTrack.call(
|
161
|
-
param_for_step_one: false,
|
162
|
-
fail_one_param: false
|
163
|
-
)
|
164
|
-
|
165
|
-
puts success_action # =>
|
166
|
-
# Result: success
|
167
|
-
|
168
|
-
# Railway Flow:
|
169
|
-
# step_one -> step_two
|
170
|
-
|
171
|
-
# Context:
|
172
|
-
# {:param_for_step_one=>true, :step_two=>"Success"}
|
173
|
-
|
174
|
-
# Errors:
|
175
|
-
# {}
|
176
|
-
|
177
|
-
puts fail_step_success # =>
|
178
|
-
# Result: success
|
179
|
-
|
180
|
-
# Railway Flow:
|
181
|
-
# step_one -> fail_one -> step_two
|
182
|
-
|
183
|
-
# Context:
|
184
|
-
# {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true, :step_two=>"Success"}
|
185
|
-
|
186
|
-
# Errors:
|
187
|
-
# {}
|
188
|
-
|
189
|
-
puts fail_step_failure # =>
|
190
|
-
# Result: failure
|
191
|
-
|
192
|
-
# Railway Flow:
|
193
|
-
# step_one -> fail_one -> fail_two
|
194
|
-
|
195
|
-
# Context:
|
196
|
-
# {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false, :fail_two=>"Failure"}
|
197
|
-
|
198
|
-
# Errors:
|
199
|
-
# {}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
# on_success: next failure track step
|
204
|
-
class SomeActionOnSuccessToFailureTrack < Decouplio::Action
|
205
|
-
logic do
|
206
|
-
step :step_one
|
207
|
-
fail :fail_one, on_success: :fail_three
|
208
|
-
step :step_two
|
209
|
-
fail :fail_two
|
210
|
-
fail :fail_three
|
211
|
-
end
|
212
|
-
|
213
|
-
def step_one(param_for_step_one:, **)
|
214
|
-
param_for_step_one
|
215
|
-
end
|
216
|
-
|
217
|
-
def fail_one(fail_one_param:, **)
|
218
|
-
ctx[:action_failed] = fail_one_param
|
219
|
-
end
|
220
|
-
|
221
|
-
def step_two(**)
|
222
|
-
ctx[:step_two] = 'Success'
|
223
|
-
end
|
224
|
-
|
225
|
-
def fail_two(**)
|
226
|
-
ctx[:fail_two] = 'Failure'
|
227
|
-
end
|
228
|
-
|
229
|
-
def fail_three(**)
|
230
|
-
ctx[:fail_three] = 'Failure'
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
success_action = SomeActionOnSuccessToFailureTrack.call(
|
235
|
-
param_for_step_one: true
|
236
|
-
)
|
237
|
-
fail_step_success = SomeActionOnSuccessToFailureTrack.call(
|
238
|
-
param_for_step_one: false,
|
239
|
-
fail_one_param: true
|
240
|
-
)
|
241
|
-
fail_step_failure = SomeActionOnSuccessToFailureTrack.call(
|
242
|
-
param_for_step_one: false,
|
243
|
-
fail_one_param: false
|
244
|
-
)
|
245
|
-
|
246
|
-
puts success_action # =>
|
247
|
-
# Result: success
|
248
|
-
|
249
|
-
# Railway Flow:
|
250
|
-
# step_one -> step_two
|
251
|
-
|
252
|
-
# Context:
|
253
|
-
# {:param_for_step_one=>true, :step_two=>"Success"}
|
254
|
-
|
255
|
-
# Errors:
|
256
|
-
# {}
|
257
|
-
|
258
|
-
|
259
|
-
puts fail_step_success # =>
|
260
|
-
# Result: failure
|
261
|
-
|
262
|
-
# Railway Flow:
|
263
|
-
# step_one -> fail_one -> fail_three
|
264
|
-
|
265
|
-
# Context:
|
266
|
-
# {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true, :fail_three=>"Failure"}
|
267
|
-
|
268
|
-
# Errors:
|
269
|
-
# {}
|
270
|
-
|
271
|
-
|
272
|
-
puts fail_step_failure # =>
|
273
|
-
# Result: failure
|
274
|
-
|
275
|
-
# Railway Flow:
|
276
|
-
# step_one -> fail_one -> fail_two -> fail_three
|
277
|
-
|
278
|
-
# Context:
|
279
|
-
# {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false, :fail_two=>"Failure", :fail_three=>"Failure"}
|
280
|
-
|
281
|
-
# Errors:
|
282
|
-
# {}
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
# on_failure: :finish_him
|
287
|
-
class SomeActionOnFailureFinishHim < Decouplio::Action
|
288
|
-
logic do
|
289
|
-
step :step_one
|
290
|
-
fail :fail_one, on_failure: :finish_him
|
291
|
-
step :step_two
|
292
|
-
fail :fail_two
|
293
|
-
end
|
294
|
-
|
295
|
-
def step_one(param_for_step_one:, **)
|
296
|
-
param_for_step_one
|
297
|
-
end
|
298
|
-
|
299
|
-
def fail_one(fail_one_param:, **)
|
300
|
-
ctx[:action_failed] = fail_one_param
|
301
|
-
end
|
302
|
-
|
303
|
-
def step_two(**)
|
304
|
-
ctx[:step_two] = 'Success'
|
305
|
-
end
|
306
|
-
|
307
|
-
def fail_two(**)
|
308
|
-
ctx[:fail_two] = 'Failure'
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
success_action = SomeActionOnFailureFinishHim.call(
|
313
|
-
param_for_step_one: true
|
314
|
-
)
|
315
|
-
fail_step_success = SomeActionOnFailureFinishHim.call(
|
316
|
-
param_for_step_one: false,
|
317
|
-
fail_one_param: true
|
318
|
-
)
|
319
|
-
fail_step_failure = SomeActionOnFailureFinishHim.call(
|
320
|
-
param_for_step_one: false,
|
321
|
-
fail_one_param: false
|
322
|
-
)
|
323
|
-
|
324
|
-
puts success_action # =>
|
325
|
-
# Result: success
|
326
|
-
|
327
|
-
# Railway Flow:
|
328
|
-
# step_one -> step_two
|
329
|
-
|
330
|
-
# Context:
|
331
|
-
# {:param_for_step_one=>true, :step_two=>"Success"}
|
332
|
-
|
333
|
-
# Errors:
|
334
|
-
# {}
|
335
|
-
|
336
|
-
|
337
|
-
puts fail_step_success # =>
|
338
|
-
# Result: failure
|
339
|
-
|
340
|
-
# Railway Flow:
|
341
|
-
# step_one -> fail_one -> fail_two
|
342
|
-
|
343
|
-
# Context:
|
344
|
-
# {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true, :fail_two=>"Failure"}
|
345
|
-
|
346
|
-
# Errors:
|
347
|
-
# {}
|
348
|
-
|
349
|
-
|
350
|
-
puts fail_step_failure # =>
|
351
|
-
# Result: failure
|
352
|
-
|
353
|
-
# Railway Flow:
|
354
|
-
# step_one -> fail_one
|
355
|
-
|
356
|
-
# Context:
|
357
|
-
# {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false}
|
358
|
-
|
359
|
-
# Errors:
|
360
|
-
# {}
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
# on_failure: next success track step
|
365
|
-
class SomeActionOnFailureToSuccessTrack < Decouplio::Action
|
366
|
-
logic do
|
367
|
-
step :step_one
|
368
|
-
fail :fail_one, on_failure: :step_two
|
369
|
-
step :step_two
|
370
|
-
fail :fail_two
|
371
|
-
end
|
372
|
-
|
373
|
-
def step_one(param_for_step_one:, **)
|
374
|
-
param_for_step_one
|
375
|
-
end
|
376
|
-
|
377
|
-
def fail_one(fail_one_param:, **)
|
378
|
-
ctx[:action_failed] = fail_one_param
|
379
|
-
end
|
380
|
-
|
381
|
-
def step_two(**)
|
382
|
-
ctx[:step_two] = 'Success'
|
383
|
-
end
|
384
|
-
|
385
|
-
def fail_two(**)
|
386
|
-
ctx[:fail_two] = 'Failure'
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
success_action = SomeActionOnFailureToSuccessTrack.call(
|
391
|
-
param_for_step_one: true
|
392
|
-
)
|
393
|
-
fail_step_success = SomeActionOnFailureToSuccessTrack.call(
|
394
|
-
param_for_step_one: false,
|
395
|
-
fail_one_param: true
|
396
|
-
)
|
397
|
-
fail_step_failure = SomeActionOnFailureToSuccessTrack.call(
|
398
|
-
param_for_step_one: false,
|
399
|
-
fail_one_param: false
|
400
|
-
)
|
401
|
-
|
402
|
-
puts success_action # =>
|
403
|
-
# Result: success
|
404
|
-
|
405
|
-
# Railway Flow:
|
406
|
-
# step_one -> step_two
|
407
|
-
|
408
|
-
# Context:
|
409
|
-
# {:param_for_step_one=>true, :step_two=>"Success"}
|
410
|
-
|
411
|
-
# Errors:
|
412
|
-
# {}
|
413
|
-
|
414
|
-
puts fail_step_success # =>
|
415
|
-
# Result: failure
|
416
|
-
|
417
|
-
# Railway Flow:
|
418
|
-
# step_one -> fail_one -> fail_two
|
419
|
-
|
420
|
-
# Context:
|
421
|
-
# {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true, :fail_two=>"Failure"}
|
422
|
-
|
423
|
-
# Errors:
|
424
|
-
# {}
|
425
|
-
|
426
|
-
|
427
|
-
puts fail_step_failure # =>
|
428
|
-
# Result: success
|
429
|
-
|
430
|
-
# Railway Flow:
|
431
|
-
# step_one -> fail_one -> step_two
|
432
|
-
|
433
|
-
# Context:
|
434
|
-
# {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false, :step_two=>"Success"}
|
435
|
-
|
436
|
-
# Errors:
|
437
|
-
# {}
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
# on_failure: next failure track step
|
442
|
-
class SomeActionOnFailureToFailureTrack < Decouplio::Action
|
443
|
-
logic do
|
444
|
-
step :step_one
|
445
|
-
fail :fail_one, on_failure: :fail_three
|
446
|
-
step :step_two
|
447
|
-
fail :fail_two
|
448
|
-
fail :fail_three
|
449
|
-
end
|
450
|
-
|
451
|
-
def step_one(param_for_step_one:, **)
|
452
|
-
param_for_step_one
|
453
|
-
end
|
454
|
-
|
455
|
-
def fail_one(fail_one_param:, **)
|
456
|
-
ctx[:action_failed] = fail_one_param
|
457
|
-
end
|
458
|
-
|
459
|
-
def step_two(**)
|
460
|
-
ctx[:step_two] = 'Success'
|
461
|
-
end
|
462
|
-
|
463
|
-
def fail_two(**)
|
464
|
-
ctx[:fail_two] = 'Failure'
|
465
|
-
end
|
466
|
-
|
467
|
-
def fail_three(**)
|
468
|
-
ctx[:fail_three] = 'Failure'
|
469
|
-
end
|
470
|
-
end
|
471
|
-
|
472
|
-
success_action = SomeActionOnFailureToFailureTrack.call(
|
473
|
-
param_for_step_one: true
|
474
|
-
)
|
475
|
-
fail_step_success = SomeActionOnFailureToFailureTrack.call(
|
476
|
-
param_for_step_one: false,
|
477
|
-
fail_one_param: true
|
478
|
-
)
|
479
|
-
fail_step_failure = SomeActionOnFailureToFailureTrack.call(
|
480
|
-
param_for_step_one: false,
|
481
|
-
fail_one_param: false
|
482
|
-
)
|
483
|
-
|
484
|
-
puts success_action # =>
|
485
|
-
# Result: success
|
486
|
-
|
487
|
-
# Railway Flow:
|
488
|
-
# step_one -> step_two
|
489
|
-
|
490
|
-
# Context:
|
491
|
-
# {:param_for_step_one=>true, :step_two=>"Success"}
|
492
|
-
|
493
|
-
# Errors:
|
494
|
-
# {}
|
495
|
-
puts fail_step_success # =>
|
496
|
-
# Result: failure
|
497
|
-
|
498
|
-
# Railway Flow:
|
499
|
-
# step_one -> fail_one -> fail_two -> fail_three
|
500
|
-
|
501
|
-
# Context:
|
502
|
-
# {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true, :fail_two=>"Failure", :fail_three=>"Failure"}
|
503
|
-
|
504
|
-
# Errors:
|
505
|
-
# {}
|
506
|
-
puts fail_step_failure # =>
|
507
|
-
# Result: failure
|
508
|
-
|
509
|
-
# Railway Flow:
|
510
|
-
# step_one -> fail_one -> fail_three
|
511
|
-
|
512
|
-
# Context:
|
513
|
-
# {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false, :fail_three=>"Failure"}
|
514
|
-
|
515
|
-
# Errors:
|
516
|
-
# {}
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
# if: condition method name
|
521
|
-
class SomeActionOnIfCondition < Decouplio::Action
|
522
|
-
logic do
|
523
|
-
step :step_one
|
524
|
-
fail :fail_one
|
525
|
-
step :step_two
|
526
|
-
fail :fail_two, if: :some_condition?
|
527
|
-
fail :fail_three
|
528
|
-
end
|
529
|
-
|
530
|
-
def step_one(param_for_step_one:, **)
|
531
|
-
param_for_step_one
|
532
|
-
end
|
533
|
-
|
534
|
-
def fail_one(**)
|
535
|
-
ctx[:action_failed] = true
|
536
|
-
end
|
537
|
-
|
538
|
-
def step_two(**)
|
539
|
-
ctx[:step_two] = 'Success'
|
540
|
-
end
|
541
|
-
|
542
|
-
def fail_two(**)
|
543
|
-
ctx[:fail_two] = 'Failure'
|
544
|
-
end
|
545
|
-
|
546
|
-
def fail_three(**)
|
547
|
-
ctx[:fail_three] = 'Failure'
|
548
|
-
end
|
549
|
-
|
550
|
-
def some_condition?(if_condition_param:, **)
|
551
|
-
if_condition_param
|
552
|
-
end
|
553
|
-
end
|
554
|
-
|
555
|
-
success_action = SomeActionOnIfCondition.call(
|
556
|
-
param_for_step_one: true
|
557
|
-
)
|
558
|
-
fail_condition_positive = SomeActionOnIfCondition.call(
|
559
|
-
param_for_step_one: false,
|
560
|
-
if_condition_param: true
|
561
|
-
)
|
562
|
-
fail_condition_negative = SomeActionOnIfCondition.call(
|
563
|
-
param_for_step_one: false,
|
564
|
-
if_condition_param: false
|
565
|
-
)
|
566
|
-
|
567
|
-
puts success_action # =>
|
568
|
-
# Result: success
|
569
|
-
|
570
|
-
# Railway Flow:
|
571
|
-
# step_one -> step_two
|
572
|
-
|
573
|
-
# Context:
|
574
|
-
# {:param_for_step_one=>true, :step_two=>"Success"}
|
575
|
-
|
576
|
-
# Errors:
|
577
|
-
# {}
|
578
|
-
|
579
|
-
puts fail_condition_positive # =>
|
580
|
-
# Result: failure
|
581
|
-
|
582
|
-
# Railway Flow:
|
583
|
-
# step_one -> fail_one -> fail_two -> fail_three
|
584
|
-
|
585
|
-
# Context:
|
586
|
-
# {:param_for_step_one=>false, :if_condition_param=>true, :action_failed=>true, :fail_two=>"Failure", :fail_three=>"Failure"}
|
587
|
-
|
588
|
-
# Errors:
|
589
|
-
# {}
|
590
|
-
|
591
|
-
puts fail_condition_negative # =>
|
592
|
-
# Result: failure
|
593
|
-
|
594
|
-
# Railway Flow:
|
595
|
-
# step_one -> fail_one -> fail_three
|
596
|
-
|
597
|
-
# Context:
|
598
|
-
# {:param_for_step_one=>false, :if_condition_param=>false, :action_failed=>true, :fail_three=>"Failure"}
|
599
|
-
|
600
|
-
# Errors:
|
601
|
-
# {}
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
# unless: condition method name
|
606
|
-
class SomeActionOnUnlessCondition < Decouplio::Action
|
607
|
-
logic do
|
608
|
-
step :step_one
|
609
|
-
fail :fail_one
|
610
|
-
step :step_two
|
611
|
-
fail :fail_two, unless: :some_condition?
|
612
|
-
fail :fail_three
|
613
|
-
end
|
614
|
-
|
615
|
-
def step_one(param_for_step_one:, **)
|
616
|
-
param_for_step_one
|
617
|
-
end
|
618
|
-
|
619
|
-
def fail_one(**)
|
620
|
-
ctx[:action_failed] = true
|
621
|
-
end
|
622
|
-
|
623
|
-
def step_two(**)
|
624
|
-
ctx[:step_two] = 'Success'
|
625
|
-
end
|
626
|
-
|
627
|
-
def fail_two(**)
|
628
|
-
ctx[:fail_two] = 'Failure'
|
629
|
-
end
|
630
|
-
|
631
|
-
def fail_three(**)
|
632
|
-
ctx[:fail_three] = 'Failure'
|
633
|
-
end
|
634
|
-
|
635
|
-
def some_condition?(if_condition_param:, **)
|
636
|
-
if_condition_param
|
637
|
-
end
|
638
|
-
end
|
639
|
-
|
640
|
-
success_action = SomeActionOnUnlessCondition.call(
|
641
|
-
param_for_step_one: true
|
642
|
-
)
|
643
|
-
fail_condition_positive = SomeActionOnUnlessCondition.call(
|
644
|
-
param_for_step_one: false,
|
645
|
-
if_condition_param: false
|
646
|
-
)
|
647
|
-
fail_condition_negative = SomeActionOnUnlessCondition.call(
|
648
|
-
param_for_step_one: false,
|
649
|
-
if_condition_param: true
|
650
|
-
)
|
651
|
-
|
652
|
-
puts success_action # =>
|
653
|
-
# Result: success
|
654
|
-
|
655
|
-
# Railway Flow:
|
656
|
-
# step_one -> step_two
|
657
|
-
|
658
|
-
# Context:
|
659
|
-
# {:param_for_step_one=>true, :step_two=>"Success"}
|
660
|
-
|
661
|
-
# Errors:
|
662
|
-
# {}
|
663
|
-
|
664
|
-
puts fail_condition_positive # =>
|
665
|
-
# Result: failure
|
666
|
-
|
667
|
-
# Railway Flow:
|
668
|
-
# step_one -> fail_one -> fail_two -> fail_three
|
669
|
-
|
670
|
-
# Context:
|
671
|
-
# {:param_for_step_one=>false, :if_condition_param=>false, :action_failed=>true, :fail_two=>"Failure", :fail_three=>"Failure"}
|
672
|
-
|
673
|
-
# Errors:
|
674
|
-
# {}
|
675
|
-
|
676
|
-
puts fail_condition_negative # =>
|
677
|
-
# Result: failure
|
678
|
-
|
679
|
-
# Railway Flow:
|
680
|
-
# step_one -> fail_one -> fail_three
|
681
|
-
|
682
|
-
# Context:
|
683
|
-
# {:param_for_step_one=>false, :if_condition_param=>true, :action_failed=>true, :fail_three=>"Failure"}
|
684
|
-
|
685
|
-
# Errors:
|
686
|
-
# {}
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
# finish_him: true
|
691
|
-
class SomeActionFinishHimTrue < Decouplio::Action
|
692
|
-
logic do
|
693
|
-
step :step_one
|
694
|
-
fail :fail_one, finish_him: true
|
695
|
-
step :step_two
|
696
|
-
fail :fail_two
|
697
|
-
end
|
698
|
-
|
699
|
-
def step_one(param_for_step_one:, **)
|
700
|
-
param_for_step_one
|
701
|
-
end
|
702
|
-
|
703
|
-
def fail_one(fail_one_param:, **)
|
704
|
-
ctx[:action_failed] = fail_one_param
|
705
|
-
end
|
706
|
-
|
707
|
-
def step_two(**)
|
708
|
-
ctx[:step_two] = 'Success'
|
709
|
-
end
|
710
|
-
|
711
|
-
def fail_two(**)
|
712
|
-
ctx[:fail_two] = 'Failure'
|
713
|
-
end
|
714
|
-
end
|
715
|
-
|
716
|
-
success_action = SomeActionFinishHimTrue.call(
|
717
|
-
param_for_step_one: true
|
718
|
-
)
|
719
|
-
fail_step_success = SomeActionFinishHimTrue.call(
|
720
|
-
param_for_step_one: false,
|
721
|
-
fail_one_param: true
|
722
|
-
)
|
723
|
-
fail_step_failure = SomeActionFinishHimTrue.call(
|
724
|
-
param_for_step_one: false,
|
725
|
-
fail_one_param: false
|
726
|
-
)
|
727
|
-
|
728
|
-
puts success_action # =>
|
729
|
-
# Result: success
|
730
|
-
|
731
|
-
# Railway Flow:
|
732
|
-
# step_one -> step_two
|
733
|
-
|
734
|
-
# Context:
|
735
|
-
# {:param_for_step_one=>true, :step_two=>"Success"}
|
736
|
-
|
737
|
-
# Errors:
|
738
|
-
# {}
|
739
|
-
|
740
|
-
puts fail_step_success # =>
|
741
|
-
# Result: failure
|
742
|
-
|
743
|
-
# Railway Flow:
|
744
|
-
# step_one -> fail_one
|
745
|
-
|
746
|
-
# Context:
|
747
|
-
# {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true}
|
748
|
-
|
749
|
-
# Errors:
|
750
|
-
# {}
|
751
|
-
|
752
|
-
puts fail_step_failure # =>
|
753
|
-
# Result: failure
|
754
|
-
|
755
|
-
# Railway Flow:
|
756
|
-
# step_one -> fail_one
|
757
|
-
|
758
|
-
# Context:
|
759
|
-
# {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false}
|
760
|
-
|
761
|
-
# Errors:
|
762
|
-
# {}
|