decouplio 1.0.0alpha8 → 1.0.0rc
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/README.md +313 -15
- data/decouplio.gemspec +8 -2
- data/lib/decouplio/action.rb +24 -40
- data/lib/decouplio/action_state_printer.rb +2 -5
- data/lib/decouplio/const/flows.rb +59 -0
- data/lib/decouplio/const/reserved_methods.rb +6 -13
- data/lib/decouplio/const/types.rb +0 -144
- data/lib/decouplio/const/validations/common.rb +10 -0
- data/lib/decouplio/const/validations/octo.rb +16 -0
- data/lib/decouplio/const/validations/resq.rb +12 -1
- data/lib/decouplio/ctx.rb +13 -0
- data/lib/decouplio/default_meta_store.rb +2 -4
- data/lib/decouplio/errors/action_class_error.rb +0 -3
- data/lib/decouplio/errors/base_error.rb +0 -3
- data/lib/decouplio/errors/execution_error.rb +0 -2
- data/lib/decouplio/errors/extra_key_for_pass_error.rb +0 -3
- data/lib/decouplio/errors/fail_can_not_be_first_step_error.rb +0 -3
- data/lib/decouplio/errors/fail_controversial_keys_error.rb +0 -3
- data/lib/decouplio/errors/fail_finish_him_error.rb +0 -3
- data/lib/decouplio/errors/invalid_error_class_error.rb +0 -3
- data/lib/decouplio/errors/invalid_options_for_resq_step.rb +18 -0
- data/lib/decouplio/errors/invalid_wrap_name_error.rb +0 -3
- data/lib/decouplio/errors/logic_is_not_defined_error.rb +0 -3
- data/lib/decouplio/errors/logic_redefinition_error.rb +0 -3
- data/lib/decouplio/errors/octo_block_is_not_defined_error.rb +0 -3
- data/lib/decouplio/errors/octo_case_is_not_defined_error.rb +19 -0
- data/lib/decouplio/errors/octo_controversial_keys_error.rb +0 -3
- data/lib/decouplio/errors/{error_store_error.rb → octo_finish_him_is_not_allowed_error.rb} +2 -4
- data/lib/decouplio/errors/options_validation_error.rb +13 -1
- data/lib/decouplio/errors/palp_block_is_not_defined_error.rb +0 -3
- data/lib/decouplio/errors/palp_validation_error.rb +0 -3
- data/lib/decouplio/errors/pass_controversial_keys_error.rb +0 -3
- data/lib/decouplio/errors/pass_finish_him_error.rb +0 -3
- data/lib/decouplio/errors/required_options_is_missing_for_octo_error.rb +0 -3
- data/lib/decouplio/errors/resq_definition_error.rb +0 -3
- data/lib/decouplio/errors/resq_error_class_error.rb +0 -3
- data/lib/decouplio/errors/resq_handler_method_error.rb +0 -3
- data/lib/decouplio/errors/step_controversial_keys_error.rb +0 -3
- data/lib/decouplio/errors/step_definition_error.rb +17 -0
- data/lib/decouplio/errors/step_finish_him_error.rb +0 -3
- data/lib/decouplio/errors/step_is_not_defined_for_fail_error.rb +0 -3
- data/lib/decouplio/errors/step_is_not_defined_for_pass_error.rb +0 -4
- data/lib/decouplio/errors/step_is_not_defined_for_step_error.rb +0 -4
- data/lib/decouplio/errors/step_is_not_defined_for_wrap_error.rb +0 -3
- data/lib/decouplio/errors/step_name_error.rb +0 -3
- data/lib/decouplio/errors/wrap_block_is_not_defined_error.rb +0 -3
- data/lib/decouplio/errors/wrap_controversial_keys_error.rb +0 -3
- data/lib/decouplio/errors/wrap_finish_him_error.rb +0 -3
- data/lib/decouplio/errors/wrap_klass_method_error.rb +0 -3
- data/lib/decouplio/graph.rb +9 -0
- data/lib/decouplio/logic_dsl.rb +340 -79
- data/lib/decouplio/new_flow.rb +283 -0
- data/lib/decouplio/octo_hash_case.rb +20 -5
- data/lib/decouplio/octo_options_validator.rb +10 -64
- data/lib/decouplio/step_validator.rb +200 -0
- data/lib/decouplio/steps/base_condition.rb +21 -0
- data/lib/decouplio/steps/base_if_condition.rb +11 -0
- data/lib/decouplio/steps/base_inner_action.rb +42 -0
- data/lib/decouplio/steps/base_octo.rb +26 -0
- data/lib/decouplio/steps/base_resq.rb +25 -28
- data/lib/decouplio/steps/base_resq_with_mapping.rb +34 -0
- data/lib/decouplio/steps/base_service_step.rb +39 -0
- data/lib/decouplio/steps/base_step.rb +33 -6
- data/lib/decouplio/steps/base_unless_condition.rb +11 -0
- data/lib/decouplio/steps/base_wrap.rb +27 -0
- data/lib/decouplio/steps/fail.rb +1 -28
- data/lib/decouplio/steps/if_condition_fail.rb +1 -21
- data/lib/decouplio/steps/if_condition_pass.rb +1 -19
- data/lib/decouplio/steps/inner_action_fail.rb +1 -35
- data/lib/decouplio/steps/inner_action_pass.rb +9 -29
- data/lib/decouplio/steps/inner_action_step.rb +1 -35
- data/lib/decouplio/steps/octo_by_key.rb +31 -0
- data/lib/decouplio/steps/octo_by_method.rb +31 -0
- data/lib/decouplio/steps/pass.rb +5 -26
- data/lib/decouplio/steps/resq_fail.rb +0 -2
- data/lib/decouplio/steps/resq_pass.rb +1 -3
- data/lib/decouplio/steps/resq_with_mapping_fail.rb +8 -0
- data/lib/decouplio/steps/resq_with_mapping_pass.rb +8 -0
- data/lib/decouplio/steps/service_as_fail.rb +8 -0
- data/lib/decouplio/steps/service_as_pass.rb +16 -0
- data/lib/decouplio/steps/service_as_step.rb +8 -0
- data/lib/decouplio/steps/step.rb +0 -24
- data/lib/decouplio/steps/unless_condition_fail.rb +1 -21
- data/lib/decouplio/steps/unless_condition_pass.rb +1 -19
- data/lib/decouplio/steps/wrap.rb +25 -37
- data/lib/decouplio/steps/wrap_with_class.rb +43 -0
- data/lib/decouplio/steps/wrap_with_class_method.rb +45 -0
- data/lib/decouplio/utils/prepare_resq_mappings.rb +17 -0
- data/lib/decouplio/version.rb +1 -1
- data/lib/decouplio.rb +93 -0
- metadata +30 -42
- data/.circleci/config.yml +0 -63
- data/.dockerignore +0 -12
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.rubocop.yml +0 -108
- data/.rubocop_todo.yml +0 -147
- data/.ruby-version +0 -1
- data/.vscode/settings.json +0 -3
- data/Dockerfile +0 -12
- data/Gemfile +0 -8
- data/benchmarks/.ruby-version +0 -1
- data/benchmarks/Dockerfile +0 -12
- data/benchmarks/Gemfile +0 -12
- data/benchmarks/multi_step_benchmark.rb +0 -336
- data/benchmarks/single_step_benchmark.rb +0 -159
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/docker-compose.yml +0 -29
- data/lib/decouplio/composer.rb +0 -615
- data/lib/decouplio/const/colors.rb +0 -25
- data/lib/decouplio/const/results.rb +0 -15
- data/lib/decouplio/const/step_options.rb +0 -16
- data/lib/decouplio/errors/extra_key_for_fail_error.rb +0 -26
- data/lib/decouplio/errors/extra_key_for_octo_error.rb +0 -26
- data/lib/decouplio/errors/extra_key_for_resq_error.rb +0 -29
- data/lib/decouplio/errors/extra_key_for_step_error.rb +0 -23
- data/lib/decouplio/errors/extra_key_for_wrap_error.rb +0 -23
- data/lib/decouplio/errors/palp_is_not_defined_error.rb +0 -26
- data/lib/decouplio/flow.rb +0 -17
- data/lib/decouplio/options_validator.rb +0 -606
- data/lib/decouplio/processor.rb +0 -20
- data/lib/decouplio/steps/octo.rb +0 -27
- data/lib/decouplio/steps/service_fail.rb +0 -41
- data/lib/decouplio/steps/service_pass.rb +0 -41
- data/lib/decouplio/steps/service_step.rb +0 -41
- data/lib/decouplio/steps/shared/fail_resolver.rb +0 -40
- data/lib/decouplio/steps/shared/step_resolver.rb +0 -43
- data/lib/decouplio/validators/condition.rb +0 -49
@@ -1,606 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'const/types'
|
4
|
-
require_relative 'const/reserved_methods'
|
5
|
-
require_relative 'errors/action_class_error'
|
6
|
-
require_relative 'errors/extra_key_for_step_error'
|
7
|
-
require_relative 'errors/extra_key_for_fail_error'
|
8
|
-
require_relative 'errors/extra_key_for_octo_error'
|
9
|
-
require_relative 'errors/extra_key_for_pass_error'
|
10
|
-
require_relative 'errors/extra_key_for_resq_error'
|
11
|
-
require_relative 'errors/extra_key_for_wrap_error'
|
12
|
-
require_relative 'errors/fail_finish_him_error'
|
13
|
-
require_relative 'errors/invalid_error_class_error'
|
14
|
-
require_relative 'errors/invalid_wrap_name_error'
|
15
|
-
require_relative 'errors/pass_finish_him_error'
|
16
|
-
require_relative 'errors/required_options_is_missing_for_octo_error'
|
17
|
-
require_relative 'errors/resq_error_class_error'
|
18
|
-
require_relative 'errors/resq_handler_method_error'
|
19
|
-
require_relative 'errors/step_finish_him_error'
|
20
|
-
require_relative 'errors/step_is_not_defined_for_step_error'
|
21
|
-
require_relative 'errors/step_is_not_defined_for_fail_error'
|
22
|
-
require_relative 'errors/step_is_not_defined_for_pass_error'
|
23
|
-
require_relative 'errors/step_is_not_defined_for_wrap_error'
|
24
|
-
require_relative 'errors/wrap_finish_him_error'
|
25
|
-
require_relative 'errors/wrap_klass_method_error'
|
26
|
-
require_relative 'errors/step_controversial_keys_error'
|
27
|
-
require_relative 'errors/fail_controversial_keys_error'
|
28
|
-
require_relative 'errors/pass_controversial_keys_error'
|
29
|
-
require_relative 'errors/octo_controversial_keys_error'
|
30
|
-
require_relative 'errors/wrap_controversial_keys_error'
|
31
|
-
require_relative 'errors/palp_is_not_defined_error'
|
32
|
-
require_relative 'errors/step_name_error'
|
33
|
-
|
34
|
-
module Decouplio
|
35
|
-
class OptionsValidator
|
36
|
-
def initialize(flow:, palps:, next_steps:, action_class:)
|
37
|
-
@flow = flow
|
38
|
-
@palps = palps
|
39
|
-
@next_steps = next_steps
|
40
|
-
@action_class = action_class
|
41
|
-
end
|
42
|
-
|
43
|
-
def call
|
44
|
-
@flow.each_with_index do |(_step_id, options), index|
|
45
|
-
step_names = extract_step_names(flow: @flow.to_a[index..].to_h.merge(@next_steps || {}))
|
46
|
-
|
47
|
-
validate(options: options, step_names: step_names)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def validate(options:, step_names:)
|
54
|
-
filtered_options = options.reject { |key, _val| OPTIONS_TO_FILTER.include?(key) }
|
55
|
-
|
56
|
-
validate_name(name: options[:name])
|
57
|
-
@palps.each_key do |palp_name|
|
58
|
-
validate_name(name: palp_name)
|
59
|
-
end
|
60
|
-
|
61
|
-
case options[:type]
|
62
|
-
when Decouplio::Const::Types::STEP_TYPE
|
63
|
-
validate_step(options: filtered_options, step_names: step_names)
|
64
|
-
when Decouplio::Const::Types::FAIL_TYPE
|
65
|
-
validate_fail(options: filtered_options, step_names: step_names)
|
66
|
-
when Decouplio::Const::Types::PASS_TYPE
|
67
|
-
validate_pass(options: filtered_options, step_names: step_names)
|
68
|
-
when Decouplio::Const::Types::OCTO_TYPE
|
69
|
-
validate_octo(options: filtered_options, hash_case: options[:hash_case])
|
70
|
-
when Decouplio::Const::Types::WRAP_TYPE
|
71
|
-
validate_wrap(options: filtered_options, name: options[:name], step_names: step_names)
|
72
|
-
when Decouplio::Const::Types::ACTION_TYPE_STEP
|
73
|
-
validate_action(action_class: options[:action], type: Decouplio::Const::Types::STEP_TYPE)
|
74
|
-
validate_step(options: filtered_options, step_names: step_names)
|
75
|
-
when Decouplio::Const::Types::ACTION_TYPE_FAIL
|
76
|
-
validate_action(action_class: options[:action], type: Decouplio::Const::Types::FAIL_TYPE)
|
77
|
-
validate_fail(options: filtered_options, step_names: step_names)
|
78
|
-
when Decouplio::Const::Types::ACTION_TYPE_PASS
|
79
|
-
validate_action(action_class: options[:action], type: Decouplio::Const::Types::PASS_TYPE)
|
80
|
-
validate_pass(options: filtered_options, step_names: step_names)
|
81
|
-
when Decouplio::Const::Types::RESQ_TYPE_STEP,
|
82
|
-
Decouplio::Const::Types::RESQ_TYPE_FAIL,
|
83
|
-
Decouplio::Const::Types::RESQ_TYPE_PASS
|
84
|
-
validate(options: options[:step_to_resq], step_names: step_names)
|
85
|
-
validate_resq(options: filtered_options)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def validate_action(action_class:, type:)
|
90
|
-
return if action_class.is_a?(Class) && action_class <= Decouplio::Action
|
91
|
-
|
92
|
-
raise Decouplio::Errors::ActionClassError.new(
|
93
|
-
step_type: type,
|
94
|
-
errored_option: "action: #{action_class}"
|
95
|
-
)
|
96
|
-
end
|
97
|
-
|
98
|
-
def validate_step(options:, step_names:)
|
99
|
-
check_step_presence_for_step(options: options, step_names: step_names)
|
100
|
-
check_step_controversial_keys(options: options)
|
101
|
-
check_step_extra_keys(options: options)
|
102
|
-
check_step_finish_him(options: options)
|
103
|
-
end
|
104
|
-
|
105
|
-
def validate_fail(options:, step_names:)
|
106
|
-
check_step_presence_for_fail(options: options, step_names: step_names)
|
107
|
-
check_fail_controversial_keys(options: options)
|
108
|
-
check_fail_extra_keys(options: options)
|
109
|
-
check_fail_finish_him(options: options)
|
110
|
-
end
|
111
|
-
|
112
|
-
def validate_pass(options:, step_names:)
|
113
|
-
check_step_presence_for_pass(options: options, step_names: step_names)
|
114
|
-
check_pass_extra_keys(options: options)
|
115
|
-
check_pass_finish_him(options: options)
|
116
|
-
end
|
117
|
-
|
118
|
-
def validate_octo(options:, hash_case:)
|
119
|
-
check_octo_required_keys(options: options)
|
120
|
-
check_octo_extra_keys(options: options)
|
121
|
-
check_octo_palps(hash_case: hash_case)
|
122
|
-
end
|
123
|
-
|
124
|
-
def validate_wrap(options:, name:, step_names:)
|
125
|
-
check_wrap_name(name: name)
|
126
|
-
check_wrap_controversial_keys(options: options)
|
127
|
-
check_step_presence_for_wrap(options: options, step_names: step_names)
|
128
|
-
check_wrap_extra_keys(options: options)
|
129
|
-
check_wrap_finish_him(options: options)
|
130
|
-
check_wrap_klass_method_presence(options: options)
|
131
|
-
end
|
132
|
-
|
133
|
-
def validate_resq(options:)
|
134
|
-
options[:handler_hash].each_value do |error_handler_name|
|
135
|
-
validate_name(name: error_handler_name)
|
136
|
-
end
|
137
|
-
check_resq_extra_keys(options: options)
|
138
|
-
check_resq_handler_method_is_a_symbol(options: options)
|
139
|
-
check_resq_error_classes(options: options)
|
140
|
-
check_resq_exception_classes_inheritance(options: options)
|
141
|
-
end
|
142
|
-
|
143
|
-
def validate_name(name:)
|
144
|
-
return unless Decouplio::Const::ReservedMethods::NAMES.include?(name)
|
145
|
-
|
146
|
-
raise Decouplio::Errors::StepNameError.new(
|
147
|
-
errored_option: name
|
148
|
-
)
|
149
|
-
end
|
150
|
-
|
151
|
-
def check_step_presence_for_step(options:, step_names:)
|
152
|
-
options.slice(*STEP_CHECK_STEP_PRESENCE).each do |option_key, option_value|
|
153
|
-
next if %i[on_success on_failure on_error].include?(option_key) &&
|
154
|
-
STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
|
155
|
-
|
156
|
-
next if step_names.keys.include?(option_value)
|
157
|
-
|
158
|
-
raise Decouplio::Errors::StepIsNotDefinedForStepError.new(
|
159
|
-
errored_option: options.slice(option_key).to_s,
|
160
|
-
details: option_value
|
161
|
-
)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
def check_step_presence_for_pass(options:, step_names:)
|
166
|
-
options.slice(*PASS_CHECK_STEP_PRESENCE).each do |option_key, option_value|
|
167
|
-
next if %i[on_error].include?(option_key) &&
|
168
|
-
STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
|
169
|
-
|
170
|
-
next if step_names.keys.include?(option_value)
|
171
|
-
|
172
|
-
raise Decouplio::Errors::StepIsNotDefinedForPassError.new(
|
173
|
-
errored_option: options.slice(option_key).to_s,
|
174
|
-
details: option_value
|
175
|
-
)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
def check_step_presence_for_fail(options:, step_names:)
|
180
|
-
options.slice(*STEP_CHECK_STEP_PRESENCE).each do |option_key, option_value|
|
181
|
-
next if %i[on_success on_failure on_error].include?(option_key) &&
|
182
|
-
STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
|
183
|
-
|
184
|
-
next if step_names.keys.include?(option_value)
|
185
|
-
|
186
|
-
raise Decouplio::Errors::StepIsNotDefinedForFailError.new(
|
187
|
-
errored_option: options.slice(option_key).to_s,
|
188
|
-
details: option_value
|
189
|
-
)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def check_step_presence_for_wrap(options:, step_names:)
|
194
|
-
options.slice(*WRAP_CHECK_STEP_PRESENCE).each do |option_key, option_value|
|
195
|
-
next if %i[on_success on_failure on_error].include?(option_key) &&
|
196
|
-
STEP_ALLOWED_ON_S_ON_F_VALUES.include?(option_value)
|
197
|
-
|
198
|
-
next if step_names.keys.include?(option_value)
|
199
|
-
|
200
|
-
raise Decouplio::Errors::StepIsNotDefinedForWrapError.new(
|
201
|
-
errored_option: options.slice(option_key).to_s,
|
202
|
-
details: option_value
|
203
|
-
)
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
def check_step_extra_keys(options:)
|
208
|
-
extra_keys = options.keys - STEP_ALLOWED_OPTIONS
|
209
|
-
|
210
|
-
if extra_keys.size.positive?
|
211
|
-
raise Decouplio::Errors::ExtraKeyForStepError.new(
|
212
|
-
errored_option: options.slice(*extra_keys).to_s
|
213
|
-
)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
def check_step_controversial_keys(options:)
|
218
|
-
on_success_on_failure = options.slice(:on_success, :on_failure)
|
219
|
-
finish_him = options.slice(:finish_him)
|
220
|
-
|
221
|
-
if !on_success_on_failure.empty? && !finish_him.empty?
|
222
|
-
raise Decouplio::Errors::StepControversialKeysError.new(
|
223
|
-
errored_option: on_success_on_failure.merge(finish_him).to_s,
|
224
|
-
details: [on_success_on_failure.keys.join(', '), :finish_him]
|
225
|
-
)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
def check_fail_extra_keys(options:)
|
230
|
-
extra_keys = options.keys - FAIL_ALLOWED_OPTIONS
|
231
|
-
|
232
|
-
return if extra_keys.size.zero?
|
233
|
-
|
234
|
-
raise Decouplio::Errors::ExtraKeyForFailError.new(
|
235
|
-
errored_option: options.slice(*extra_keys).to_s,
|
236
|
-
details: extra_keys.join(', ')
|
237
|
-
)
|
238
|
-
end
|
239
|
-
|
240
|
-
def check_fail_controversial_keys(options:)
|
241
|
-
on_success_on_failure = options.slice(:on_success, :on_failure)
|
242
|
-
finish_him = options.slice(:finish_him)
|
243
|
-
|
244
|
-
if !on_success_on_failure.empty? && !finish_him.empty?
|
245
|
-
raise Decouplio::Errors::FailControversialKeysError.new(
|
246
|
-
errored_option: on_success_on_failure.merge(finish_him).to_s,
|
247
|
-
details: [on_success_on_failure.keys.join(', '), :finish_him]
|
248
|
-
)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
def check_pass_extra_keys(options:)
|
253
|
-
extra_keys = options.keys - PASS_ALLOWED_OPTIONS
|
254
|
-
|
255
|
-
if extra_keys.size.positive?
|
256
|
-
raise Decouplio::Errors::ExtraKeyForPassError.new(
|
257
|
-
errored_option: options.slice(*extra_keys).to_s,
|
258
|
-
details: extra_keys.join(', ')
|
259
|
-
)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
def check_octo_extra_keys(options:)
|
264
|
-
extra_keys = options.keys - OCTO_ALLOWED_OPTIONS
|
265
|
-
|
266
|
-
if extra_keys.size.positive?
|
267
|
-
raise Decouplio::Errors::ExtraKeyForOctoError.new(
|
268
|
-
errored_option: options.slice(*extra_keys).to_s,
|
269
|
-
details: extra_keys.join(', ')
|
270
|
-
)
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
def check_wrap_extra_keys(options:)
|
275
|
-
extra_keys = options.keys - WRAP_ALLOWED_OPTIONS
|
276
|
-
|
277
|
-
if extra_keys.size.positive?
|
278
|
-
raise Decouplio::Errors::ExtraKeyForWrapError.new(
|
279
|
-
errored_option: options.slice(*extra_keys).to_s
|
280
|
-
)
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
def check_wrap_controversial_keys(options:)
|
285
|
-
on_success_on_failure = options.slice(:on_success, :on_failure)
|
286
|
-
finish_him = options.slice(:finish_him)
|
287
|
-
|
288
|
-
if !on_success_on_failure.empty? && !finish_him.empty?
|
289
|
-
raise Decouplio::Errors::WrapControversialKeysError.new(
|
290
|
-
errored_option: on_success_on_failure.merge(finish_him).to_s,
|
291
|
-
details: [on_success_on_failure.keys.join(', '), :finish_him]
|
292
|
-
)
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
def check_octo_palps(hash_case:)
|
297
|
-
hash_casse_palps = hash_case.map { |_octo_key, hash| hash[:palp] }.compact
|
298
|
-
undefined_palps = hash_casse_palps - @palps.keys
|
299
|
-
|
300
|
-
return if undefined_palps.empty?
|
301
|
-
|
302
|
-
errored_options = hash_case.select do |_key, val|
|
303
|
-
undefined_palps.include?(val[:palp])
|
304
|
-
end
|
305
|
-
errored_options = errored_options.map do |key, val|
|
306
|
-
"\"on :#{key}, palp: :#{val[:palp]}\""
|
307
|
-
end
|
308
|
-
|
309
|
-
raise Decouplio::Errors::PalpIsNotDefinedError.new(
|
310
|
-
errored_option: errored_options,
|
311
|
-
details: undefined_palps
|
312
|
-
)
|
313
|
-
end
|
314
|
-
|
315
|
-
def check_octo_required_keys(options:)
|
316
|
-
if (OCTO_REQUIRED_KEYS - options.keys).size.zero?
|
317
|
-
if options.keys.sort == OCTO_REQUIRED_KEYS.sort
|
318
|
-
raise Decouplio::Errors::OctoControversialKeysError.new(
|
319
|
-
errored_option: options.slice(*OCTO_REQUIRED_KEYS),
|
320
|
-
details: OCTO_REQUIRED_KEYS
|
321
|
-
)
|
322
|
-
end
|
323
|
-
else
|
324
|
-
return if options.slice(*OCTO_REQUIRED_KEYS).size == 1
|
325
|
-
|
326
|
-
raise Decouplio::Errors::RequiredOptionsIsMissingForOctoError.new(
|
327
|
-
details: OCTO_REQUIRED_KEYS.join(', ')
|
328
|
-
)
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
def check_step_finish_him(options:)
|
333
|
-
finish_him_value = options.dig(:finish_him)
|
334
|
-
|
335
|
-
return unless finish_him_value && options.key?(:finish_him)
|
336
|
-
|
337
|
-
unless ALLOWED_STEP_FINISH_HIM_VALUES.include?(finish_him_value)
|
338
|
-
raise Decouplio::Errors::StepFinishHimError.new(
|
339
|
-
errored_option: options.slice(:finish_him).to_s,
|
340
|
-
details: finish_him_value
|
341
|
-
)
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
def check_fail_finish_him(options:)
|
346
|
-
finish_him_value = options.dig(:finish_him)
|
347
|
-
|
348
|
-
return unless options.key?(:finish_him)
|
349
|
-
|
350
|
-
return if ALLOWED_FAIL_FINISH_HIM_VALUES.include?(finish_him_value)
|
351
|
-
|
352
|
-
raise Decouplio::Errors::FailFinishHimError.new(
|
353
|
-
errored_option: options.slice(:finish_him).to_s,
|
354
|
-
details: finish_him_value
|
355
|
-
)
|
356
|
-
end
|
357
|
-
|
358
|
-
def check_pass_finish_him(options:)
|
359
|
-
finish_him_value = options.dig(:finish_him)
|
360
|
-
|
361
|
-
return unless finish_him_value && options.key?(:finish_him)
|
362
|
-
|
363
|
-
unless ALLOWED_PASS_FINISH_HIM_VALUES.include?(finish_him_value)
|
364
|
-
raise Decouplio::Errors::PassFinishHimError.new(
|
365
|
-
errored_option: options.slice(:finish_him).to_s,
|
366
|
-
details: finish_him_value
|
367
|
-
)
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
def check_wrap_finish_him(options:)
|
372
|
-
finish_him_value = options.dig(:finish_him)
|
373
|
-
|
374
|
-
return unless finish_him_value && options.key?(:finish_him)
|
375
|
-
|
376
|
-
unless ALLOWED_WRAP_FINISH_HIM_VALUES.include?(finish_him_value)
|
377
|
-
raise Decouplio::Errors::WrapFinishHimError.new(
|
378
|
-
errored_option: options.slice(:finish_him).to_s,
|
379
|
-
details: finish_him_value
|
380
|
-
)
|
381
|
-
end
|
382
|
-
end
|
383
|
-
|
384
|
-
def check_wrap_klass_method_presence(options:)
|
385
|
-
klass_method_options = options.slice(:klass, :method)
|
386
|
-
klass_method_options_size = klass_method_options.size
|
387
|
-
|
388
|
-
return if klass_method_options_size.zero? || klass_method_options_size == 2
|
389
|
-
|
390
|
-
raise Decouplio::Errors::WrapKlassMethodError.new(
|
391
|
-
errored_option: klass_method_options.to_s
|
392
|
-
)
|
393
|
-
end
|
394
|
-
|
395
|
-
def check_wrap_name(name:)
|
396
|
-
return if name.is_a?(Symbol)
|
397
|
-
|
398
|
-
raise Decouplio::Errors::InvalidWrapNameError
|
399
|
-
end
|
400
|
-
|
401
|
-
def check_resq_extra_keys(options:)
|
402
|
-
extra_options = options[:handler_hash].values.select do |option|
|
403
|
-
RESQ_NOT_ALLOWED_OPTIONS.include?(option)
|
404
|
-
end
|
405
|
-
|
406
|
-
return if extra_options.empty?
|
407
|
-
|
408
|
-
raise Decouplio::Errors::ExtraKeyForResqError.new(
|
409
|
-
errored_option: extra_options.join(', ').to_s,
|
410
|
-
details: extra_options.join(', ').to_s
|
411
|
-
)
|
412
|
-
end
|
413
|
-
|
414
|
-
def check_resq_handler_method_is_a_symbol(options:)
|
415
|
-
options[:handler_hash].values.uniq.each do |handler_method|
|
416
|
-
next if handler_method.is_a?(Symbol)
|
417
|
-
|
418
|
-
raise Decouplio::Errors::ResqHandlerMethodError.new(
|
419
|
-
errored_option: handler_method.to_s
|
420
|
-
)
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
def check_resq_error_classes(options:)
|
425
|
-
options[:handler_hash].each_key do |error_class|
|
426
|
-
next if error_class.is_a?(Class)
|
427
|
-
|
428
|
-
raise Decouplio::Errors::ResqErrorClassError.new(
|
429
|
-
errored_option: error_class.to_s,
|
430
|
-
details: options[:handler_hash][error_class].to_s
|
431
|
-
)
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
|
-
def check_resq_exception_classes_inheritance(options:)
|
436
|
-
options[:handler_hash].each_key do |klass|
|
437
|
-
next if klass < Exception
|
438
|
-
|
439
|
-
raise Decouplio::Errors::InvalidErrorClassError.new(
|
440
|
-
errored_option: klass.to_s,
|
441
|
-
details: klass.to_s
|
442
|
-
)
|
443
|
-
end
|
444
|
-
end
|
445
|
-
|
446
|
-
def extract_step_names(flow:)
|
447
|
-
flow.to_h do |_step_id, stp|
|
448
|
-
[stp[:name], stp[:type]]
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
OPTIONS_TO_FILTER = %i[
|
453
|
-
step_id
|
454
|
-
flow
|
455
|
-
name
|
456
|
-
type
|
457
|
-
hash_case
|
458
|
-
wrap_flow
|
459
|
-
step_to_resq
|
460
|
-
_args
|
461
|
-
].freeze
|
462
|
-
|
463
|
-
# *************************************************
|
464
|
-
# STEP
|
465
|
-
# *************************************************
|
466
|
-
|
467
|
-
STEP_CHECK_METHOD_EXISTENCE_OPTIONS = %i[
|
468
|
-
on_success
|
469
|
-
on_failure
|
470
|
-
on_error
|
471
|
-
if
|
472
|
-
unless
|
473
|
-
].freeze
|
474
|
-
STEP_CHECK_STEP_PRESENCE = %i[
|
475
|
-
on_success
|
476
|
-
on_failure
|
477
|
-
on_error
|
478
|
-
].freeze
|
479
|
-
STEP_ALLOWED_ON_S_ON_F_VALUES = [
|
480
|
-
Decouplio::Const::Results::STEP_PASS,
|
481
|
-
Decouplio::Const::Results::STEP_FAIL,
|
482
|
-
Decouplio::Const::Results::FINISH_HIM
|
483
|
-
].freeze
|
484
|
-
STEP_ALLOWED_OPTIONS = %i[
|
485
|
-
on_success
|
486
|
-
on_failure
|
487
|
-
on_error
|
488
|
-
finish_him
|
489
|
-
if
|
490
|
-
unless
|
491
|
-
action
|
492
|
-
].freeze
|
493
|
-
ALLOWED_STEP_FINISH_HIM_VALUES = %i[
|
494
|
-
on_success
|
495
|
-
on_failure
|
496
|
-
on_error
|
497
|
-
].freeze
|
498
|
-
|
499
|
-
# *************************************************
|
500
|
-
# FAIL
|
501
|
-
# *************************************************
|
502
|
-
|
503
|
-
FAIL_CHECK_METHOD_EXISTENCE_OPTIONS = %i[
|
504
|
-
if
|
505
|
-
unless
|
506
|
-
].freeze
|
507
|
-
FAIL_ALLOWED_OPTIONS = %i[
|
508
|
-
on_success
|
509
|
-
on_failure
|
510
|
-
on_error
|
511
|
-
finish_him
|
512
|
-
if
|
513
|
-
unless
|
514
|
-
action
|
515
|
-
].freeze
|
516
|
-
ALLOWED_FAIL_FINISH_HIM_VALUES = [true, :on_success, :on_failure, :on_error].freeze
|
517
|
-
|
518
|
-
# *************************************************
|
519
|
-
# PASS
|
520
|
-
# *************************************************
|
521
|
-
|
522
|
-
PASS_ALLOWED_OPTIONS = %i[
|
523
|
-
finish_him
|
524
|
-
if
|
525
|
-
unless
|
526
|
-
action
|
527
|
-
on_error
|
528
|
-
].freeze
|
529
|
-
|
530
|
-
PASS_CHECK_METHOD_EXISTENCE_OPTIONS = %i[
|
531
|
-
if
|
532
|
-
unless
|
533
|
-
].freeze
|
534
|
-
PASS_CHECK_STEP_PRESENCE = %i[
|
535
|
-
on_error
|
536
|
-
].freeze
|
537
|
-
ALLOWED_PASS_FINISH_HIM_VALUES = [true, :on_error].freeze
|
538
|
-
|
539
|
-
# *************************************************
|
540
|
-
# OCTO
|
541
|
-
# *************************************************
|
542
|
-
|
543
|
-
OCTO_ALLOWED_OPTIONS = %i[
|
544
|
-
ctx_key
|
545
|
-
method
|
546
|
-
if
|
547
|
-
unless
|
548
|
-
].freeze
|
549
|
-
OCTO_CHECK_METHOD_EXISTENCE_OPTIONS = %i[
|
550
|
-
if
|
551
|
-
unless
|
552
|
-
].freeze
|
553
|
-
OCTO_REQUIRED_KEYS = %i[
|
554
|
-
ctx_key
|
555
|
-
method
|
556
|
-
].freeze
|
557
|
-
|
558
|
-
# *************************************************
|
559
|
-
# WRAP
|
560
|
-
# *************************************************
|
561
|
-
|
562
|
-
WRAP_CHECK_METHOD_EXISTENCE_OPTIONS = %i[
|
563
|
-
on_success
|
564
|
-
on_failure
|
565
|
-
on_error
|
566
|
-
if
|
567
|
-
unless
|
568
|
-
].freeze
|
569
|
-
WRAP_CHECK_STEP_PRESENCE = %i[
|
570
|
-
on_success
|
571
|
-
on_failure
|
572
|
-
on_error
|
573
|
-
].freeze
|
574
|
-
WRAP_ALLOWED_OPTIONS = %i[
|
575
|
-
on_success
|
576
|
-
on_failure
|
577
|
-
on_error
|
578
|
-
finish_him
|
579
|
-
if
|
580
|
-
unless
|
581
|
-
klass
|
582
|
-
method
|
583
|
-
wrap_block
|
584
|
-
].freeze
|
585
|
-
ALLOWED_WRAP_FINISH_HIM_VALUES = %i[
|
586
|
-
on_success
|
587
|
-
on_failure
|
588
|
-
on_error
|
589
|
-
].freeze
|
590
|
-
|
591
|
-
# *************************************************
|
592
|
-
# RESQ
|
593
|
-
# *************************************************
|
594
|
-
|
595
|
-
RESQ_NOT_ALLOWED_OPTIONS = %i[
|
596
|
-
on_success
|
597
|
-
on_failure
|
598
|
-
on_error
|
599
|
-
finish_him
|
600
|
-
if
|
601
|
-
unless
|
602
|
-
klass
|
603
|
-
method
|
604
|
-
].freeze
|
605
|
-
end
|
606
|
-
end
|
data/lib/decouplio/processor.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decouplio
|
4
|
-
class Processor
|
5
|
-
class << self
|
6
|
-
def call(first_step:, steps_pool:, steps_flow:, instance:)
|
7
|
-
process(first_step, instance, steps_pool, steps_flow)
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def process(next_step_name, instance, steps_pool, steps_flow)
|
13
|
-
while next_step_name
|
14
|
-
result = steps_pool[next_step_name].process(instance: instance)
|
15
|
-
next_step_name = steps_flow[next_step_name][result]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/decouplio/steps/octo.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'base_step'
|
4
|
-
|
5
|
-
module Decouplio
|
6
|
-
module Steps
|
7
|
-
class Octo < BaseStep
|
8
|
-
attr_accessor :hash_case
|
9
|
-
|
10
|
-
def initialize(name:, ctx_key:, method:)
|
11
|
-
super()
|
12
|
-
@name = name
|
13
|
-
@ctx_key = ctx_key
|
14
|
-
@method = method
|
15
|
-
end
|
16
|
-
|
17
|
-
def process(instance:)
|
18
|
-
instance.append_railway_flow(@name)
|
19
|
-
if @method
|
20
|
-
instance.send(@method, **instance.ctx)
|
21
|
-
else
|
22
|
-
instance[@ctx_key]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'base_step'
|
4
|
-
require_relative 'shared/fail_resolver'
|
5
|
-
|
6
|
-
module Decouplio
|
7
|
-
module Steps
|
8
|
-
class ServiceFail < Decouplio::Steps::BaseStep
|
9
|
-
def initialize(name:, service:, args:, on_success_type:, on_failure_type:)
|
10
|
-
super()
|
11
|
-
@name = name
|
12
|
-
@service = service
|
13
|
-
@args = args
|
14
|
-
@on_success_type = on_success_type
|
15
|
-
@on_failure_type = on_failure_type
|
16
|
-
end
|
17
|
-
|
18
|
-
def process(instance:)
|
19
|
-
instance.append_railway_flow(@name)
|
20
|
-
result = @service.call(
|
21
|
-
ctx: instance.ctx,
|
22
|
-
ms: instance.meta_store,
|
23
|
-
**@args
|
24
|
-
)
|
25
|
-
|
26
|
-
resolve(result: result, instance: instance)
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def resolve(result:, instance:)
|
32
|
-
Decouplio::Steps::Shared::FailResolver.call(
|
33
|
-
instance: instance,
|
34
|
-
result: result,
|
35
|
-
on_success_type: @on_success_type,
|
36
|
-
on_failure_type: @on_failure_type
|
37
|
-
)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|