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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +11 -1
  3. data/.rubocop.yml +7 -0
  4. data/README.md +12 -3
  5. data/benchmarks/Gemfile +2 -1
  6. data/benchmarks/multi_step_benchmark.rb +336 -0
  7. data/benchmarks/single_step_benchmark.rb +159 -0
  8. data/decouplio.gemspec +4 -4
  9. data/docker-compose.yml +13 -2
  10. data/lib/decouplio/action.rb +34 -3
  11. data/lib/decouplio/composer.rb +111 -22
  12. data/lib/decouplio/const/doby_aide_options.rb +15 -0
  13. data/lib/decouplio/const/error_messages.rb +9 -0
  14. data/lib/decouplio/const/reserved_methods.rb +13 -9
  15. data/lib/decouplio/const/results.rb +2 -0
  16. data/lib/decouplio/const/types.rb +19 -5
  17. data/lib/decouplio/const/validations/aide.rb +38 -0
  18. data/lib/decouplio/const/validations/doby.rb +36 -0
  19. data/lib/decouplio/const/validations/fail.rb +5 -1
  20. data/lib/decouplio/const/validations/octo.rb +2 -1
  21. data/lib/decouplio/errors/aide_can_not_be_first_step_error.rb +18 -0
  22. data/lib/decouplio/errors/aide_controversial_keys_error.rb +26 -0
  23. data/lib/decouplio/errors/aide_finish_him_error.rb +26 -0
  24. data/lib/decouplio/errors/doby_controversial_keys_error.rb +26 -0
  25. data/lib/decouplio/errors/doby_finish_him_error.rb +26 -0
  26. data/lib/decouplio/errors/execution_error.rb +20 -0
  27. data/lib/decouplio/errors/{fail_is_first_step_error.rb → fail_can_not_be_first_step_error.rb} +1 -1
  28. data/lib/decouplio/errors/step_is_not_defined_for_aide_error.rb +26 -0
  29. data/lib/decouplio/errors/step_is_not_defined_for_doby_error.rb +27 -0
  30. data/lib/decouplio/errors/step_is_not_defined_for_pass_error.rb +27 -0
  31. data/lib/decouplio/logic_dsl.rb +30 -3
  32. data/lib/decouplio/options_validator.rb +162 -13
  33. data/lib/decouplio/steps/aide.rb +37 -0
  34. data/lib/decouplio/steps/base_resq.rb +13 -3
  35. data/lib/decouplio/steps/doby.rb +14 -9
  36. data/lib/decouplio/steps/fail.rb +7 -22
  37. data/lib/decouplio/steps/inner_action_fail.rb +7 -22
  38. data/lib/decouplio/steps/inner_action_step.rb +7 -18
  39. data/lib/decouplio/steps/octo.rb +7 -2
  40. data/lib/decouplio/steps/service_fail.rb +11 -23
  41. data/lib/decouplio/steps/service_pass.rb +4 -1
  42. data/lib/decouplio/steps/service_step.rb +11 -19
  43. data/lib/decouplio/steps/shared/fail_resolver.rb +40 -0
  44. data/lib/decouplio/steps/shared/step_resolver.rb +43 -0
  45. data/lib/decouplio/steps/step.rb +7 -18
  46. data/lib/decouplio/steps/wrap.rb +7 -18
  47. data/lib/decouplio/validators/condition.rb +10 -0
  48. data/lib/decouplio/version.rb +1 -1
  49. metadata +30 -41
  50. data/benchmarks/benchmarks.rb +0 -527
  51. data/docs/_config.yml +0 -1
  52. data/docs/benchmarks.md +0 -1
  53. data/docs/context.md +0 -74
  54. data/docs/context.rb +0 -62
  55. data/docs/doby.md +0 -80
  56. data/docs/doby.rb +0 -38
  57. data/docs/error_store.md +0 -347
  58. data/docs/error_store.rb +0 -202
  59. data/docs/fail.md +0 -1016
  60. data/docs/fail.rb +0 -762
  61. data/docs/index.md +0 -25
  62. data/docs/inner_action.md +0 -63
  63. data/docs/inner_action.rb +0 -43
  64. data/docs/logic_block.md +0 -25
  65. data/docs/octo.md +0 -269
  66. data/docs/octo.rb +0 -164
  67. data/docs/pass.md +0 -309
  68. data/docs/pass.rb +0 -213
  69. data/docs/quick_start.md +0 -71
  70. data/docs/quick_start.rb +0 -38
  71. data/docs/resq.md +0 -263
  72. data/docs/resq.rb +0 -176
  73. data/docs/step.md +0 -737
  74. data/docs/step.rb +0 -526
  75. data/docs/step_as_a_service.md +0 -109
  76. data/docs/step_as_a_service.rb +0 -77
  77. data/docs/wrap.md +0 -232
  78. data/docs/wrap.rb +0 -137
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_error'
4
+ require_relative '../const/validations/doby'
5
+ require_relative '../const/validations/common'
6
+
7
+ module Decouplio
8
+ module Errors
9
+ class StepIsNotDefinedForDobyError < Decouplio::Errors::BaseError
10
+ def template
11
+ Decouplio::Const::Validations::Doby::VALIDATION_ERROR_MESSAGE
12
+ end
13
+
14
+ def interpolation_values
15
+ [
16
+ @errored_option,
17
+ format(
18
+ Decouplio::Const::Validations::Common::STEP_IS_NOT_DEFINED,
19
+ @details
20
+ ),
21
+ Decouplio::Const::Validations::Doby::ALLOWED_OPTIONS_MESSAGE,
22
+ Decouplio::Const::Validations::Doby::MANUAL_URL
23
+ ]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_error'
4
+ require_relative '../const/validations/pass'
5
+ require_relative '../const/validations/common'
6
+
7
+ module Decouplio
8
+ module Errors
9
+ class StepIsNotDefinedForPassError < Decouplio::Errors::BaseError
10
+ def template
11
+ Decouplio::Const::Validations::Pass::VALIDATION_ERROR_MESSAGE
12
+ end
13
+
14
+ def interpolation_values
15
+ [
16
+ @errored_option,
17
+ format(
18
+ Decouplio::Const::Validations::Common::STEP_IS_NOT_DEFINED,
19
+ @details
20
+ ),
21
+ Decouplio::Const::Validations::Pass::ALLOWED_OPTIONS_MESSAGE,
22
+ Decouplio::Const::Validations::Pass::MANUAL_URL
23
+ ]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,13 +2,15 @@
2
2
 
3
3
  require_relative 'flow'
4
4
  require_relative 'const/types'
5
+ require_relative 'const/doby_aide_options'
5
6
  require_relative 'octo_hash_case'
6
7
  require_relative 'errors/options_validation_error'
7
8
  require_relative 'errors/palp_validation_error'
8
9
  require_relative 'errors/resq_definition_error'
9
10
  require_relative 'errors/wrap_block_is_not_defined_error'
10
11
  require_relative 'errors/palp_block_is_not_defined_error'
11
- require_relative 'errors/fail_is_first_step_error'
12
+ require_relative 'errors/fail_can_not_be_first_step_error'
13
+ require_relative 'errors/aide_can_not_be_first_step_error'
12
14
  require_relative 'errors/octo_block_is_not_defined_error'
13
15
 
14
16
  module Decouplio
@@ -32,7 +34,7 @@ module Decouplio
32
34
  end
33
35
 
34
36
  def fail(stp, **options)
35
- raise Decouplio::Errors::FailCanNotBeTheFirstStepError if @steps.empty?
37
+ raise Decouplio::Errors::FailCanNotBeFirstStepError if @steps.empty?
36
38
 
37
39
  @steps << options.merge(type: Decouplio::Const::Types::FAIL_TYPE, name: stp)
38
40
  end
@@ -84,11 +86,36 @@ module Decouplio
84
86
  end
85
87
 
86
88
  def doby(doby_class, **options)
89
+ step_options = {}
90
+ options.each_key do |key|
91
+ step_options[key] = options.delete(key) if Decouplio::Const::DobyAideOptions::ALLOWED.include?(key)
92
+ end
93
+ doby_options = options
94
+
87
95
  @steps << {
88
96
  type: Decouplio::Const::Types::DOBY_TYPE,
89
97
  name: doby_class.name.to_sym,
90
98
  doby_class: doby_class,
91
- doby_options: options
99
+ doby_options: doby_options,
100
+ **step_options
101
+ }
102
+ end
103
+
104
+ def aide(aide_class, **options)
105
+ raise Decouplio::Errors::AideCanNotBeFirstStepError if @steps.empty?
106
+
107
+ step_options = {}
108
+ options.each_key do |key|
109
+ step_options[key] = options.delete(key) if Decouplio::Const::DobyAideOptions::ALLOWED.include?(key)
110
+ end
111
+ aide_options = options
112
+
113
+ @steps << {
114
+ type: Decouplio::Const::Types::AIDE_TYPE,
115
+ name: aide_class.name.to_sym,
116
+ aide_class: aide_class,
117
+ aide_options: aide_options,
118
+ **step_options
92
119
  }
93
120
  end
94
121
  end
@@ -10,6 +10,8 @@ require_relative 'errors/extra_key_for_pass_error'
10
10
  require_relative 'errors/extra_key_for_resq_error'
11
11
  require_relative 'errors/extra_key_for_wrap_error'
12
12
  require_relative 'errors/fail_finish_him_error'
13
+ require_relative 'errors/doby_finish_him_error'
14
+ require_relative 'errors/aide_finish_him_error'
13
15
  require_relative 'errors/invalid_error_class_error'
14
16
  require_relative 'errors/invalid_wrap_name_error'
15
17
  require_relative 'errors/pass_finish_him_error'
@@ -19,10 +21,15 @@ require_relative 'errors/resq_handler_method_error'
19
21
  require_relative 'errors/step_finish_him_error'
20
22
  require_relative 'errors/step_is_not_defined_for_step_error'
21
23
  require_relative 'errors/step_is_not_defined_for_fail_error'
24
+ require_relative 'errors/step_is_not_defined_for_pass_error'
22
25
  require_relative 'errors/step_is_not_defined_for_wrap_error'
26
+ require_relative 'errors/step_is_not_defined_for_aide_error'
27
+ require_relative 'errors/step_is_not_defined_for_doby_error'
23
28
  require_relative 'errors/wrap_finish_him_error'
24
29
  require_relative 'errors/wrap_klass_method_error'
25
30
  require_relative 'errors/step_controversial_keys_error'
31
+ require_relative 'errors/doby_controversial_keys_error'
32
+ require_relative 'errors/aide_controversial_keys_error'
26
33
  require_relative 'errors/fail_controversial_keys_error'
27
34
  require_relative 'errors/pass_controversial_keys_error'
28
35
  require_relative 'errors/octo_controversial_keys_error'
@@ -64,7 +71,7 @@ module Decouplio
64
71
  when Decouplio::Const::Types::FAIL_TYPE
65
72
  validate_fail(options: filtered_options, step_names: step_names)
66
73
  when Decouplio::Const::Types::PASS_TYPE
67
- validate_pass(options: filtered_options)
74
+ validate_pass(options: filtered_options, step_names: step_names)
68
75
  when Decouplio::Const::Types::OCTO_TYPE
69
76
  validate_octo(options: filtered_options, hash_case: options[:hash_case])
70
77
  when Decouplio::Const::Types::WRAP_TYPE
@@ -80,12 +87,16 @@ module Decouplio
80
87
  when Decouplio::Const::Types::ACTION_TYPE_PASS
81
88
  validate_action(action_class: options[:action], type: Decouplio::Const::Types::PASS_TYPE)
82
89
  validate_error_store(parent_action_class: @action_class, child_action_class: options[:action])
83
- validate_pass(options: filtered_options)
90
+ validate_pass(options: filtered_options, step_names: step_names)
84
91
  when Decouplio::Const::Types::RESQ_TYPE_STEP,
85
92
  Decouplio::Const::Types::RESQ_TYPE_FAIL,
86
93
  Decouplio::Const::Types::RESQ_TYPE_PASS
87
94
  validate(options: options[:step_to_resq], step_names: step_names)
88
95
  validate_resq(options: filtered_options)
96
+ when Decouplio::Const::Types::DOBY_TYPE
97
+ validate_doby(options: filtered_options, step_names: step_names)
98
+ when Decouplio::Const::Types::AIDE_TYPE
99
+ validate_aide(options: filtered_options, step_names: step_names)
89
100
  end
90
101
  end
91
102
 
@@ -112,7 +123,8 @@ module Decouplio
112
123
  check_fail_finish_him(options: options)
113
124
  end
114
125
 
115
- def validate_pass(options:)
126
+ def validate_pass(options:, step_names:)
127
+ check_step_presence_for_pass(options: options, step_names: step_names)
116
128
  check_pass_extra_keys(options: options)
117
129
  check_pass_finish_him(options: options)
118
130
  end
@@ -142,6 +154,18 @@ module Decouplio
142
154
  check_resq_exception_classes_inheritance(options: options)
143
155
  end
144
156
 
157
+ def validate_doby(options:, step_names:)
158
+ check_step_presence_for_doby(options: options, step_names: step_names)
159
+ check_doby_controversial_keys(options: options)
160
+ check_doby_finish_him(options: options)
161
+ end
162
+
163
+ def validate_aide(options:, step_names:)
164
+ check_step_presence_for_aide(options: options, step_names: step_names)
165
+ check_aide_controversial_keys(options: options)
166
+ check_aide_finish_him(options: options)
167
+ end
168
+
145
169
  def validate_name(name:)
146
170
  return unless Decouplio::Const::ReservedMethods::NAMES.include?(name)
147
171
 
@@ -152,7 +176,8 @@ module Decouplio
152
176
 
153
177
  def check_step_presence_for_step(options:, step_names:)
154
178
  options.slice(*STEP_CHECK_STEP_PRESENCE).each do |option_key, option_value|
155
- next if %i[on_success on_failure].include?(option_key) && option_value == :finish_him
179
+ next if %i[on_success on_failure on_error].include?(option_key) &&
180
+ STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
156
181
 
157
182
  next if step_names.keys.include?(option_value)
158
183
 
@@ -163,9 +188,52 @@ module Decouplio
163
188
  end
164
189
  end
165
190
 
191
+ def check_step_presence_for_pass(options:, step_names:)
192
+ options.slice(*PASS_CHECK_STEP_PRESENCE).each do |option_key, option_value|
193
+ next if %i[on_error].include?(option_key) &&
194
+ STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
195
+
196
+ next if step_names.keys.include?(option_value)
197
+
198
+ raise Decouplio::Errors::StepIsNotDefinedForPassError.new(
199
+ errored_option: options.slice(option_key).to_s,
200
+ details: option_value
201
+ )
202
+ end
203
+ end
204
+
205
+ def check_step_presence_for_doby(options:, step_names:)
206
+ options.slice(*STEP_CHECK_STEP_PRESENCE).each do |option_key, option_value|
207
+ next if %i[on_success on_failure on_error].include?(option_key) &&
208
+ STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
209
+
210
+ next if step_names.keys.include?(option_value)
211
+
212
+ raise Decouplio::Errors::StepIsNotDefinedForDobyError.new(
213
+ errored_option: options.slice(option_key).to_s,
214
+ details: option_value
215
+ )
216
+ end
217
+ end
218
+
219
+ def check_step_presence_for_aide(options:, step_names:)
220
+ options.slice(*STEP_CHECK_STEP_PRESENCE).each do |option_key, option_value|
221
+ next if %i[on_success on_failure on_error].include?(option_key) &&
222
+ STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
223
+
224
+ next if step_names.keys.include?(option_value)
225
+
226
+ raise Decouplio::Errors::StepIsNotDefinedForAideError.new(
227
+ errored_option: options.slice(option_key).to_s,
228
+ details: option_value
229
+ )
230
+ end
231
+ end
232
+
166
233
  def check_step_presence_for_fail(options:, step_names:)
167
234
  options.slice(*STEP_CHECK_STEP_PRESENCE).each do |option_key, option_value|
168
- next if %i[on_success on_failure].include?(option_key) && option_value == :finish_him
235
+ next if %i[on_success on_failure on_error].include?(option_key) &&
236
+ STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
169
237
 
170
238
  next if step_names.keys.include?(option_value)
171
239
 
@@ -178,7 +246,8 @@ module Decouplio
178
246
 
179
247
  def check_step_presence_for_wrap(options:, step_names:)
180
248
  options.slice(*WRAP_CHECK_STEP_PRESENCE).each do |option_key, option_value|
181
- next if %i[on_success on_failure].include?(option_key) && option_value == :finish_him
249
+ next if %i[on_success on_failure on_error].include?(option_key) &&
250
+ STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
182
251
 
183
252
  next if step_names.keys.include?(option_value)
184
253
 
@@ -211,6 +280,30 @@ module Decouplio
211
280
  end
212
281
  end
213
282
 
283
+ def check_doby_controversial_keys(options:)
284
+ on_success_on_failure = options.slice(:on_success, :on_failure)
285
+ finish_him = options.slice(:finish_him)
286
+
287
+ if !on_success_on_failure.empty? && !finish_him.empty?
288
+ raise Decouplio::Errors::DobyControversialKeysError.new(
289
+ errored_option: on_success_on_failure.merge(finish_him).to_s,
290
+ details: [on_success_on_failure.keys.join(', '), :finish_him]
291
+ )
292
+ end
293
+ end
294
+
295
+ def check_aide_controversial_keys(options:)
296
+ on_success_on_failure = options.slice(:on_success, :on_failure)
297
+ finish_him = options.slice(:finish_him)
298
+
299
+ if !on_success_on_failure.empty? && !finish_him.empty?
300
+ raise Decouplio::Errors::AideControversialKeysError.new(
301
+ errored_option: on_success_on_failure.merge(finish_him).to_s,
302
+ details: [on_success_on_failure.keys.join(', '), :finish_him]
303
+ )
304
+ end
305
+ end
306
+
214
307
  def validate_error_store(parent_action_class:, child_action_class:)
215
308
  return if parent_action_class.error_store == child_action_class.error_store
216
309
 
@@ -304,11 +397,20 @@ module Decouplio
304
397
  end
305
398
 
306
399
  def check_octo_required_keys(options:)
307
- return if (OCTO_REQUIRED_KEYS - options.keys).size.zero?
308
-
309
- raise Decouplio::Errors::RequiredOptionsIsMissingForOctoError.new(
310
- details: OCTO_REQUIRED_KEYS.join(', ')
311
- )
400
+ if (OCTO_REQUIRED_KEYS - options.keys).size.zero?
401
+ if options.keys.sort == OCTO_REQUIRED_KEYS.sort
402
+ raise Decouplio::Errors::OctoControversialKeysError.new(
403
+ errored_option: options.slice(*OCTO_REQUIRED_KEYS),
404
+ details: OCTO_REQUIRED_KEYS
405
+ )
406
+ end
407
+ else
408
+ return if options.slice(*OCTO_REQUIRED_KEYS).size == 1
409
+
410
+ raise Decouplio::Errors::RequiredOptionsIsMissingForOctoError.new(
411
+ details: OCTO_REQUIRED_KEYS.join(', ')
412
+ )
413
+ end
312
414
  end
313
415
 
314
416
  def check_step_finish_him(options:)
@@ -324,6 +426,32 @@ module Decouplio
324
426
  end
325
427
  end
326
428
 
429
+ def check_doby_finish_him(options:)
430
+ finish_him_value = options.dig(:finish_him)
431
+
432
+ return unless finish_him_value && options.key?(:finish_him)
433
+
434
+ unless ALLOWED_STEP_FINISH_HIM_VALUES.include?(finish_him_value)
435
+ raise Decouplio::Errors::DobyFinishHimError.new(
436
+ errored_option: options.slice(:finish_him).to_s,
437
+ details: finish_him_value
438
+ )
439
+ end
440
+ end
441
+
442
+ def check_aide_finish_him(options:)
443
+ finish_him_value = options.dig(:finish_him)
444
+
445
+ return unless options.key?(:finish_him)
446
+
447
+ return if ALLOWED_FAIL_FINISH_HIM_VALUES.include?(finish_him_value)
448
+
449
+ raise Decouplio::Errors::AideFinishHimError.new(
450
+ errored_option: options.slice(:finish_him).to_s,
451
+ details: finish_him_value
452
+ )
453
+ end
454
+
327
455
  def check_fail_finish_him(options:)
328
456
  finish_him_value = options.dig(:finish_him)
329
457
 
@@ -448,16 +576,24 @@ module Decouplio
448
576
  STEP_CHECK_METHOD_EXISTENCE_OPTIONS = %i[
449
577
  on_success
450
578
  on_failure
579
+ on_error
451
580
  if
452
581
  unless
453
582
  ].freeze
454
583
  STEP_CHECK_STEP_PRESENCE = %i[
455
584
  on_success
456
585
  on_failure
586
+ on_error
587
+ ].freeze
588
+ STEP_ALLOWED_ON_S_ON_F_VALUES = [
589
+ Decouplio::Const::Results::STEP_PASS,
590
+ Decouplio::Const::Results::STEP_FAIL,
591
+ Decouplio::Const::Results::FINISH_HIM
457
592
  ].freeze
458
593
  STEP_ALLOWED_OPTIONS = %i[
459
594
  on_success
460
595
  on_failure
596
+ on_error
461
597
  finish_him
462
598
  if
463
599
  unless
@@ -466,6 +602,7 @@ module Decouplio
466
602
  ALLOWED_STEP_FINISH_HIM_VALUES = %i[
467
603
  on_success
468
604
  on_failure
605
+ on_error
469
606
  ].freeze
470
607
 
471
608
  # *************************************************
@@ -479,12 +616,13 @@ module Decouplio
479
616
  FAIL_ALLOWED_OPTIONS = %i[
480
617
  on_success
481
618
  on_failure
619
+ on_error
482
620
  finish_him
483
621
  if
484
622
  unless
485
623
  action
486
624
  ].freeze
487
- ALLOWED_FAIL_FINISH_HIM_VALUES = [true, :on_success, :on_failure].freeze
625
+ ALLOWED_FAIL_FINISH_HIM_VALUES = [true, :on_success, :on_failure, :on_error].freeze
488
626
 
489
627
  # *************************************************
490
628
  # PASS
@@ -495,13 +633,17 @@ module Decouplio
495
633
  if
496
634
  unless
497
635
  action
636
+ on_error
498
637
  ].freeze
499
638
 
500
639
  PASS_CHECK_METHOD_EXISTENCE_OPTIONS = %i[
501
640
  if
502
641
  unless
503
642
  ].freeze
504
- ALLOWED_PASS_FINISH_HIM_VALUES = [true].freeze
643
+ PASS_CHECK_STEP_PRESENCE = %i[
644
+ on_error
645
+ ].freeze
646
+ ALLOWED_PASS_FINISH_HIM_VALUES = [true, :on_error].freeze
505
647
 
506
648
  # *************************************************
507
649
  # OCTO
@@ -509,6 +651,7 @@ module Decouplio
509
651
 
510
652
  OCTO_ALLOWED_OPTIONS = %i[
511
653
  ctx_key
654
+ method
512
655
  if
513
656
  unless
514
657
  ].freeze
@@ -518,6 +661,7 @@ module Decouplio
518
661
  ].freeze
519
662
  OCTO_REQUIRED_KEYS = %i[
520
663
  ctx_key
664
+ method
521
665
  ].freeze
522
666
 
523
667
  # *************************************************
@@ -527,16 +671,19 @@ module Decouplio
527
671
  WRAP_CHECK_METHOD_EXISTENCE_OPTIONS = %i[
528
672
  on_success
529
673
  on_failure
674
+ on_error
530
675
  if
531
676
  unless
532
677
  ].freeze
533
678
  WRAP_CHECK_STEP_PRESENCE = %i[
534
679
  on_success
535
680
  on_failure
681
+ on_error
536
682
  ].freeze
537
683
  WRAP_ALLOWED_OPTIONS = %i[
538
684
  on_success
539
685
  on_failure
686
+ on_error
540
687
  finish_him
541
688
  if
542
689
  unless
@@ -547,6 +694,7 @@ module Decouplio
547
694
  ALLOWED_WRAP_FINISH_HIM_VALUES = %i[
548
695
  on_success
549
696
  on_failure
697
+ on_error
550
698
  ].freeze
551
699
 
552
700
  # *************************************************
@@ -556,6 +704,7 @@ module Decouplio
556
704
  RESQ_NOT_ALLOWED_OPTIONS = %i[
557
705
  on_success
558
706
  on_failure
707
+ on_error
559
708
  finish_him
560
709
  if
561
710
  unless
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_step'
4
+
5
+ module Decouplio
6
+ module Steps
7
+ class Aide < Decouplio::Steps::BaseStep
8
+ def initialize(name:, aide_class:, aide_options:, on_success_type:, on_failure_type:)
9
+ super()
10
+ @name = name
11
+ @aide_class = aide_class
12
+ @aide_options = aide_options
13
+ @on_success_type = on_success_type
14
+ @on_failure_type = on_failure_type
15
+ end
16
+
17
+ def process(instance:)
18
+ instance.append_railway_flow(@name)
19
+ result = @aide_class.call(
20
+ ctx: instance.ctx,
21
+ error_store: instance.error_store,
22
+ **@aide_options
23
+ )
24
+ resolve(instance: instance, result: result)
25
+ end
26
+
27
+ def resolve(instance:, result:)
28
+ Decouplio::Steps::Shared::FailResolver.call(
29
+ instance: instance,
30
+ result: result,
31
+ on_success_type: @on_success_type,
32
+ on_failure_type: @on_failure_type
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
@@ -5,10 +5,11 @@ require_relative 'base_step'
5
5
  module Decouplio
6
6
  module Steps
7
7
  class BaseResq < BaseStep
8
- def initialize(handler_hash:, step_to_resq:)
8
+ def initialize(handler_hash:, step_to_resq:, on_error_type:)
9
9
  super()
10
10
  @handler_hash = handler_hash
11
11
  @step_to_resq = step_to_resq
12
+ @on_error_type = on_error_type
12
13
  end
13
14
 
14
15
  def process(instance:)
@@ -21,8 +22,17 @@ module Decouplio
21
22
  instance.append_railway_flow(handler_method)
22
23
  instance.public_send(handler_method, e, **instance.ctx)
23
24
 
24
- instance.fail_action
25
- Decouplio::Const::Results::ERROR
25
+ case @on_error_type
26
+ when Decouplio::Const::Results::PASS, Decouplio::Const::Results::STEP_PASS
27
+ instance.pass_action
28
+ Decouplio::Const::Results::ERROR
29
+ when Decouplio::Const::Results::FINISH_HIM
30
+ instance.fail_action
31
+ Decouplio::Const::Results::FINISH_HIM
32
+ else
33
+ instance.fail_action
34
+ Decouplio::Const::Results::ERROR
35
+ end
26
36
  else
27
37
  result
28
38
  end
@@ -5,27 +5,32 @@ require_relative 'base_step'
5
5
  module Decouplio
6
6
  module Steps
7
7
  class Doby < Decouplio::Steps::BaseStep
8
- def initialize(name:, doby_class:, doby_options:)
8
+ def initialize(name:, doby_class:, doby_options:, on_success_type:, on_failure_type:)
9
9
  super()
10
10
  @name = name
11
11
  @doby_class = doby_class
12
12
  @doby_options = doby_options
13
+ @on_success_type = on_success_type
14
+ @on_failure_type = on_failure_type
13
15
  end
14
16
 
15
17
  def process(instance:)
16
18
  instance.append_railway_flow(@name)
17
- result = @doby_class.call(ctx: instance.ctx, **@doby_options)
19
+ result = @doby_class.call(
20
+ ctx: instance.ctx,
21
+ error_store: instance.error_store,
22
+ **@doby_options
23
+ )
18
24
  resolve(result: result, instance: instance)
19
25
  end
20
26
 
21
27
  def resolve(result:, instance:)
22
- if result
23
- instance.pass_action
24
- Decouplio::Const::Results::PASS
25
- else
26
- instance.fail_action
27
- Decouplio::Const::Results::FAIL
28
- end
28
+ Decouplio::Steps::Shared::StepResolver.call(
29
+ instance: instance,
30
+ result: result,
31
+ on_success_type: @on_success_type,
32
+ on_failure_type: @on_failure_type
33
+ )
29
34
  end
30
35
  end
31
36
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base_step'
4
+ require_relative 'shared/fail_resolver'
4
5
 
5
6
  module Decouplio
6
7
  module Steps
@@ -22,28 +23,12 @@ module Decouplio
22
23
  private
23
24
 
24
25
  def resolve(result:, instance:)
25
- if result
26
- case @on_success_type
27
- when Decouplio::Const::Results::PASS
28
- instance.pass_action
29
- Decouplio::Const::Results::PASS
30
- when Decouplio::Const::Results::FAIL
31
- instance.fail_action
32
- Decouplio::Const::Results::PASS
33
- when Decouplio::Const::Results::FINISH_HIM
34
- instance.fail_action
35
- Decouplio::Const::Results::FINISH_HIM
36
- end
37
- elsif @on_failure_type == Decouplio::Const::Results::PASS
38
- instance.pass_action
39
- Decouplio::Const::Results::FAIL
40
- elsif @on_failure_type == Decouplio::Const::Results::FAIL
41
- instance.fail_action
42
- Decouplio::Const::Results::FAIL
43
- elsif @on_failure_type == Decouplio::Const::Results::FINISH_HIM
44
- instance.fail_action
45
- Decouplio::Const::Results::FINISH_HIM
46
- end
26
+ Decouplio::Steps::Shared::FailResolver.call(
27
+ instance: instance,
28
+ result: result,
29
+ on_success_type: @on_success_type,
30
+ on_failure_type: @on_failure_type
31
+ )
47
32
  end
48
33
  end
49
34
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base_step'
4
+ require_relative 'shared/fail_resolver'
4
5
 
5
6
  module Decouplio
6
7
  module Steps
@@ -27,28 +28,12 @@ module Decouplio
27
28
 
28
29
  instance.error_store.merge(outcome.error_store)
29
30
 
30
- if result
31
- case @on_success_type
32
- when Decouplio::Const::Results::PASS
33
- instance.pass_action
34
- Decouplio::Const::Results::PASS
35
- when Decouplio::Const::Results::FAIL
36
- instance.fail_action
37
- Decouplio::Const::Results::PASS
38
- when Decouplio::Const::Results::FINISH_HIM
39
- instance.fail_action
40
- Decouplio::Const::Results::FINISH_HIM
41
- end
42
- elsif @on_failure_type == Decouplio::Const::Results::PASS
43
- instance.pass_action
44
- Decouplio::Const::Results::FAIL
45
- elsif @on_failure_type == Decouplio::Const::Results::FAIL
46
- instance.fail_action
47
- Decouplio::Const::Results::FAIL
48
- elsif @on_failure_type == Decouplio::Const::Results::FINISH_HIM
49
- instance.fail_action
50
- Decouplio::Const::Results::FINISH_HIM
51
- end
31
+ Decouplio::Steps::Shared::FailResolver.call(
32
+ instance: instance,
33
+ result: result,
34
+ on_success_type: @on_success_type,
35
+ on_failure_type: @on_failure_type
36
+ )
52
37
  end
53
38
  end
54
39
  end