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/step.rb
DELETED
@@ -1,526 +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
|
-
step :step_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 step_two(**)
|
22
|
-
ctx[:result] = 'Success'
|
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 -> step_two
|
34
|
-
|
35
|
-
# Context:
|
36
|
-
# {:param_for_step_one=>true, :result=>"Success"}
|
37
|
-
|
38
|
-
# Errors:
|
39
|
-
# {}
|
40
|
-
|
41
|
-
puts failure_action # =>
|
42
|
-
# Result: failure
|
43
|
-
|
44
|
-
# Railway Flow:
|
45
|
-
# step_one -> fail_one
|
46
|
-
|
47
|
-
# Context:
|
48
|
-
# {:param_for_step_one=>false, :action_failed=>true}
|
49
|
-
|
50
|
-
# Errors:
|
51
|
-
# {}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
# on_success: :finish_him
|
56
|
-
class SomeActionOnSuccessFinishHim < Decouplio::Action
|
57
|
-
logic do
|
58
|
-
step :step_one, on_success: :finish_him
|
59
|
-
fail :fail_one
|
60
|
-
step :step_two
|
61
|
-
end
|
62
|
-
|
63
|
-
def step_one(param_for_step_one:, **)
|
64
|
-
param_for_step_one
|
65
|
-
end
|
66
|
-
|
67
|
-
def fail_one(**)
|
68
|
-
ctx[:action_failed] = true
|
69
|
-
end
|
70
|
-
|
71
|
-
def step_two(**)
|
72
|
-
ctx[:result] = 'Success'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
success_action = SomeActionOnSuccessFinishHim.call(param_for_step_one: true)
|
77
|
-
failure_action = SomeActionOnSuccessFinishHim.call(param_for_step_one: false)
|
78
|
-
|
79
|
-
puts success_action # =>
|
80
|
-
# Result: success
|
81
|
-
|
82
|
-
# Railway Flow:
|
83
|
-
# step_one
|
84
|
-
|
85
|
-
# Context:
|
86
|
-
# {:param_for_step_one=>true}
|
87
|
-
|
88
|
-
# Errors:
|
89
|
-
# {}
|
90
|
-
|
91
|
-
puts failure_action # =>
|
92
|
-
# Result: failure
|
93
|
-
|
94
|
-
# Railway Flow:
|
95
|
-
# step_one -> fail_one
|
96
|
-
|
97
|
-
# Context:
|
98
|
-
# {:param_for_step_one=>false, :action_failed=>true}
|
99
|
-
|
100
|
-
# Errors:
|
101
|
-
# {}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
# on_success: next success track step
|
106
|
-
class SomeActionOnSuccessToSuccessTrack < Decouplio::Action
|
107
|
-
logic do
|
108
|
-
step :step_one, on_success: :step_three
|
109
|
-
fail :fail_one
|
110
|
-
step :step_two
|
111
|
-
step :step_three
|
112
|
-
end
|
113
|
-
|
114
|
-
def step_one(param_for_step_one:, **)
|
115
|
-
param_for_step_one
|
116
|
-
end
|
117
|
-
|
118
|
-
def fail_one(**)
|
119
|
-
ctx[:action_failed] = true
|
120
|
-
end
|
121
|
-
|
122
|
-
def step_two(**)
|
123
|
-
ctx[:step_two] = 'Success'
|
124
|
-
end
|
125
|
-
|
126
|
-
def step_three(**)
|
127
|
-
ctx[:result] = 'Result'
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
success_action = SomeActionOnSuccessToSuccessTrack.call(param_for_step_one: true)
|
132
|
-
failure_action = SomeActionOnSuccessToSuccessTrack.call(param_for_step_one: false)
|
133
|
-
puts success_action # =>
|
134
|
-
# Result: success
|
135
|
-
|
136
|
-
# Railway Flow:
|
137
|
-
# step_one -> step_three
|
138
|
-
|
139
|
-
# Context:
|
140
|
-
# {:param_for_step_one=>true, :result=>"Result"}
|
141
|
-
|
142
|
-
# Errors:
|
143
|
-
# {}
|
144
|
-
|
145
|
-
|
146
|
-
puts failure_action # =>
|
147
|
-
# Result: failure
|
148
|
-
|
149
|
-
# Railway Flow:
|
150
|
-
# step_one -> fail_one
|
151
|
-
|
152
|
-
# Context:
|
153
|
-
# {:param_for_step_one=>false, :action_failed=>true}
|
154
|
-
|
155
|
-
# Errors:
|
156
|
-
# {}
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
# on_success: next failure track step
|
161
|
-
class SomeActionOnSuccessToFailureTrack < Decouplio::Action
|
162
|
-
logic do
|
163
|
-
step :step_one, on_success: :fail_two
|
164
|
-
fail :fail_one
|
165
|
-
step :step_two
|
166
|
-
step :step_three
|
167
|
-
fail :fail_two
|
168
|
-
end
|
169
|
-
|
170
|
-
def step_one(param_for_step_one:, **)
|
171
|
-
param_for_step_one
|
172
|
-
end
|
173
|
-
|
174
|
-
def fail_one(**)
|
175
|
-
ctx[:action_failed] = true
|
176
|
-
end
|
177
|
-
|
178
|
-
def step_two(**)
|
179
|
-
ctx[:step_two] = 'Success'
|
180
|
-
end
|
181
|
-
|
182
|
-
def step_three(**)
|
183
|
-
ctx[:result] = 'Result'
|
184
|
-
end
|
185
|
-
|
186
|
-
def fail_two(**)
|
187
|
-
ctx[:fail_two] = 'Failure'
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
success_action = SomeActionOnSuccessToFailureTrack.call(param_for_step_one: true)
|
192
|
-
failure_action = SomeActionOnSuccessToFailureTrack.call(param_for_step_one: false)
|
193
|
-
puts success_action # =>
|
194
|
-
# Result: failure
|
195
|
-
|
196
|
-
# Railway Flow:
|
197
|
-
# step_one -> fail_two
|
198
|
-
|
199
|
-
# Context:
|
200
|
-
# {:param_for_step_one=>true, :fail_two=>"Failure"}
|
201
|
-
|
202
|
-
# Errors:
|
203
|
-
# {}
|
204
|
-
|
205
|
-
puts failure_action # =>
|
206
|
-
# Result: failure
|
207
|
-
|
208
|
-
# Railway Flow:
|
209
|
-
# step_one -> fail_one -> fail_two
|
210
|
-
|
211
|
-
# Context:
|
212
|
-
# {:param_for_step_one=>false, :action_failed=>true, :fail_two=>"Failure"}
|
213
|
-
|
214
|
-
# Errors:
|
215
|
-
# {}
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
# on_failure: :finish_him
|
220
|
-
class SomeActionOnFailureFinishHim < Decouplio::Action
|
221
|
-
logic do
|
222
|
-
step :step_one, on_failure: :finish_him
|
223
|
-
fail :fail_one
|
224
|
-
step :step_two
|
225
|
-
fail :fail_two
|
226
|
-
end
|
227
|
-
|
228
|
-
def step_one(param_for_step_one:, **)
|
229
|
-
param_for_step_one
|
230
|
-
end
|
231
|
-
|
232
|
-
def fail_one(**)
|
233
|
-
ctx[:action_failed] = true
|
234
|
-
end
|
235
|
-
|
236
|
-
def step_two(**)
|
237
|
-
ctx[:result] = 'Success'
|
238
|
-
end
|
239
|
-
|
240
|
-
def fail_two(**)
|
241
|
-
ctx[:fail_two] = 'failure'
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
success_action = SomeActionOnFailureFinishHim.call(param_for_step_one: true)
|
246
|
-
failure_action = SomeActionOnFailureFinishHim.call(param_for_step_one: false)
|
247
|
-
puts success_action # =>
|
248
|
-
# Result: success
|
249
|
-
|
250
|
-
# Railway Flow:
|
251
|
-
# step_one -> step_two
|
252
|
-
|
253
|
-
# Context:
|
254
|
-
# {:param_for_step_one=>true, :result=>"Success"}
|
255
|
-
|
256
|
-
# Errors:
|
257
|
-
# {}
|
258
|
-
|
259
|
-
puts failure_action # =>
|
260
|
-
# Result: failure
|
261
|
-
|
262
|
-
# Railway Flow:
|
263
|
-
# step_one
|
264
|
-
|
265
|
-
# Context:
|
266
|
-
# {:param_for_step_one=>false}
|
267
|
-
|
268
|
-
# Errors:
|
269
|
-
# {}
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
# on_failure: next success track step
|
274
|
-
class SomeActionOnFailureToSuccessTrack < Decouplio::Action
|
275
|
-
logic do
|
276
|
-
step :step_one, on_failure: :step_three
|
277
|
-
fail :fail_one
|
278
|
-
step :step_two
|
279
|
-
fail :fail_two
|
280
|
-
step :step_three
|
281
|
-
end
|
282
|
-
|
283
|
-
def step_one(param_for_step_one:, **)
|
284
|
-
param_for_step_one
|
285
|
-
end
|
286
|
-
|
287
|
-
def fail_one(**)
|
288
|
-
ctx[:action_failed] = true
|
289
|
-
end
|
290
|
-
|
291
|
-
def step_two(**)
|
292
|
-
ctx[:result] = 'Success'
|
293
|
-
end
|
294
|
-
|
295
|
-
def fail_two(**)
|
296
|
-
ctx[:fail_two] = 'failure'
|
297
|
-
end
|
298
|
-
|
299
|
-
def step_three(**)
|
300
|
-
ctx[:step_three] = 'Success'
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
success_action = SomeActionOnFailureToSuccessTrack.call(param_for_step_one: true)
|
305
|
-
failure_action = SomeActionOnFailureToSuccessTrack.call(param_for_step_one: false)
|
306
|
-
puts success_action # =>
|
307
|
-
# Result: success
|
308
|
-
|
309
|
-
# Railway Flow:
|
310
|
-
# step_one -> step_two -> step_three
|
311
|
-
|
312
|
-
# Context:
|
313
|
-
# {:param_for_step_one=>true, :result=>"Success", :step_three=>"Success"}
|
314
|
-
|
315
|
-
# Errors:
|
316
|
-
# {}
|
317
|
-
|
318
|
-
|
319
|
-
puts failure_action # =>
|
320
|
-
# Result: success
|
321
|
-
|
322
|
-
# Railway Flow:
|
323
|
-
# step_one -> step_three
|
324
|
-
|
325
|
-
# Context:
|
326
|
-
# {:param_for_step_one=>false, :step_three=>"Success"}
|
327
|
-
|
328
|
-
# Errors:
|
329
|
-
# {}
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
# on_failure: next failure track step
|
334
|
-
class SomeActionOnFailureToFailureTrack < Decouplio::Action
|
335
|
-
logic do
|
336
|
-
step :step_one, on_failure: :fail_two
|
337
|
-
fail :fail_one
|
338
|
-
step :step_two
|
339
|
-
fail :fail_two
|
340
|
-
step :step_three
|
341
|
-
end
|
342
|
-
|
343
|
-
def step_one(param_for_step_one:, **)
|
344
|
-
param_for_step_one
|
345
|
-
end
|
346
|
-
|
347
|
-
def fail_one(**)
|
348
|
-
ctx[:action_failed] = true
|
349
|
-
end
|
350
|
-
|
351
|
-
def step_two(**)
|
352
|
-
ctx[:result] = 'Success'
|
353
|
-
end
|
354
|
-
|
355
|
-
def fail_two(**)
|
356
|
-
ctx[:fail_two] = 'failure'
|
357
|
-
end
|
358
|
-
|
359
|
-
def step_three(**)
|
360
|
-
ctx[:step_three] = 'Success'
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
success_action = SomeActionOnFailureToFailureTrack.call(param_for_step_one: true)
|
365
|
-
failure_action = SomeActionOnFailureToFailureTrack.call(param_for_step_one: false)
|
366
|
-
puts success_action # =>
|
367
|
-
# Result: success
|
368
|
-
|
369
|
-
# Railway Flow:
|
370
|
-
# step_one -> step_two -> step_three
|
371
|
-
|
372
|
-
# Context:
|
373
|
-
# {:param_for_step_one=>true, :result=>"Success", :step_three=>"Success"}
|
374
|
-
|
375
|
-
# Errors:
|
376
|
-
# {}
|
377
|
-
|
378
|
-
puts failure_action # =>
|
379
|
-
# Result: failure
|
380
|
-
|
381
|
-
# Railway Flow:
|
382
|
-
# step_one -> fail_two
|
383
|
-
|
384
|
-
# Context:
|
385
|
-
# {:param_for_step_one=>false, :fail_two=>"failure"}
|
386
|
-
|
387
|
-
# Errors:
|
388
|
-
# {}
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
# if: condition method name
|
393
|
-
class SomeActionOnIfCondition < Decouplio::Action
|
394
|
-
logic do
|
395
|
-
step :step_one
|
396
|
-
fail :fail_one
|
397
|
-
step :step_two
|
398
|
-
fail :fail_two
|
399
|
-
step :step_three, if: :step_condition?
|
400
|
-
end
|
401
|
-
|
402
|
-
def step_one(param_for_step_one:, **)
|
403
|
-
param_for_step_one
|
404
|
-
end
|
405
|
-
|
406
|
-
def fail_one(**)
|
407
|
-
ctx[:action_failed] = true
|
408
|
-
end
|
409
|
-
|
410
|
-
def step_two(**)
|
411
|
-
ctx[:result] = 'Success'
|
412
|
-
end
|
413
|
-
|
414
|
-
def fail_two(**)
|
415
|
-
ctx[:fail_two] = 'failure'
|
416
|
-
end
|
417
|
-
|
418
|
-
def step_three(**)
|
419
|
-
ctx[:step_three] = 'Success'
|
420
|
-
end
|
421
|
-
|
422
|
-
def step_condition?(step_condition_param:, **)
|
423
|
-
step_condition_param
|
424
|
-
end
|
425
|
-
end
|
426
|
-
|
427
|
-
condition_positive = SomeActionOnIfCondition.call(
|
428
|
-
param_for_step_one: true,
|
429
|
-
step_condition_param: true
|
430
|
-
)
|
431
|
-
condition_negative = SomeActionOnIfCondition.call(
|
432
|
-
param_for_step_one: true,
|
433
|
-
step_condition_param: false
|
434
|
-
)
|
435
|
-
puts condition_positive # =>
|
436
|
-
# Result: success
|
437
|
-
|
438
|
-
# Railway Flow:
|
439
|
-
# step_one -> step_two -> step_three
|
440
|
-
|
441
|
-
# Context:
|
442
|
-
# {:param_for_step_one=>true, :step_condition_param=>true, :result=>"Success", :step_three=>"Success"}
|
443
|
-
|
444
|
-
# Errors:
|
445
|
-
# {}
|
446
|
-
|
447
|
-
puts condition_negative # =>
|
448
|
-
# Result: success
|
449
|
-
|
450
|
-
# Railway Flow:
|
451
|
-
# step_one -> step_two
|
452
|
-
|
453
|
-
# Context:
|
454
|
-
# {:param_for_step_one=>true, :step_condition_param=>false, :result=>"Success"}
|
455
|
-
|
456
|
-
# Errors:
|
457
|
-
# {}
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
# unless: condition method name
|
462
|
-
class SomeActionOnUnlessCondition < Decouplio::Action
|
463
|
-
logic do
|
464
|
-
step :step_one
|
465
|
-
fail :fail_one
|
466
|
-
step :step_two
|
467
|
-
fail :fail_two
|
468
|
-
step :step_three, unless: :step_condition?
|
469
|
-
end
|
470
|
-
|
471
|
-
def step_one(param_for_step_one:, **)
|
472
|
-
param_for_step_one
|
473
|
-
end
|
474
|
-
|
475
|
-
def fail_one(**)
|
476
|
-
ctx[:action_failed] = true
|
477
|
-
end
|
478
|
-
|
479
|
-
def step_two(**)
|
480
|
-
ctx[:result] = 'Success'
|
481
|
-
end
|
482
|
-
|
483
|
-
def fail_two(**)
|
484
|
-
ctx[:fail_two] = 'failure'
|
485
|
-
end
|
486
|
-
|
487
|
-
def step_three(**)
|
488
|
-
ctx[:step_three] = 'Success'
|
489
|
-
end
|
490
|
-
|
491
|
-
def step_condition?(step_condition_param:, **)
|
492
|
-
step_condition_param
|
493
|
-
end
|
494
|
-
end
|
495
|
-
|
496
|
-
condition_positive = SomeActionOnUnlessCondition.call(
|
497
|
-
param_for_step_one: true,
|
498
|
-
step_condition_param: true
|
499
|
-
)
|
500
|
-
condition_negative = SomeActionOnUnlessCondition.call(
|
501
|
-
param_for_step_one: true,
|
502
|
-
step_condition_param: false
|
503
|
-
)
|
504
|
-
puts condition_positive # =>
|
505
|
-
# Result: success
|
506
|
-
|
507
|
-
# Railway Flow:
|
508
|
-
# step_one -> step_two
|
509
|
-
|
510
|
-
# Context:
|
511
|
-
# {:param_for_step_one=>true, :step_condition_param=>true, :result=>"Success"}
|
512
|
-
|
513
|
-
# Errors:
|
514
|
-
# {}
|
515
|
-
|
516
|
-
puts condition_negative # =>
|
517
|
-
# Result: success
|
518
|
-
|
519
|
-
# Railway Flow:
|
520
|
-
# step_one -> step_two -> step_three
|
521
|
-
|
522
|
-
# Context:
|
523
|
-
# {:param_for_step_one=>true, :step_condition_param=>false, :result=>"Success", :step_three=>"Success"}
|
524
|
-
|
525
|
-
# Errors:
|
526
|
-
# {}
|
data/docs/step_as_a_service.md
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
# Step as a service
|
2
|
-
|
3
|
-
It's similar to [Inner action](https://github.com/differencialx/decouplio/blob/master/docs/inner_action.md), but instead of using `Decouplio::Action`, you can use PORO class.
|
4
|
-
|
5
|
-
## Signature
|
6
|
-
|
7
|
-
```ruby
|
8
|
-
(step|fail|pass)(service_class, **options)
|
9
|
-
```
|
10
|
-
|
11
|
-
## How to use?
|
12
|
-
|
13
|
-
Create a PORO class with `.call` class method.
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
# :ctx - is the required kwarg
|
17
|
-
class Concat
|
18
|
-
def self.call(ctx:)
|
19
|
-
new(ctx: ctx).call
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize(ctx:)
|
23
|
-
@ctx = ctx
|
24
|
-
end
|
25
|
-
|
26
|
-
def call
|
27
|
-
@ctx[:result] = @ctx[:one] + @ctx[:two]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# OR
|
32
|
-
|
33
|
-
# :ctx - is the required kwarg
|
34
|
-
class Subtract
|
35
|
-
def self.call(ctx:)
|
36
|
-
ctx[:result] = ctx[:one] - ctx[:two]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
```
|
40
|
-
|
41
|
-
Now you can use these classes as a `step|fail|pass` step
|
42
|
-
|
43
|
-
```ruby
|
44
|
-
class SomeActionConcat < Decouplio::Action
|
45
|
-
logic do
|
46
|
-
step Concat
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
action = SomeActionConcat.call(one: 1, two: 2)
|
51
|
-
|
52
|
-
puts action[:result] # => 3
|
53
|
-
|
54
|
-
puts action # =>
|
55
|
-
# Result: success
|
56
|
-
|
57
|
-
# Railway Flow:
|
58
|
-
# Concat
|
59
|
-
|
60
|
-
# Context:
|
61
|
-
# {:one=>1, :two=>2, :result=>3}
|
62
|
-
|
63
|
-
# Errors:
|
64
|
-
# {}
|
65
|
-
```
|
66
|
-
|
67
|
-
OR
|
68
|
-
|
69
|
-
```ruby
|
70
|
-
class SomeActionSubtract < Decouplio::Action
|
71
|
-
logic do
|
72
|
-
step :init_one
|
73
|
-
step :init_two
|
74
|
-
step Subtract
|
75
|
-
end
|
76
|
-
|
77
|
-
def init_one(param_one:, **)
|
78
|
-
ctx[:one] = param_one
|
79
|
-
end
|
80
|
-
|
81
|
-
def init_two(param_two:, **)
|
82
|
-
ctx[:two] = param_two
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
action = SomeActionSubtract.call(param_one: 5, param_two: 2)
|
87
|
-
|
88
|
-
puts action[:result] # => 3
|
89
|
-
|
90
|
-
puts action # =>
|
91
|
-
# Result: success
|
92
|
-
|
93
|
-
# Railway Flow:
|
94
|
-
# init_one -> init_two -> Subtract
|
95
|
-
|
96
|
-
# Context:
|
97
|
-
# {:param_one=>5, :param_two=>2, :one=>5, :two=>2, :result=>3}
|
98
|
-
|
99
|
-
# Errors:
|
100
|
-
# {}
|
101
|
-
|
102
|
-
```
|
103
|
-
|
104
|
-
## Behavior
|
105
|
-
|
106
|
-
- service class should implement `.call` class method
|
107
|
-
- service class can be used as `step` or `fail` or `pass`
|
108
|
-
- all options of `step|fail|pass` can be used as [Inner action](https://github.com/differencialx/decouplio/blob/master/docs/inner_action.md)
|
109
|
-
- depending on returning value of `.call` method(truthy ot falsy) the execution will be moved to `success or failure` track accordingly.
|
data/docs/step_as_a_service.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require_relative '../lib/decouplio'
|
2
|
-
|
3
|
-
class Concat
|
4
|
-
def self.call(ctx:)
|
5
|
-
new(ctx: ctx).call
|
6
|
-
end
|
7
|
-
|
8
|
-
def initialize(ctx:)
|
9
|
-
@ctx = ctx
|
10
|
-
end
|
11
|
-
|
12
|
-
def call
|
13
|
-
@ctx[:result] = @ctx[:one] + @ctx[:two]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Subtract
|
18
|
-
def self.call(ctx:)
|
19
|
-
ctx[:result] = ctx[:one] - ctx[:two]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class SomeActionConcat < Decouplio::Action
|
24
|
-
logic do
|
25
|
-
step Concat
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
action = SomeActionConcat.call(one: 1, two: 2)
|
30
|
-
|
31
|
-
puts action[:result] # => 3
|
32
|
-
|
33
|
-
puts action # =>
|
34
|
-
# Result: success
|
35
|
-
|
36
|
-
# Railway Flow:
|
37
|
-
# Concat
|
38
|
-
|
39
|
-
# Context:
|
40
|
-
# {:one=>1, :two=>2, :result=>3}
|
41
|
-
|
42
|
-
# Errors:
|
43
|
-
# {}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
class SomeActionSubtract < Decouplio::Action
|
48
|
-
logic do
|
49
|
-
step :init_one
|
50
|
-
step :init_two
|
51
|
-
step Subtract
|
52
|
-
end
|
53
|
-
|
54
|
-
def init_one(param_one:, **)
|
55
|
-
ctx[:one] = param_one
|
56
|
-
end
|
57
|
-
|
58
|
-
def init_two(param_two:, **)
|
59
|
-
ctx[:two] = param_two
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
action = SomeActionSubtract.call(param_one: 5, param_two: 2)
|
64
|
-
|
65
|
-
puts action[:result] # => 3
|
66
|
-
|
67
|
-
puts action # =>
|
68
|
-
# Result: success
|
69
|
-
|
70
|
-
# Railway Flow:
|
71
|
-
# init_one -> init_two -> Subtract
|
72
|
-
|
73
|
-
# Context:
|
74
|
-
# {:param_one=>5, :param_two=>2, :one=>5, :two=>2, :result=>3}
|
75
|
-
|
76
|
-
# Errors:
|
77
|
-
# {}
|