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
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_error'
4
+ require_relative '../const/validations/doby'
5
+
6
+ module Decouplio
7
+ module Errors
8
+ class DobyControversialKeysError < Decouplio::Errors::BaseError
9
+ def template
10
+ Decouplio::Const::Validations::Doby::VALIDATION_ERROR_MESSAGE
11
+ end
12
+
13
+ def interpolation_values
14
+ [
15
+ @errored_option,
16
+ format(
17
+ Decouplio::Const::Validations::Doby::CONTROVERSIAL_KEYS,
18
+ *@details
19
+ ),
20
+ Decouplio::Const::Validations::Doby::ALLOWED_OPTIONS_MESSAGE,
21
+ Decouplio::Const::Validations::Doby::MANUAL_URL
22
+ ]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_error'
4
+ require_relative '../const/validations/doby'
5
+
6
+ module Decouplio
7
+ module Errors
8
+ class DobyFinishHimError < Decouplio::Errors::BaseError
9
+ def template
10
+ Decouplio::Const::Validations::Doby::VALIDATION_ERROR_MESSAGE
11
+ end
12
+
13
+ def interpolation_values
14
+ [
15
+ @errored_option,
16
+ format(
17
+ Decouplio::Const::Validations::Common::WRONG_FINISH_HIM_VALUE,
18
+ @details
19
+ ),
20
+ Decouplio::Const::Validations::Doby::ALLOWED_OPTIONS_MESSAGE,
21
+ Decouplio::Const::Validations::Doby::MANUAL_URL
22
+ ]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../const/error_messages'
4
+
5
+ module Decouplio
6
+ module Errors
7
+ class ExecutionError < StandardError
8
+ attr_reader :action
9
+
10
+ def initialize(action:)
11
+ @action = action
12
+ super(message)
13
+ end
14
+
15
+ def message
16
+ Decouplio::Const::ErrorMessages::EXECUTION_ERROR
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_error'
4
+ require_relative '../const/validations/fail'
5
+
6
+ module Decouplio
7
+ module Errors
8
+ class StepIsNotDefinedForAideError < Decouplio::Errors::BaseError
9
+ def template
10
+ Decouplio::Const::Validations::Aide::VALIDATION_ERROR_MESSAGE
11
+ end
12
+
13
+ def interpolation_values
14
+ [
15
+ @errored_option,
16
+ format(
17
+ Decouplio::Const::Validations::Common::STEP_IS_NOT_DEFINED,
18
+ @details
19
+ ),
20
+ Decouplio::Const::Validations::Aide::ALLOWED_OPTIONS_MESSAGE,
21
+ Decouplio::Const::Validations::Aide::MANUAL_URL
22
+ ]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -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,6 +2,7 @@
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'
@@ -9,7 +10,7 @@ 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
12
  require_relative 'errors/fail_can_not_be_first_step_error'
12
- require_relative 'errors/deny_can_not_be_first_step_error'
13
+ require_relative 'errors/aide_can_not_be_first_step_error'
13
14
  require_relative 'errors/octo_block_is_not_defined_error'
14
15
 
15
16
  module Decouplio
@@ -85,22 +86,36 @@ module Decouplio
85
86
  end
86
87
 
87
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
+
88
95
  @steps << {
89
96
  type: Decouplio::Const::Types::DOBY_TYPE,
90
97
  name: doby_class.name.to_sym,
91
98
  doby_class: doby_class,
92
- doby_options: options
99
+ doby_options: doby_options,
100
+ **step_options
93
101
  }
94
102
  end
95
103
 
96
- def deny(deny_class, **options)
97
- raise Decouplio::Errors::DenyCanNotBeFirstStepError if @steps.empty?
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
98
112
 
99
113
  @steps << {
100
- type: Decouplio::Const::Types::DENY_TYPE,
101
- name: deny_class.name.to_sym,
102
- deny_class: deny_class,
103
- deny_options: options
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
104
119
  }
105
120
  end
106
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) && STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
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) && STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
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) && STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
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,12 +576,14 @@ 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
457
587
  ].freeze
458
588
  STEP_ALLOWED_ON_S_ON_F_VALUES = [
459
589
  Decouplio::Const::Results::STEP_PASS,
@@ -463,6 +593,7 @@ module Decouplio
463
593
  STEP_ALLOWED_OPTIONS = %i[
464
594
  on_success
465
595
  on_failure
596
+ on_error
466
597
  finish_him
467
598
  if
468
599
  unless
@@ -471,6 +602,7 @@ module Decouplio
471
602
  ALLOWED_STEP_FINISH_HIM_VALUES = %i[
472
603
  on_success
473
604
  on_failure
605
+ on_error
474
606
  ].freeze
475
607
 
476
608
  # *************************************************
@@ -484,12 +616,13 @@ module Decouplio
484
616
  FAIL_ALLOWED_OPTIONS = %i[
485
617
  on_success
486
618
  on_failure
619
+ on_error
487
620
  finish_him
488
621
  if
489
622
  unless
490
623
  action
491
624
  ].freeze
492
- 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
493
626
 
494
627
  # *************************************************
495
628
  # PASS
@@ -500,13 +633,17 @@ module Decouplio
500
633
  if
501
634
  unless
502
635
  action
636
+ on_error
503
637
  ].freeze
504
638
 
505
639
  PASS_CHECK_METHOD_EXISTENCE_OPTIONS = %i[
506
640
  if
507
641
  unless
508
642
  ].freeze
509
- 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
510
647
 
511
648
  # *************************************************
512
649
  # OCTO
@@ -514,6 +651,7 @@ module Decouplio
514
651
 
515
652
  OCTO_ALLOWED_OPTIONS = %i[
516
653
  ctx_key
654
+ method
517
655
  if
518
656
  unless
519
657
  ].freeze
@@ -523,6 +661,7 @@ module Decouplio
523
661
  ].freeze
524
662
  OCTO_REQUIRED_KEYS = %i[
525
663
  ctx_key
664
+ method
526
665
  ].freeze
527
666
 
528
667
  # *************************************************
@@ -532,16 +671,19 @@ module Decouplio
532
671
  WRAP_CHECK_METHOD_EXISTENCE_OPTIONS = %i[
533
672
  on_success
534
673
  on_failure
674
+ on_error
535
675
  if
536
676
  unless
537
677
  ].freeze
538
678
  WRAP_CHECK_STEP_PRESENCE = %i[
539
679
  on_success
540
680
  on_failure
681
+ on_error
541
682
  ].freeze
542
683
  WRAP_ALLOWED_OPTIONS = %i[
543
684
  on_success
544
685
  on_failure
686
+ on_error
545
687
  finish_him
546
688
  if
547
689
  unless
@@ -552,6 +694,7 @@ module Decouplio
552
694
  ALLOWED_WRAP_FINISH_HIM_VALUES = %i[
553
695
  on_success
554
696
  on_failure
697
+ on_error
555
698
  ].freeze
556
699
 
557
700
  # *************************************************
@@ -561,6 +704,7 @@ module Decouplio
561
704
  RESQ_NOT_ALLOWED_OPTIONS = %i[
562
705
  on_success
563
706
  on_failure
707
+ on_error
564
708
  finish_him
565
709
  if
566
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,11 +5,13 @@ 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:)
@@ -23,13 +25,12 @@ module Decouplio
23
25
  end
24
26
 
25
27
  def resolve(result:, instance:)
26
- if result
27
- instance.pass_action
28
- Decouplio::Const::Results::PASS
29
- else
30
- instance.fail_action
31
- Decouplio::Const::Results::FAIL
32
- 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
+ )
33
34
  end
34
35
  end
35
36
  end