decouplio 1.0.0alpha2 → 1.0.0alpha5

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +11 -1
  3. data/.rubocop.yml +6 -0
  4. data/.ruby-version +1 -1
  5. data/README.md +2 -17
  6. data/benchmarks/multi_step_benchmark.rb +11 -10
  7. data/benchmarks/single_step_benchmark.rb +1 -1
  8. data/decouplio.gemspec +4 -4
  9. data/lib/decouplio/action.rb +12 -0
  10. data/lib/decouplio/composer.rb +47 -24
  11. data/lib/decouplio/const/doby_aide_options.rb +16 -0
  12. data/lib/decouplio/const/error_messages.rb +9 -0
  13. data/lib/decouplio/const/types.rb +14 -6
  14. data/lib/decouplio/const/validations/aide.rb +38 -0
  15. data/lib/decouplio/const/validations/doby.rb +36 -0
  16. data/lib/decouplio/const/validations/fail.rb +4 -0
  17. data/lib/decouplio/const/validations/octo.rb +2 -1
  18. data/lib/decouplio/errors/{deny_can_not_be_first_step_error.rb → aide_can_not_be_first_step_error.rb} +3 -3
  19. data/lib/decouplio/errors/aide_controversial_keys_error.rb +26 -0
  20. data/lib/decouplio/errors/aide_finish_him_error.rb +26 -0
  21. data/lib/decouplio/errors/doby_controversial_keys_error.rb +26 -0
  22. data/lib/decouplio/errors/doby_finish_him_error.rb +26 -0
  23. data/lib/decouplio/errors/execution_error.rb +20 -0
  24. data/lib/decouplio/errors/step_is_not_defined_for_aide_error.rb +26 -0
  25. data/lib/decouplio/errors/step_is_not_defined_for_doby_error.rb +27 -0
  26. data/lib/decouplio/errors/step_is_not_defined_for_pass_error.rb +27 -0
  27. data/lib/decouplio/logic_dsl.rb +23 -8
  28. data/lib/decouplio/options_validator.rb +157 -13
  29. data/lib/decouplio/steps/aide.rb +37 -0
  30. data/lib/decouplio/steps/base_resq.rb +13 -3
  31. data/lib/decouplio/steps/doby.rb +9 -8
  32. data/lib/decouplio/steps/octo.rb +7 -2
  33. data/lib/decouplio/validators/condition.rb +10 -0
  34. data/lib/decouplio/version.rb +1 -1
  35. metadata +24 -42
  36. data/docs/_config.yml +0 -1
  37. data/docs/benchmarks.md +0 -1
  38. data/docs/context.md +0 -74
  39. data/docs/context.rb +0 -62
  40. data/docs/deny.rb +0 -59
  41. data/docs/doby.rb +0 -38
  42. data/docs/doby_deny.md +0 -171
  43. data/docs/error_store.md +0 -347
  44. data/docs/error_store.rb +0 -202
  45. data/docs/fail.md +0 -1159
  46. data/docs/fail.rb +0 -859
  47. data/docs/index.md +0 -25
  48. data/docs/inner_action.md +0 -63
  49. data/docs/inner_action.rb +0 -43
  50. data/docs/logic_block.md +0 -25
  51. data/docs/octo.md +0 -269
  52. data/docs/octo.rb +0 -164
  53. data/docs/pass.md +0 -309
  54. data/docs/pass.rb +0 -213
  55. data/docs/quick_start.md +0 -71
  56. data/docs/quick_start.rb +0 -38
  57. data/docs/resq.md +0 -263
  58. data/docs/resq.rb +0 -176
  59. data/docs/step.md +0 -885
  60. data/docs/step.rb +0 -627
  61. data/docs/step_as_a_service.md +0 -123
  62. data/docs/step_as_a_service.rb +0 -77
  63. data/docs/wrap.md +0 -240
  64. data/docs/wrap.rb +0 -137
  65. data/lib/decouplio/const/validations/deny.rb +0 -11
  66. data/lib/decouplio/steps/deny.rb +0 -31
data/docs/fail.md DELETED
@@ -1,1159 +0,0 @@
1
- # Fail
2
-
3
- `fail` is the special type of step to mark failure track
4
-
5
- ## Signature
6
-
7
- ```ruby
8
- fail(step_name, **options)
9
- ```
10
-
11
- ## Behavior
12
-
13
- - when step method(`#fail_one`) returns truthy or falsy value then it goes to failure track(`step_two` step) if `on_success:` or `on_failure:` option wasn't passed(see `on_success, on_failure` docs)
14
-
15
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
16
- <p>
17
-
18
- ```ruby
19
- require 'decouplio'
20
-
21
- class SomeAction < Decouplio::Action
22
- logic do
23
- step :step_one
24
- fail :fail_one
25
- fail :fail_two
26
- end
27
-
28
- def step_one(param_for_step_one:, **)
29
- param_for_step_one
30
- end
31
-
32
- def fail_one(**)
33
- ctx[:action_failed] = true
34
- end
35
-
36
- def fail_two(**)
37
- ctx[:fail_two] = 'Failure'
38
- end
39
- end
40
-
41
- success_action = SomeAction.call(param_for_step_one: true)
42
- failure_action = SomeAction.call(param_for_step_one: false)
43
-
44
- success_action # =>
45
- # Result: success
46
-
47
- # Railway Flow:
48
- # step_one
49
-
50
- # Context:
51
- # {:param_for_step_one=>true}
52
-
53
- # Errors:
54
- # {}
55
-
56
-
57
- failure_action # =>
58
- # Result: failure
59
-
60
- # Railway Flow:
61
- # step_one -> fail_one -> fail_two
62
-
63
- # Context:
64
- # {:param_for_step_one=>false, :action_failed=>true, :fail_two=>"Failure"}
65
-
66
- # Errors:
67
- # {}
68
- ```
69
-
70
- ```mermaid
71
- flowchart LR
72
- 1(start)-->2(step_one);
73
- 2(step_one)-->|success track|3(finish_success);
74
- 2(step_one)-->|failure track|4(fail_one);
75
- 4(fail_one)-->|failure track|5(fail_two);
76
- 5(fail_two)-->|failure track|F(finish_failure);
77
- ```
78
-
79
- </p>
80
- </details>
81
-
82
- ***
83
-
84
- ## Options
85
-
86
- ### on_success:
87
- |Allowed values|Description|
88
- |-|-|
89
- |:finish_him|action stops execution if `fail` method returns truthy value|
90
- |symbol with next step name|step with specified symbol name performs if step method returns truthy value|
91
- |:PASS|will direct execution flow to nearest success track step. If current step is the last step when action will finish as `success`|
92
- |:FAIL|will direct execution flow to nearest failure track step. If current step is the last step when action will finish as `failure`|
93
-
94
- ### on_success: :finish_him
95
-
96
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
97
- <p>
98
-
99
- ```ruby
100
- require 'decouplio'
101
-
102
- class SomeActionOnSuccessFinishHim < Decouplio::Action
103
- logic do
104
- step :step_one
105
- fail :fail_one, on_success: :finish_him
106
- fail :fail_two
107
- end
108
-
109
- def step_one(param_for_step_one:, **)
110
- param_for_step_one
111
- end
112
-
113
- def fail_one(fail_one_param:, **)
114
- ctx[:action_failed] = fail_one_param
115
- end
116
-
117
- def fail_two(**)
118
- ctx[:fail_two] = 'Failure'
119
- end
120
- end
121
-
122
- success_action = SomeActionOnSuccessFinishHim.call(
123
- param_for_step_one: true
124
- )
125
- fail_step_success = SomeActionOnSuccessFinishHim.call(
126
- param_for_step_one: false,
127
- fail_one_param: true
128
- )
129
- fail_step_failure = SomeActionOnSuccessFinishHim.call(
130
- param_for_step_one: false,
131
- fail_one_param: false
132
- )
133
-
134
- success_action # =>
135
- # Result: success
136
-
137
- # Railway Flow:
138
- # step_one
139
-
140
- # Context:
141
- # {:param_for_step_one=>true}
142
-
143
- # Errors:
144
- # {}
145
-
146
- fail_step_success # =>
147
- # Result: failure
148
-
149
- # Railway Flow:
150
- # step_one -> fail_one
151
-
152
- # Context:
153
- # {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true}
154
-
155
- # Errors:
156
- # {}
157
-
158
- fail_step_failure # =>
159
- # Result: failure
160
-
161
- # Railway Flow:
162
- # step_one -> fail_one -> fail_two
163
-
164
- # Context:
165
- # {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false, :fail_two=>"Failure"}
166
-
167
- # Errors:
168
- # {}
169
- ```
170
-
171
- ```mermaid
172
- flowchart LR
173
- 1(start)-->2(step_one);
174
- 2(step_one)-->|success track|3(finish_success);
175
- 2(step_one)-->|failure track|4(fail_one success);
176
- 2(step_one)-->|failure track|7(fail_one failure);
177
- 4(fail_one success)-->|failure track|5(finish_failure);
178
- 7(fail_one failure)-->|failure track|6(fail_two);
179
- 6(fail_two)-->|failure track|5(finish_failure);
180
- ```
181
- </p>
182
- </details>
183
-
184
- ***
185
-
186
- ### on_success: next success track step
187
-
188
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
189
- <p>
190
-
191
- ```ruby
192
- require 'decouplio'
193
-
194
- class SomeActionOnSuccessToSuccessTrack < Decouplio::Action
195
- logic do
196
- step :step_one
197
- fail :fail_one, on_success: :step_two
198
- step :step_two
199
- fail :fail_two
200
- end
201
-
202
- def step_one(param_for_step_one:, **)
203
- param_for_step_one
204
- end
205
-
206
- def fail_one(fail_one_param:, **)
207
- ctx[:action_failed] = fail_one_param
208
- end
209
-
210
- def step_two(**)
211
- ctx[:step_two] = 'Success'
212
- end
213
-
214
- def fail_two(**)
215
- ctx[:fail_two] = 'Failure'
216
- end
217
- end
218
-
219
- success_action = SomeActionOnSuccessToSuccessTrack.call(
220
- param_for_step_one: true
221
- )
222
- fail_step_success = SomeActionOnSuccessToSuccessTrack.call(
223
- param_for_step_one: false,
224
- fail_one_param: true
225
- )
226
- fail_step_failure = SomeActionOnSuccessToSuccessTrack.call(
227
- param_for_step_one: false,
228
- fail_one_param: false
229
- )
230
-
231
- success_action # =>
232
- # Result: success
233
-
234
- # Railway Flow:
235
- # step_one -> step_two
236
-
237
- # Context:
238
- # {:param_for_step_one=>true, :step_two=>"Success"}
239
-
240
- # Errors:
241
- # {}
242
-
243
- fail_step_success # =>
244
- # Result: success
245
-
246
- # Railway Flow:
247
- # step_one -> fail_one -> step_two
248
-
249
- # Context:
250
- # {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true, :step_two=>"Success"}
251
-
252
- # Errors:
253
- # {}
254
-
255
- fail_step_failure # =>
256
- # Result: failure
257
-
258
- # Railway Flow:
259
- # step_one -> fail_one -> fail_two
260
-
261
- # Context:
262
- # {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false, :fail_two=>"Failure"}
263
-
264
- # Errors:
265
- # {}
266
- ```
267
-
268
- ```mermaid
269
- flowchart LR
270
- 1(start)-->2(step_one);
271
- 2(step_one)-->|success track|3(step_two);
272
- 3(step_two)-->|success track|4(finish_success);
273
- 2(step_one)-->|failure track|5(fail_one success);
274
- 2(step_one)-->|failure track|6(fail_one failure);
275
- 5(fail_one success)-->|success track|3(step_two);
276
- 6(fail_one failure)-->|failure track|7(fail_two);
277
- 7(fail_two)-->|failure track|8(finish_failure);
278
- ```
279
-
280
- </p>
281
- </details>
282
-
283
- ***
284
-
285
- ### on_success: next failure track step
286
-
287
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
288
- <p>
289
-
290
- ```ruby
291
- require 'decouplio'
292
-
293
- class SomeActionOnSuccessToFailureTrack < Decouplio::Action
294
- logic do
295
- step :step_one
296
- fail :fail_one, on_success: :fail_three
297
- step :step_two
298
- fail :fail_two
299
- fail :fail_three
300
- end
301
-
302
- def step_one(param_for_step_one:, **)
303
- param_for_step_one
304
- end
305
-
306
- def fail_one(fail_one_param:, **)
307
- ctx[:action_failed] = fail_one_param
308
- end
309
-
310
- def step_two(**)
311
- ctx[:step_two] = 'Success'
312
- end
313
-
314
- def fail_two(**)
315
- ctx[:fail_two] = 'Failure'
316
- end
317
-
318
- def fail_three(**)
319
- ctx[:fail_three] = 'Failure'
320
- end
321
- end
322
-
323
- success_action = SomeActionOnSuccessToFailureTrack.call(
324
- param_for_step_one: true
325
- )
326
- fail_step_success = SomeActionOnSuccessToFailureTrack.call(
327
- param_for_step_one: false,
328
- fail_one_param: true
329
- )
330
- fail_step_failure = SomeActionOnSuccessToFailureTrack.call(
331
- param_for_step_one: false,
332
- fail_one_param: false
333
- )
334
-
335
- success_action # =>
336
- # Result: success
337
-
338
- # Railway Flow:
339
- # step_one -> step_two
340
-
341
- # Context:
342
- # {:param_for_step_one=>true, :step_two=>"Success"}
343
-
344
- # Errors:
345
- # {}
346
-
347
-
348
- fail_step_success # =>
349
- # Result: failure
350
-
351
- # Railway Flow:
352
- # step_one -> fail_one -> fail_three
353
-
354
- # Context:
355
- # {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true, :fail_three=>"Failure"}
356
-
357
- # Errors:
358
- # {}
359
-
360
-
361
- fail_step_failure # =>
362
- # Result: failure
363
-
364
- # Railway Flow:
365
- # step_one -> fail_one -> fail_two -> fail_three
366
-
367
- # Context:
368
- # {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false, :fail_two=>"Failure", :fail_three=>"Failure"}
369
-
370
- # Errors:
371
- # {}
372
- ```
373
-
374
- ```mermaid
375
- flowchart LR
376
- 1(start)-->2(step_one);
377
- 2(step_one)-->|success track|3(step_two);
378
- 3(step_two)-->|success track|4(finish success);
379
- 2(step_one)-->|failure track|5(fail_one success);
380
- 5(fail_one success)-->|failure track|6(fail_three);
381
- 6(fail_three)-->|failure track|7(finish failure);
382
- 2(step_one)-->|failure track|8(fail_one failure);
383
- 8(fail_one failure)-->|failure track|9(fail_two);
384
- 9(fail_two)-->|failure track|6(fail_three);
385
- ```
386
-
387
- </p>
388
- </details>
389
-
390
- ***
391
-
392
- ### on_success: :PASS
393
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
394
- <p>
395
-
396
- ```ruby
397
- require 'decouplio'
398
- class SomeActionOnSuccessPass < Decouplio::Action
399
- logic do
400
- step :step_one
401
- fail :fail_one, on_success: :PASS
402
- end
403
-
404
- def step_one(**)
405
- ctx[:step_one] = false
406
- end
407
-
408
- def fail_one(fail_one_param:, **)
409
- ctx[:fail_one] = fail_one_param
410
- end
411
- end
412
-
413
- fail_step_success = SomeActionOnSuccessPass.call(fail_one_param: true)
414
- fail_step_failure = SomeActionOnSuccessPass.call(fail_one_param: false)
415
-
416
- fail_step_success # =>
417
- # Result: success
418
-
419
- # Railway Flow:
420
- # step_one -> fail_one
421
-
422
- # Context:
423
- # :fail_one_param => true
424
- # :step_one => false
425
- # :fail_one => true
426
-
427
- # Errors:
428
- # {}
429
-
430
- fail_step_failure # =>
431
- # Result: failure
432
-
433
- # Railway Flow:
434
- # step_one -> fail_one
435
-
436
- # Context:
437
- # :fail_one_param => false
438
- # :step_one => false
439
- # :fail_one => false
440
-
441
- # Errors:
442
- # {}
443
- ```
444
-
445
- ```mermaid
446
- flowchart LR
447
- 1(start)-->2(step_one);
448
- 2(step_one)-->|failure track|3(fail_one);
449
- 3(fail_one)-->|on_success: :PASS|5(finish_success);
450
- 3(fail_one)-->|failure track|4(finish_failure);
451
- ```
452
- </p>
453
- </details>
454
-
455
- ***
456
-
457
- ### on_success: :FAIL
458
- It will perform like regular `fail` step, just move to next failure track step.
459
-
460
- ***
461
-
462
- ### on_failure:
463
- |Allowed values|Description|
464
- |-|-|
465
- |:finish_him|action stops execution if `fail` method returns falsy value|
466
- |symbol with next step name|step with specified symbol name performs if step method returns falsy value|
467
- |:PASS|will direct execution flow to nearest success track step. If current step is the last step when action will finish as `success`|
468
- |:FAIL|will direct execution flow to nearest failure track step. If current step is the last step when action will finish as `failure`|
469
-
470
- ### on_failure: :finish_him
471
-
472
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
473
- <p>
474
-
475
- ```ruby
476
- require 'decouplio'
477
-
478
- class SomeActionOnFailureFinishHim < Decouplio::Action
479
- logic do
480
- step :step_one
481
- fail :fail_one, on_failure: :finish_him
482
- step :step_two
483
- fail :fail_two
484
- end
485
-
486
- def step_one(param_for_step_one:, **)
487
- param_for_step_one
488
- end
489
-
490
- def fail_one(fail_one_param:, **)
491
- ctx[:action_failed] = fail_one_param
492
- end
493
-
494
- def step_two(**)
495
- ctx[:step_two] = 'Success'
496
- end
497
-
498
- def fail_two(**)
499
- ctx[:fail_two] = 'Failure'
500
- end
501
- end
502
-
503
- success_action = SomeActionOnFailureFinishHim.call(
504
- param_for_step_one: true
505
- )
506
- fail_step_success = SomeActionOnFailureFinishHim.call(
507
- param_for_step_one: false,
508
- fail_one_param: true
509
- )
510
- fail_step_failure = SomeActionOnFailureFinishHim.call(
511
- param_for_step_one: false,
512
- fail_one_param: false
513
- )
514
-
515
- success_action # =>
516
- # Result: success
517
-
518
- # Railway Flow:
519
- # step_one -> step_two
520
-
521
- # Context:
522
- # {:param_for_step_one=>true, :step_two=>"Success"}
523
-
524
- # Errors:
525
- # {}
526
-
527
-
528
- fail_step_success # =>
529
- # Result: failure
530
-
531
- # Railway Flow:
532
- # step_one -> fail_one -> fail_two
533
-
534
- # Context:
535
- # {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true, :fail_two=>"Failure"}
536
-
537
- # Errors:
538
- # {}
539
-
540
-
541
- fail_step_failure # =>
542
- # Result: failure
543
-
544
- # Railway Flow:
545
- # step_one -> fail_one
546
-
547
- # Context:
548
- # {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false}
549
-
550
- # Errors:
551
- # {}
552
- ```
553
-
554
- ```mermaid
555
- flowchart LR
556
- 1(start)-->2(step_one);
557
- 2(step_one)-->|success track|3(step_two);
558
- 3(step_two)-->|success track|4(finish_success);
559
- 2(step_one)-->|failure track|5(fail_one success);
560
- 5(fail_one success)-->|failure track|6(fail_two);
561
- 6(fail_two)-->|failure track|7(finish failure);
562
- 2(step_one)-->|failure track|8(fail_one failure);
563
- 8(fail_one failure)-->|failure track|7(finish failure);
564
- ```
565
- </p>
566
- </details>
567
-
568
- ***
569
-
570
- ### on_failure: next success track step
571
-
572
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
573
- <p>
574
-
575
- ```ruby
576
- require 'decouplio'
577
-
578
- class SomeActionOnFailureToSuccessTrack < Decouplio::Action
579
- logic do
580
- step :step_one
581
- fail :fail_one, on_failure: :step_two
582
- step :step_two
583
- fail :fail_two
584
- end
585
-
586
- def step_one(param_for_step_one:, **)
587
- param_for_step_one
588
- end
589
-
590
- def fail_one(fail_one_param:, **)
591
- ctx[:action_failed] = fail_one_param
592
- end
593
-
594
- def step_two(**)
595
- ctx[:step_two] = 'Success'
596
- end
597
-
598
- def fail_two(**)
599
- ctx[:fail_two] = 'Failure'
600
- end
601
- end
602
-
603
- success_action = SomeActionOnFailureToSuccessTrack.call(
604
- param_for_step_one: true
605
- )
606
- fail_step_success = SomeActionOnFailureToSuccessTrack.call(
607
- param_for_step_one: false,
608
- fail_one_param: true
609
- )
610
- fail_step_failure = SomeActionOnFailureToSuccessTrack.call(
611
- param_for_step_one: false,
612
- fail_one_param: false
613
- )
614
-
615
- success_action # =>
616
- # Result: success
617
-
618
- # Railway Flow:
619
- # step_one -> step_two
620
-
621
- # Context:
622
- # {:param_for_step_one=>true, :step_two=>"Success"}
623
-
624
- # Errors:
625
- # {}
626
-
627
- fail_step_success # =>
628
- # Result: failure
629
-
630
- # Railway Flow:
631
- # step_one -> fail_one -> fail_two
632
-
633
- # Context:
634
- # {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true, :fail_two=>"Failure"}
635
-
636
- # Errors:
637
- # {}
638
-
639
-
640
- fail_step_failure # =>
641
- # Result: success
642
-
643
- # Railway Flow:
644
- # step_one -> fail_one -> step_two
645
-
646
- # Context:
647
- # {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false, :step_two=>"Success"}
648
-
649
- # Errors:
650
- # {}
651
- ```
652
-
653
- ```mermaid
654
- flowchart LR
655
- 1(start)-->2(step_one);
656
- 2(step_one)-->|success track|3(finish success);
657
- 2(step_one)-->|failure track|4(fail_one success);
658
- 4(fail_one success)-->|failure track|5(fail_two);
659
- 3(step_two)-->|success track|4(step_three);
660
- 4(step_three)-->|success track|5(finish_success);
661
- 2(step_one)-->|failure track|4(step_three);
662
- ```
663
- </p>
664
- </details>
665
-
666
- ***
667
-
668
- ### on_failure: next failure track step
669
-
670
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
671
- <p>
672
-
673
- ```ruby
674
- require 'decouplio'
675
-
676
- class SomeActionOnFailureToFailureTrack < Decouplio::Action
677
- logic do
678
- step :step_one
679
- fail :fail_one, on_failure: :fail_three
680
- step :step_two
681
- fail :fail_two
682
- fail :fail_three
683
- end
684
-
685
- def step_one(param_for_step_one:, **)
686
- param_for_step_one
687
- end
688
-
689
- def fail_one(fail_one_param:, **)
690
- ctx[:action_failed] = fail_one_param
691
- end
692
-
693
- def step_two(**)
694
- ctx[:step_two] = 'Success'
695
- end
696
-
697
- def fail_two(**)
698
- ctx[:fail_two] = 'Failure'
699
- end
700
-
701
- def fail_three(**)
702
- ctx[:fail_three] = 'Failure'
703
- end
704
- end
705
-
706
- success_action = SomeActionOnFailureToFailureTrack.call(
707
- param_for_step_one: true
708
- )
709
- fail_step_success = SomeActionOnFailureToFailureTrack.call(
710
- param_for_step_one: false,
711
- fail_one_param: true
712
- )
713
- fail_step_failure = SomeActionOnFailureToFailureTrack.call(
714
- param_for_step_one: false,
715
- fail_one_param: false
716
- )
717
-
718
- success_action # =>
719
- # Result: success
720
-
721
- # Railway Flow:
722
- # step_one -> step_two
723
-
724
- # Context:
725
- # {:param_for_step_one=>true, :step_two=>"Success"}
726
-
727
- # Errors:
728
- # {}
729
- fail_step_success # =>
730
- # Result: failure
731
-
732
- # Railway Flow:
733
- # step_one -> fail_one -> fail_two -> fail_three
734
-
735
- # Context:
736
- # {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true, :fail_two=>"Failure", :fail_three=>"Failure"}
737
-
738
- # Errors:
739
- # {}
740
- fail_step_failure # =>
741
- # Result: failure
742
-
743
- # Railway Flow:
744
- # step_one -> fail_one -> fail_three
745
-
746
- # Context:
747
- # {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false, :fail_three=>"Failure"}
748
-
749
- # Errors:
750
- # {}
751
- ```
752
-
753
- ```mermaid
754
- flowchart LR
755
- 1(start)-->2(step_one);
756
- 2(step_one)-->|success track|3(step_two);
757
- 3(step_two)-->|success track|4(finish_success);
758
- 2(step_one)-->|failure track|5(fail_one success);
759
- 5(fail_one success)-->|failure track|6(fail_two);
760
- 6(fail_two)-->|failure track|7(fail_three);
761
- 7(fail_three)-->|failure track|8(finish failure);
762
- 2(step_one)-->|failure track|9(fail_one failure);
763
- 9(fail_one failure)-->|failure track|7(fail_three);
764
- ```
765
- </p>
766
- </details>
767
-
768
- ***
769
-
770
- ### on_failure: :PASS
771
-
772
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
773
- <p>
774
-
775
- ```ruby
776
- require 'decouplio'
777
- class SomeActionOnFailurePass < Decouplio::Action
778
- logic do
779
- step :step_one
780
- fail :fail_one, on_failure: :PASS
781
- end
782
-
783
- def step_one(**)
784
- false
785
- end
786
-
787
- def fail_one(fail_one_param:, **)
788
- ctx[:fail_one] = fail_one_param
789
- end
790
- end
791
-
792
- fail_step_success = SomeActionOnFailurePass.call(fail_one_param: true)
793
- fail_step_failure = SomeActionOnFailurePass.call(fail_one_param: false)
794
-
795
- fail_step_success # =>
796
- # Result: failure
797
-
798
- # Railway Flow:
799
- # step_one -> fail_one
800
-
801
- # Context:
802
- # :fail_one_param => true
803
- # :fail_one => true
804
-
805
- # Errors:
806
- # {}
807
-
808
- fail_step_failure # =>
809
- # Result: success
810
-
811
- # Railway Flow:
812
- # step_one -> fail_one
813
-
814
- # Context:
815
- # :fail_one_param => false
816
- # :fail_one => false
817
-
818
- # Errors:
819
- # {}
820
- ```
821
-
822
- ```mermaid
823
- flowchart LR
824
- 1(start)-->2(step_one);
825
- 2(step_one)-->|failure track|3(fail_one);
826
- 3(fail_one)-->|failure track|4(finish_failure);
827
- 3(fail_one)-->|on_failure: :PASS|5(finish_success);
828
- ```
829
- </p>
830
- </details>
831
-
832
- ***
833
-
834
- ### on_failure: :FAIL
835
- It will perform like regular `fail` step, just move to next failure track step.
836
-
837
- ***
838
-
839
- ### if: condition method name
840
- Can be used in case if for some reason step shouldn't be executed
841
-
842
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
843
- <p>
844
-
845
- ```ruby
846
- require 'decouplio'
847
-
848
- class SomeActionOnIfCondition < Decouplio::Action
849
- logic do
850
- step :step_one
851
- fail :fail_one
852
- step :step_two
853
- fail :fail_two, if: :some_condition?
854
- fail :fail_three
855
- end
856
-
857
- def step_one(param_for_step_one:, **)
858
- param_for_step_one
859
- end
860
-
861
- def fail_one(**)
862
- ctx[:action_failed] = true
863
- end
864
-
865
- def step_two(**)
866
- ctx[:step_two] = 'Success'
867
- end
868
-
869
- def fail_two(**)
870
- ctx[:fail_two] = 'Failure'
871
- end
872
-
873
- def fail_three(**)
874
- ctx[:fail_three] = 'Failure'
875
- end
876
-
877
- def some_condition?(if_condition_param:, **)
878
- if_condition_param
879
- end
880
- end
881
-
882
- success_action = SomeActionOnIfCondition.call(
883
- param_for_step_one: true
884
- )
885
- fail_condition_positive = SomeActionOnIfCondition.call(
886
- param_for_step_one: false,
887
- if_condition_param: true
888
- )
889
- fail_condition_negative = SomeActionOnIfCondition.call(
890
- param_for_step_one: false,
891
- if_condition_param: false
892
- )
893
-
894
- success_action # =>
895
- # Result: success
896
-
897
- # Railway Flow:
898
- # step_one -> step_two
899
-
900
- # Context:
901
- # {:param_for_step_one=>true, :step_two=>"Success"}
902
-
903
- # Errors:
904
- # {}
905
-
906
- fail_condition_positive # =>
907
- # Result: failure
908
-
909
- # Railway Flow:
910
- # step_one -> fail_one -> fail_two -> fail_three
911
-
912
- # Context:
913
- # {:param_for_step_one=>false, :if_condition_param=>true, :action_failed=>true, :fail_two=>"Failure", :fail_three=>"Failure"}
914
-
915
- # Errors:
916
- # {}
917
-
918
- fail_condition_negative # =>
919
- # Result: failure
920
-
921
- # Railway Flow:
922
- # step_one -> fail_one -> fail_three
923
-
924
- # Context:
925
- # {:param_for_step_one=>false, :if_condition_param=>false, :action_failed=>true, :fail_three=>"Failure"}
926
-
927
- # Errors:
928
- # {}
929
- ```
930
-
931
- ```mermaid
932
- flowchart LR
933
- 1(start)-->2(step_one);
934
- 2(step_one)-->|success tack|3(step_two);
935
- 3(step_two)-->|success track|4(finish_success);
936
- 2(step_one)-->|failure track|5(fail_one);
937
- 5(fail_one)-->|condition positive|6(fail_two);
938
- 6(fail_two)-->|failure track|7(fail_three);
939
- 5(fail_one)-->|condition negative|7(fail_three);
940
- 7(fail_three)-->|failure track|8(finish failure);
941
- ```
942
- </p>
943
- </details>
944
-
945
- ***
946
-
947
- ### unless: condition method name
948
- Can be used in case if for some reason step shouldn't be executed
949
-
950
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
951
- <p>
952
-
953
- ```ruby
954
- require 'decouplio'
955
-
956
- class SomeActionOnUnlessCondition < Decouplio::Action
957
- logic do
958
- step :step_one
959
- fail :fail_one
960
- step :step_two
961
- fail :fail_two, unless: :some_condition?
962
- fail :fail_three
963
- end
964
-
965
- def step_one(param_for_step_one:, **)
966
- param_for_step_one
967
- end
968
-
969
- def fail_one(**)
970
- ctx[:action_failed] = true
971
- end
972
-
973
- def step_two(**)
974
- ctx[:step_two] = 'Success'
975
- end
976
-
977
- def fail_two(**)
978
- ctx[:fail_two] = 'Failure'
979
- end
980
-
981
- def fail_three(**)
982
- ctx[:fail_three] = 'Failure'
983
- end
984
-
985
- def some_condition?(if_condition_param:, **)
986
- if_condition_param
987
- end
988
- end
989
-
990
- success_action = SomeActionOnUnlessCondition.call(
991
- param_for_step_one: true
992
- )
993
- fail_condition_positive = SomeActionOnUnlessCondition.call(
994
- param_for_step_one: false,
995
- if_condition_param: false
996
- )
997
- fail_condition_negative = SomeActionOnUnlessCondition.call(
998
- param_for_step_one: false,
999
- if_condition_param: true
1000
- )
1001
-
1002
- success_action # =>
1003
- # Result: success
1004
-
1005
- # Railway Flow:
1006
- # step_one -> step_two
1007
-
1008
- # Context:
1009
- # {:param_for_step_one=>true, :step_two=>"Success"}
1010
-
1011
- # Errors:
1012
- # {}
1013
-
1014
- fail_condition_positive # =>
1015
- # Result: failure
1016
-
1017
- # Railway Flow:
1018
- # step_one -> fail_one -> fail_two -> fail_three
1019
-
1020
- # Context:
1021
- # {:param_for_step_one=>false, :if_condition_param=>false, :action_failed=>true, :fail_two=>"Failure", :fail_three=>"Failure"}
1022
-
1023
- # Errors:
1024
- # {}
1025
-
1026
- fail_condition_negative # =>
1027
- # Result: failure
1028
-
1029
- # Railway Flow:
1030
- # step_one -> fail_one -> fail_three
1031
-
1032
- # Context:
1033
- # {:param_for_step_one=>false, :if_condition_param=>true, :action_failed=>true, :fail_three=>"Failure"}
1034
-
1035
- # Errors:
1036
- # {}
1037
- ```
1038
-
1039
-
1040
- ```mermaid
1041
- flowchart LR
1042
- 1(start)-->2(step_one);
1043
- 2(step_one)-->|success tack|3(step_two);
1044
- 3(step_two)-->|success track|4(finish_success);
1045
- 2(step_one)-->|failure track|5(fail_one);
1046
- 5(fail_one)-->|condition positive|6(fail_two);
1047
- 6(fail_two)-->|failure track|7(fail_three);
1048
- 5(fail_one)-->|condition negative|7(fail_three);
1049
- 7(fail_three)-->|failure track|8(finish failure);
1050
- ```
1051
- </p>
1052
- </details>
1053
-
1054
- ***
1055
-
1056
- ### finish_him: :on_success
1057
- The same behavior as for `on_success: :finish_him`
1058
-
1059
- ### finish_him: :on_failure
1060
- The same behavior as for `on_failure: :finish_him`
1061
-
1062
- ### finish_him: true
1063
- Will finish action execution anyway
1064
-
1065
- <details><summary><b>EXAMPLE (CLICK ME)</b></summary>
1066
- <p>
1067
-
1068
- ```ruby
1069
- require 'decouplio'
1070
-
1071
- class SomeActionFinishHimTrue < Decouplio::Action
1072
- logic do
1073
- step :step_one
1074
- fail :fail_one, finish_him: true
1075
- step :step_two
1076
- fail :fail_two
1077
- end
1078
-
1079
- def step_one(param_for_step_one:, **)
1080
- param_for_step_one
1081
- end
1082
-
1083
- def fail_one(fail_one_param:, **)
1084
- ctx[:action_failed] = fail_one_param
1085
- end
1086
-
1087
- def step_two(**)
1088
- ctx[:step_two] = 'Success'
1089
- end
1090
-
1091
- def fail_two(**)
1092
- ctx[:fail_two] = 'Failure'
1093
- end
1094
- end
1095
-
1096
- success_action = SomeActionFinishHimTrue.call(
1097
- param_for_step_one: true
1098
- )
1099
- fail_step_success = SomeActionFinishHimTrue.call(
1100
- param_for_step_one: false,
1101
- fail_one_param: true
1102
- )
1103
- fail_step_failure = SomeActionFinishHimTrue.call(
1104
- param_for_step_one: false,
1105
- fail_one_param: false
1106
- )
1107
-
1108
- success_action # =>
1109
- # Result: success
1110
-
1111
- # Railway Flow:
1112
- # step_one -> step_two
1113
-
1114
- # Context:
1115
- # {:param_for_step_one=>true, :step_two=>"Success"}
1116
-
1117
- # Errors:
1118
- # {}
1119
-
1120
- fail_step_success # =>
1121
- # Result: failure
1122
-
1123
- # Railway Flow:
1124
- # step_one -> fail_one
1125
-
1126
- # Context:
1127
- # {:param_for_step_one=>false, :fail_one_param=>true, :action_failed=>true}
1128
-
1129
- # Errors:
1130
- # {}
1131
-
1132
- fail_step_failure # =>
1133
- # Result: failure
1134
-
1135
- # Railway Flow:
1136
- # step_one -> fail_one
1137
-
1138
- # Context:
1139
- # {:param_for_step_one=>false, :fail_one_param=>false, :action_failed=>false}
1140
-
1141
- # Errors:
1142
- # {}
1143
- ```
1144
-
1145
-
1146
- ```mermaid
1147
- flowchart LR
1148
- 1(start)-->2(step_one);
1149
- 2(step_one)-->|success tack|3(step_two);
1150
- 3(step_two)-->|success track|4(finish_success);
1151
- 2(step_one)-->|failure track|5(fail_one success);
1152
- 5(fail_one success)-->|failure track|6(finish failure);
1153
- 2(step_one)-->|failure track|7(fail_one failure);
1154
- 7(fail_one failure)-->|failure track|6(finish failure);
1155
- ```
1156
- </p>
1157
- </details>
1158
-
1159
- ***