decouplio 1.0.0alpha7 → 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 +34 -74
- data/lib/decouplio/action_state_printer.rb +34 -0
- data/lib/decouplio/const/flows.rb +59 -0
- data/lib/decouplio/const/reserved_methods.rb +6 -13
- data/lib/decouplio/const/types.rb +1 -165
- 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 +37 -0
- 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 +337 -107
- 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 -33
- data/lib/decouplio/steps/inner_action_pass.rb +12 -30
- data/lib/decouplio/steps/inner_action_step.rb +1 -33
- 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 +32 -55
- data/.circleci/config.yml +0 -63
- data/.dockerignore +0 -12
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.rubocop.yml +0 -116
- 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 -691
- data/lib/decouplio/const/colors.rb +0 -25
- data/lib/decouplio/const/doby_aide_options.rb +0 -16
- data/lib/decouplio/const/results.rb +0 -15
- data/lib/decouplio/const/step_options.rb +0 -16
- data/lib/decouplio/const/validations/aide.rb +0 -38
- data/lib/decouplio/const/validations/doby.rb +0 -36
- data/lib/decouplio/default_error_handler.rb +0 -39
- data/lib/decouplio/errors/aide_can_not_be_first_step_error.rb +0 -18
- data/lib/decouplio/errors/aide_controversial_keys_error.rb +0 -26
- data/lib/decouplio/errors/aide_finish_him_error.rb +0 -26
- data/lib/decouplio/errors/doby_controversial_keys_error.rb +0 -26
- data/lib/decouplio/errors/doby_finish_him_error.rb +0 -26
- 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/errors/step_is_not_defined_for_aide_error.rb +0 -26
- data/lib/decouplio/errors/step_is_not_defined_for_doby_error.rb +0 -27
- data/lib/decouplio/flow.rb +0 -17
- data/lib/decouplio/options_validator.rb +0 -716
- data/lib/decouplio/processor.rb +0 -20
- data/lib/decouplio/steps/aide.rb +0 -37
- data/lib/decouplio/steps/doby.rb +0 -37
- 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 -59
data/lib/decouplio/composer.rb
DELETED
@@ -1,691 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'action'
|
4
|
-
require_relative 'const/types'
|
5
|
-
require_relative 'const/results'
|
6
|
-
require_relative 'steps/step'
|
7
|
-
require_relative 'steps/fail'
|
8
|
-
require_relative 'steps/pass'
|
9
|
-
require_relative 'steps/wrap'
|
10
|
-
require_relative 'steps/octo'
|
11
|
-
require_relative 'steps/resq_pass'
|
12
|
-
require_relative 'steps/resq_fail'
|
13
|
-
require_relative 'steps/if_condition_pass'
|
14
|
-
require_relative 'steps/if_condition_fail'
|
15
|
-
require_relative 'steps/unless_condition_pass'
|
16
|
-
require_relative 'steps/unless_condition_fail'
|
17
|
-
require_relative 'steps/inner_action_step'
|
18
|
-
require_relative 'steps/inner_action_fail'
|
19
|
-
require_relative 'steps/inner_action_pass'
|
20
|
-
require_relative 'steps/service_step'
|
21
|
-
require_relative 'steps/service_fail'
|
22
|
-
require_relative 'steps/service_pass'
|
23
|
-
require_relative 'steps/doby'
|
24
|
-
require_relative 'steps/aide'
|
25
|
-
require_relative 'options_validator'
|
26
|
-
require_relative 'validators/condition'
|
27
|
-
|
28
|
-
module Decouplio
|
29
|
-
class Composer
|
30
|
-
class << self
|
31
|
-
def compose(logic_container_raw_data:, action_class:, palp_prefix: :root, parent_flow: {}, next_steps: nil)
|
32
|
-
flow = logic_container_raw_data.steps
|
33
|
-
palps = logic_container_raw_data.palps
|
34
|
-
|
35
|
-
steps_pool = {}
|
36
|
-
steps_flow = {}
|
37
|
-
|
38
|
-
flow = prepare_raw_data(flow, palp_prefix, action_class)
|
39
|
-
validate_flow(flow, palps, next_steps, action_class)
|
40
|
-
flow = compose_flow(flow, palps, next_steps, action_class, parent_flow)
|
41
|
-
|
42
|
-
flow.each do |step_id, stp|
|
43
|
-
steps_flow[step_id] = stp[:flow]
|
44
|
-
steps_flow.merge!(extract_palp_flow(stp))
|
45
|
-
steps_pool[step_id] = create_step_instance(stp, flow)
|
46
|
-
steps_pool.merge!(extract_palp_pool(stp))
|
47
|
-
end
|
48
|
-
|
49
|
-
{
|
50
|
-
first_step: steps_pool.keys.first,
|
51
|
-
steps_pool: steps_pool.freeze,
|
52
|
-
steps_flow: steps_flow.freeze
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def prepare_raw_data(flow, palp_prefix, action_class)
|
59
|
-
flow = flow.map do |stp|
|
60
|
-
stp[:step_id] = random_id(name: stp[:name], palp_prefix: palp_prefix, flow: flow)
|
61
|
-
stp[:flow] = {}
|
62
|
-
stp = compose_resq(stp, palp_prefix, flow)
|
63
|
-
stp = compose_action(stp)
|
64
|
-
stp = compose_wrap(stp, action_class)
|
65
|
-
condition = compose_condition(stp, palp_prefix, flow)
|
66
|
-
|
67
|
-
[condition, stp].compact
|
68
|
-
end.flatten
|
69
|
-
|
70
|
-
flow.to_h do |stp|
|
71
|
-
[stp[:step_id], stp]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def validate_flow(flow, palps, next_steps, action_class)
|
76
|
-
OptionsValidator.new(
|
77
|
-
flow: flow,
|
78
|
-
palps: palps,
|
79
|
-
next_steps: next_steps,
|
80
|
-
action_class: action_class
|
81
|
-
).call
|
82
|
-
end
|
83
|
-
|
84
|
-
def extract_palp_flow(stp)
|
85
|
-
return {} unless stp[:type] == Decouplio::Const::Types::OCTO_TYPE
|
86
|
-
|
87
|
-
stp[:hash_case].values.map { |composer_output| composer_output[:steps_flow] }.reduce({}, :merge)
|
88
|
-
end
|
89
|
-
|
90
|
-
def extract_palp_pool(stp)
|
91
|
-
return {} unless stp[:type] == Decouplio::Const::Types::OCTO_TYPE
|
92
|
-
|
93
|
-
stp[:hash_case].values.map { |composer_output| composer_output[:steps_pool] }.reduce({}, :merge)
|
94
|
-
end
|
95
|
-
|
96
|
-
def create_step_instance(stp, flow)
|
97
|
-
case stp[:type]
|
98
|
-
when Decouplio::Const::Types::STEP_TYPE
|
99
|
-
create_step(stp, flow)
|
100
|
-
when Decouplio::Const::Types::FAIL_TYPE
|
101
|
-
create_fail(stp, flow)
|
102
|
-
when Decouplio::Const::Types::PASS_TYPE
|
103
|
-
create_pass(stp, flow)
|
104
|
-
when Decouplio::Const::Types::IF_TYPE_PASS
|
105
|
-
create_if_condition_pass(stp)
|
106
|
-
when Decouplio::Const::Types::IF_TYPE_FAIL
|
107
|
-
create_if_condition_fail(stp)
|
108
|
-
when Decouplio::Const::Types::UNLESS_TYPE_PASS
|
109
|
-
create_unless_condition_pass(stp)
|
110
|
-
when Decouplio::Const::Types::UNLESS_TYPE_FAIL
|
111
|
-
create_unless_condition_fail(stp)
|
112
|
-
when Decouplio::Const::Types::OCTO_TYPE
|
113
|
-
create_octo(stp)
|
114
|
-
when Decouplio::Const::Types::WRAP_TYPE
|
115
|
-
create_wrap(flow, stp)
|
116
|
-
when Decouplio::Const::Types::RESQ_TYPE_STEP, Decouplio::Const::Types::RESQ_TYPE_PASS
|
117
|
-
create_resq_pass(stp, flow)
|
118
|
-
when Decouplio::Const::Types::RESQ_TYPE_FAIL
|
119
|
-
create_resq_fail(stp, flow)
|
120
|
-
when Decouplio::Const::Types::ACTION_TYPE_STEP
|
121
|
-
create_inner_action_step(stp, flow)
|
122
|
-
when Decouplio::Const::Types::ACTION_TYPE_FAIL
|
123
|
-
create_inner_action_fail(stp, flow)
|
124
|
-
when Decouplio::Const::Types::ACTION_TYPE_PASS
|
125
|
-
create_inner_action_pass(stp, flow)
|
126
|
-
when Decouplio::Const::Types::SERVICE_TYPE_STEP
|
127
|
-
create_inner_service_step(stp, flow)
|
128
|
-
when Decouplio::Const::Types::SERVICE_TYPE_FAIL
|
129
|
-
create_inner_service_fail(stp, flow)
|
130
|
-
when Decouplio::Const::Types::SERVICE_TYPE_PASS
|
131
|
-
create_inner_service_pass(stp, flow)
|
132
|
-
when Decouplio::Const::Types::DOBY_TYPE
|
133
|
-
create_doby(stp, flow)
|
134
|
-
when Decouplio::Const::Types::AIDE_TYPE
|
135
|
-
create_aide(stp, flow)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def create_step(stp, flow)
|
140
|
-
Decouplio::Steps::Step.new(
|
141
|
-
name: stp[:name],
|
142
|
-
on_success_type: success_type(flow, stp),
|
143
|
-
on_failure_type: failure_type(flow, stp)
|
144
|
-
)
|
145
|
-
end
|
146
|
-
|
147
|
-
def create_fail(stp, flow)
|
148
|
-
Decouplio::Steps::Fail.new(
|
149
|
-
name: stp[:name],
|
150
|
-
on_success_type: success_type(flow, stp),
|
151
|
-
on_failure_type: failure_type(flow, stp)
|
152
|
-
)
|
153
|
-
end
|
154
|
-
|
155
|
-
def create_pass(stp, flow)
|
156
|
-
Decouplio::Steps::Pass.new(
|
157
|
-
name: stp[:name],
|
158
|
-
on_success_type: success_type(flow, stp)
|
159
|
-
)
|
160
|
-
end
|
161
|
-
|
162
|
-
def create_if_condition_pass(stp)
|
163
|
-
Decouplio::Steps::IfConditionPass.new(
|
164
|
-
name: stp[:name]
|
165
|
-
)
|
166
|
-
end
|
167
|
-
|
168
|
-
def create_if_condition_fail(stp)
|
169
|
-
Decouplio::Steps::IfConditionFail.new(
|
170
|
-
name: stp[:name]
|
171
|
-
)
|
172
|
-
end
|
173
|
-
|
174
|
-
def create_unless_condition_pass(stp)
|
175
|
-
Decouplio::Steps::UnlessConditionPass.new(
|
176
|
-
name: stp[:name]
|
177
|
-
)
|
178
|
-
end
|
179
|
-
|
180
|
-
def create_unless_condition_fail(stp)
|
181
|
-
Decouplio::Steps::UnlessConditionFail.new(
|
182
|
-
name: stp[:name]
|
183
|
-
)
|
184
|
-
end
|
185
|
-
|
186
|
-
def create_octo(stp)
|
187
|
-
Decouplio::Steps::Octo.new(
|
188
|
-
name: stp[:name],
|
189
|
-
ctx_key: stp[:ctx_key],
|
190
|
-
method: stp[:method]
|
191
|
-
)
|
192
|
-
end
|
193
|
-
|
194
|
-
def create_wrap(flow, stp)
|
195
|
-
Decouplio::Steps::Wrap.new(
|
196
|
-
name: stp[:name],
|
197
|
-
klass: stp[:klass],
|
198
|
-
method: stp[:method],
|
199
|
-
wrap_flow: stp[:wrap_flow],
|
200
|
-
on_success_type: success_type(flow, stp),
|
201
|
-
on_failure_type: failure_type(flow, stp)
|
202
|
-
)
|
203
|
-
end
|
204
|
-
|
205
|
-
def create_resq_pass(stp, flow)
|
206
|
-
Decouplio::Steps::ResqPass.new(
|
207
|
-
handler_hash: stp[:handler_hash],
|
208
|
-
step_to_resq: create_step_instance(stp[:step_to_resq], flow),
|
209
|
-
on_error_type: error_type(flow, stp)
|
210
|
-
)
|
211
|
-
end
|
212
|
-
|
213
|
-
def create_resq_fail(stp, flow)
|
214
|
-
Decouplio::Steps::ResqFail.new(
|
215
|
-
handler_hash: stp[:handler_hash],
|
216
|
-
step_to_resq: create_step_instance(stp[:step_to_resq], flow),
|
217
|
-
on_error_type: error_type(flow, stp)
|
218
|
-
)
|
219
|
-
end
|
220
|
-
|
221
|
-
def create_inner_action_step(stp, flow)
|
222
|
-
Decouplio::Steps::InnerActionStep.new(
|
223
|
-
name: stp[:name],
|
224
|
-
action: stp[:action],
|
225
|
-
on_success_type: success_type(flow, stp),
|
226
|
-
on_failure_type: failure_type(flow, stp)
|
227
|
-
)
|
228
|
-
end
|
229
|
-
|
230
|
-
def create_inner_action_fail(stp, flow)
|
231
|
-
Decouplio::Steps::InnerActionFail.new(
|
232
|
-
name: stp[:name],
|
233
|
-
action: stp[:action],
|
234
|
-
on_success_type: success_type(flow, stp),
|
235
|
-
on_failure_type: failure_type(flow, stp)
|
236
|
-
)
|
237
|
-
end
|
238
|
-
|
239
|
-
def create_inner_action_pass(stp, flow)
|
240
|
-
Decouplio::Steps::InnerActionPass.new(
|
241
|
-
name: stp[:name],
|
242
|
-
action: stp[:action],
|
243
|
-
on_success_type: success_type(flow, stp),
|
244
|
-
on_failure_type: failure_type(flow, stp)
|
245
|
-
)
|
246
|
-
end
|
247
|
-
|
248
|
-
def create_inner_service_step(stp, flow)
|
249
|
-
Decouplio::Steps::ServiceStep.new(
|
250
|
-
name: stp[:name],
|
251
|
-
service: stp[:service],
|
252
|
-
args: stp[:_args],
|
253
|
-
on_success_type: success_type(flow, stp),
|
254
|
-
on_failure_type: failure_type(flow, stp)
|
255
|
-
)
|
256
|
-
end
|
257
|
-
|
258
|
-
def create_inner_service_fail(stp, flow)
|
259
|
-
Decouplio::Steps::ServiceFail.new(
|
260
|
-
name: stp[:name],
|
261
|
-
service: stp[:service],
|
262
|
-
args: stp[:_args],
|
263
|
-
on_success_type: success_type(flow, stp),
|
264
|
-
on_failure_type: failure_type(flow, stp)
|
265
|
-
)
|
266
|
-
end
|
267
|
-
|
268
|
-
def create_inner_service_pass(stp, flow)
|
269
|
-
Decouplio::Steps::ServicePass.new(
|
270
|
-
name: stp[:name],
|
271
|
-
service: stp[:service],
|
272
|
-
args: stp[:_args],
|
273
|
-
on_success_type: success_type(flow, stp),
|
274
|
-
on_failure_type: failure_type(flow, stp)
|
275
|
-
)
|
276
|
-
end
|
277
|
-
|
278
|
-
def create_doby(stp, flow)
|
279
|
-
Decouplio::Steps::Doby.new(
|
280
|
-
name: stp[:name],
|
281
|
-
doby_class: stp[:doby_class],
|
282
|
-
doby_options: stp[:doby_options],
|
283
|
-
on_success_type: success_type(flow, stp),
|
284
|
-
on_failure_type: failure_type(flow, stp)
|
285
|
-
)
|
286
|
-
end
|
287
|
-
|
288
|
-
def create_aide(stp, flow)
|
289
|
-
Decouplio::Steps::Aide.new(
|
290
|
-
name: stp[:name],
|
291
|
-
aide_class: stp[:aide_class],
|
292
|
-
aide_options: stp[:aide_options],
|
293
|
-
on_success_type: success_type(flow, stp),
|
294
|
-
on_failure_type: failure_type(flow, stp)
|
295
|
-
)
|
296
|
-
end
|
297
|
-
|
298
|
-
def compose_flow(flow, palps, next_steps, action_class, flow_hash = {})
|
299
|
-
flow.each_with_index do |(step_id, stp), idx|
|
300
|
-
case stp[:type]
|
301
|
-
when Decouplio::Const::Types::STEP_TYPE,
|
302
|
-
Decouplio::Const::Types::PASS_TYPE,
|
303
|
-
Decouplio::Const::Types::WRAP_TYPE,
|
304
|
-
Decouplio::Const::Types::ACTION_TYPE_STEP,
|
305
|
-
Decouplio::Const::Types::ACTION_TYPE_PASS,
|
306
|
-
Decouplio::Const::Types::SERVICE_TYPE_STEP,
|
307
|
-
Decouplio::Const::Types::SERVICE_TYPE_PASS,
|
308
|
-
Decouplio::Const::Types::RESQ_TYPE_STEP,
|
309
|
-
Decouplio::Const::Types::RESQ_TYPE_PASS
|
310
|
-
compose_step_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
311
|
-
when Decouplio::Const::Types::FAIL_TYPE,
|
312
|
-
Decouplio::Const::Types::RESQ_TYPE_FAIL,
|
313
|
-
Decouplio::Const::Types::ACTION_TYPE_FAIL,
|
314
|
-
Decouplio::Const::Types::SERVICE_TYPE_FAIL
|
315
|
-
compose_fail_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
316
|
-
when Decouplio::Const::Types::DOBY_TYPE
|
317
|
-
compose_doby_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
318
|
-
when Decouplio::Const::Types::AIDE_TYPE
|
319
|
-
compose_aide_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
320
|
-
when Decouplio::Const::Types::IF_TYPE_PASS, Decouplio::Const::Types::UNLESS_TYPE_PASS
|
321
|
-
compose_pass_condition_flow(stp, flow, idx, flow_hash)
|
322
|
-
when Decouplio::Const::Types::IF_TYPE_FAIL, Decouplio::Const::Types::UNLESS_TYPE_FAIL
|
323
|
-
compose_fail_condition_flow(stp, flow, idx, flow_hash)
|
324
|
-
when Decouplio::Const::Types::OCTO_TYPE
|
325
|
-
compose_octo_flow(stp, step_id, idx, flow, palps, flow_hash, action_class)
|
326
|
-
end
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
def compose_step_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
331
|
-
flow_values = flow.values + (next_steps&.values || [])
|
332
|
-
stp[:flow][Decouplio::Const::Results::PASS] = next_success_step(
|
333
|
-
flow_values,
|
334
|
-
idx,
|
335
|
-
flow[step_id][:on_success]
|
336
|
-
)
|
337
|
-
stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(
|
338
|
-
flow_values,
|
339
|
-
idx,
|
340
|
-
flow[step_id][:on_failure]
|
341
|
-
)
|
342
|
-
stp[:flow][Decouplio::Const::Results::ERROR] = next_failure_step(
|
343
|
-
flow_values,
|
344
|
-
idx,
|
345
|
-
flow[step_id][:on_error]
|
346
|
-
)
|
347
|
-
stp[:flow][Decouplio::Const::Results::PASS] ||= flow_hash[Decouplio::Const::Results::PASS]
|
348
|
-
stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
|
349
|
-
stp[:flow][Decouplio::Const::Results::ERROR] ||= flow_hash[Decouplio::Const::Results::ERROR]
|
350
|
-
stp[:flow][Decouplio::Const::Results::FINISH_HIM] = Decouplio::Const::Results::NO_STEP
|
351
|
-
end
|
352
|
-
|
353
|
-
def compose_doby_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
354
|
-
flow_values = flow.values + (next_steps&.values || [])
|
355
|
-
stp[:flow][Decouplio::Const::Results::PASS] = next_success_step(
|
356
|
-
flow_values,
|
357
|
-
idx,
|
358
|
-
flow[step_id][:on_success]
|
359
|
-
)
|
360
|
-
stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(
|
361
|
-
flow_values,
|
362
|
-
idx,
|
363
|
-
flow[step_id][:on_failure]
|
364
|
-
)
|
365
|
-
stp[:flow][Decouplio::Const::Results::ERROR] = next_failure_step(
|
366
|
-
flow_values,
|
367
|
-
idx,
|
368
|
-
flow[step_id][:on_error]
|
369
|
-
)
|
370
|
-
stp[:flow][Decouplio::Const::Results::PASS] ||= flow_hash[Decouplio::Const::Results::PASS]
|
371
|
-
stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
|
372
|
-
stp[:flow][Decouplio::Const::Results::ERROR] ||= flow_hash[Decouplio::Const::Results::ERROR]
|
373
|
-
stp[:flow][Decouplio::Const::Results::FINISH_HIM] = Decouplio::Const::Results::NO_STEP
|
374
|
-
end
|
375
|
-
|
376
|
-
def compose_aide_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
377
|
-
flow_values = flow.values + (next_steps&.values || [])
|
378
|
-
stp[:flow][Decouplio::Const::Results::PASS] = next_failure_step(
|
379
|
-
flow_values,
|
380
|
-
idx,
|
381
|
-
flow[step_id][:on_success]
|
382
|
-
)
|
383
|
-
stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(
|
384
|
-
flow_values,
|
385
|
-
idx,
|
386
|
-
flow[step_id][:on_failure]
|
387
|
-
)
|
388
|
-
stp[:flow][Decouplio::Const::Results::ERROR] = next_failure_step(
|
389
|
-
flow_values,
|
390
|
-
idx,
|
391
|
-
flow[step_id][:on_error]
|
392
|
-
)
|
393
|
-
stp[:flow][Decouplio::Const::Results::PASS] ||= flow_hash[Decouplio::Const::Results::FAIL]
|
394
|
-
stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
|
395
|
-
stp[:flow][Decouplio::Const::Results::ERROR] ||= flow_hash[Decouplio::Const::Results::ERROR]
|
396
|
-
stp[:flow][Decouplio::Const::Results::FINISH_HIM] = Decouplio::Const::Results::NO_STEP
|
397
|
-
end
|
398
|
-
|
399
|
-
def compose_fail_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
400
|
-
flow_values = flow.values + (next_steps&.values || [])
|
401
|
-
stp[:flow][Decouplio::Const::Results::PASS] = next_failure_step(
|
402
|
-
flow_values,
|
403
|
-
idx,
|
404
|
-
flow[step_id][:on_success]
|
405
|
-
)
|
406
|
-
stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(
|
407
|
-
flow_values,
|
408
|
-
idx,
|
409
|
-
flow[step_id][:on_failure]
|
410
|
-
)
|
411
|
-
stp[:flow][Decouplio::Const::Results::ERROR] = next_failure_step(
|
412
|
-
flow_values,
|
413
|
-
idx,
|
414
|
-
flow[step_id][:on_error]
|
415
|
-
)
|
416
|
-
stp[:flow][Decouplio::Const::Results::PASS] ||= flow_hash[Decouplio::Const::Results::FAIL]
|
417
|
-
stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
|
418
|
-
stp[:flow][Decouplio::Const::Results::ERROR] ||= flow_hash[Decouplio::Const::Results::ERROR]
|
419
|
-
stp[:flow][Decouplio::Const::Results::FINISH_HIM] = Decouplio::Const::Results::NO_STEP
|
420
|
-
end
|
421
|
-
|
422
|
-
def compose_pass_condition_flow(stp, flow, idx, flow_hash)
|
423
|
-
stp[:flow][Decouplio::Const::Results::PASS] = next_success_step(flow.values, idx, nil)
|
424
|
-
stp[:flow][Decouplio::Const::Results::FAIL] = next_success_step(flow.values, idx + 1, nil)
|
425
|
-
stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::PASS]
|
426
|
-
end
|
427
|
-
|
428
|
-
def compose_fail_condition_flow(stp, flow, idx, flow_hash)
|
429
|
-
stp[:flow][Decouplio::Const::Results::PASS] = next_failure_step(flow.values, idx, nil)
|
430
|
-
stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(flow.values, idx + 1, nil)
|
431
|
-
stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
|
432
|
-
end
|
433
|
-
|
434
|
-
def compose_octo_flow(stp, step_id, idx, flow, palps, flow_hash, action_class)
|
435
|
-
stp[:flow][Decouplio::Const::Results::PASS] = next_success_step(
|
436
|
-
flow.values,
|
437
|
-
idx,
|
438
|
-
flow[step_id][:on_success]
|
439
|
-
)
|
440
|
-
stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(
|
441
|
-
flow.values,
|
442
|
-
idx,
|
443
|
-
flow[step_id][:on_failure]
|
444
|
-
)
|
445
|
-
stp[:flow][Decouplio::Const::Results::PASS] ||= flow_hash[Decouplio::Const::Results::PASS]
|
446
|
-
stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
|
447
|
-
stp[:flow][Decouplio::Const::Results::FINISH_HIM] = Decouplio::Const::Results::NO_STEP
|
448
|
-
stp = compose_strategy(stp, palps, flow.to_a[(idx + 1)..].to_h, action_class)
|
449
|
-
stp[:hash_case].each do |strategy_key, strategy_raw_data|
|
450
|
-
stp[:flow][strategy_key] = strategy_raw_data[:first_step]
|
451
|
-
end
|
452
|
-
end
|
453
|
-
|
454
|
-
def success_type(flow, stp)
|
455
|
-
return :finish_him if [:on_success, true].include?(finish_him(stp))
|
456
|
-
|
457
|
-
step_id = stp.dig(:flow, Decouplio::Const::Results::PASS)
|
458
|
-
if step_id.nil? && Decouplio::Const::Results::STEP_PASS == stp[:on_success]
|
459
|
-
Decouplio::Const::Results::STEP_PASS
|
460
|
-
elsif step_id.nil? && Decouplio::Const::Results::STEP_FAIL == stp[:on_success]
|
461
|
-
Decouplio::Const::Results::STEP_FAIL
|
462
|
-
else
|
463
|
-
Decouplio::Const::Types::PASS_FLOW.include?(
|
464
|
-
flow[step_id]&.[](:type)
|
465
|
-
)
|
466
|
-
end
|
467
|
-
end
|
468
|
-
|
469
|
-
def failure_type(flow, stp)
|
470
|
-
return :finish_him if [:on_failure, true].include?(finish_him(stp))
|
471
|
-
|
472
|
-
step_id = stp.dig(:flow, Decouplio::Const::Results::FAIL)
|
473
|
-
if step_id.nil? && Decouplio::Const::Results::STEP_PASS == stp[:on_failure]
|
474
|
-
Decouplio::Const::Results::STEP_PASS
|
475
|
-
elsif step_id.nil? && Decouplio::Const::Results::STEP_FAIL == stp[:on_failure]
|
476
|
-
Decouplio::Const::Results::STEP_FAIL
|
477
|
-
else
|
478
|
-
Decouplio::Const::Types::FAIL_FLOW.include?(
|
479
|
-
flow[step_id]&.[](:type)
|
480
|
-
)
|
481
|
-
end
|
482
|
-
end
|
483
|
-
|
484
|
-
def error_type(flow, stp)
|
485
|
-
return :finish_him if [:on_error].include?(finish_him(stp))
|
486
|
-
|
487
|
-
step_id = stp.dig(:flow, Decouplio::Const::Results::ERROR)
|
488
|
-
if step_id.nil? && Decouplio::Const::Results::STEP_PASS == stp[:on_error]
|
489
|
-
Decouplio::Const::Results::STEP_PASS
|
490
|
-
elsif step_id.nil? && Decouplio::Const::Results::STEP_FAIL == stp[:on_error]
|
491
|
-
Decouplio::Const::Results::STEP_FAIL
|
492
|
-
else
|
493
|
-
Decouplio::Const::Types::FAIL_FLOW.include?(
|
494
|
-
flow[step_id]&.[](:type)
|
495
|
-
)
|
496
|
-
end
|
497
|
-
end
|
498
|
-
|
499
|
-
def finish_him(stp)
|
500
|
-
if stp[:on_success] == :finish_him
|
501
|
-
:on_success
|
502
|
-
elsif stp[:on_failure] == :finish_him
|
503
|
-
:on_failure
|
504
|
-
elsif stp.key?(:finish_him)
|
505
|
-
stp[:finish_him]
|
506
|
-
end
|
507
|
-
end
|
508
|
-
|
509
|
-
def compose_wrap(stp, action_class)
|
510
|
-
if Decouplio::Const::Types::WRAP_TYPE == stp[:type]
|
511
|
-
stp[:wrap_flow] = Flow.call(logic: stp[:wrap_flow], action_class: action_class)
|
512
|
-
elsif Decouplio::Const::Types::WRAP_TYPE == stp.dig(:step_to_resq, :type)
|
513
|
-
stp[:step_to_resq][:wrap_flow] = Flow.call(logic: stp[:step_to_resq][:wrap_flow], action_class: action_class)
|
514
|
-
end
|
515
|
-
|
516
|
-
stp
|
517
|
-
end
|
518
|
-
|
519
|
-
def compose_condition(stp, palp_prefix, flow)
|
520
|
-
condition_options = stp.slice(:if, :unless)
|
521
|
-
|
522
|
-
return if condition_options.empty?
|
523
|
-
|
524
|
-
Decouplio::Validators::Condition.validate(
|
525
|
-
condition_options: condition_options,
|
526
|
-
type: stp[:type]
|
527
|
-
)
|
528
|
-
|
529
|
-
condition = ([%i[name type]] + condition_options.invert.to_a).transpose.to_h
|
530
|
-
condition[:step_id] = random_id(name: condition[:name], palp_prefix: palp_prefix, flow: flow)
|
531
|
-
condition[:type] = Decouplio::Const::Types::STEP_TYPE_TO_CONDITION_TYPE.dig(stp[:type], condition[:type])
|
532
|
-
condition[:flow] = {}
|
533
|
-
condition
|
534
|
-
end
|
535
|
-
|
536
|
-
def compose_action(stp)
|
537
|
-
return stp if Decouplio::Const::Types::ACTION_NOT_ALLOWED_STEPS.include?(stp[:type])
|
538
|
-
|
539
|
-
if !stp[:name].is_a?(Symbol) && stp[:name] < Decouplio::Action
|
540
|
-
stp[:action] = stp[:name]
|
541
|
-
stp[:name] = stp[:name].name.to_sym
|
542
|
-
elsif stp[:name].is_a?(Class) && stp[:name].respond_to?(:call)
|
543
|
-
stp[:service] = stp[:name]
|
544
|
-
stp[:name] = stp[:name].name.to_sym
|
545
|
-
elsif stp.dig(:step_to_resq, :name) &&
|
546
|
-
!stp.dig(:step_to_resq, :name).is_a?(Symbol) &&
|
547
|
-
stp.dig(:step_to_resq, :name) < Decouplio::Action
|
548
|
-
stp[:step_to_resq][:action] = stp[:step_to_resq][:name]
|
549
|
-
stp[:step_to_resq][:name] = stp[:step_to_resq][:name].name.to_sym
|
550
|
-
elsif stp.dig(:step_to_resq, :name).is_a?(Class) && stp.dig(:step_to_resq, :name).respond_to?(:call)
|
551
|
-
stp[:step_to_resq][:service] = stp[:step_to_resq][:name]
|
552
|
-
stp[:step_to_resq][:name] = stp[:step_to_resq][:name].name.to_sym
|
553
|
-
elsif stp[:name].is_a?(Class)
|
554
|
-
stp[:action] = stp[:name]
|
555
|
-
elsif stp.dig(:step_to_resq, :name).is_a?(Class)
|
556
|
-
stp[:step_to_resq][:action] = stp.dig(:step_to_resq, :name)
|
557
|
-
end
|
558
|
-
|
559
|
-
if stp.key?(:action)
|
560
|
-
stp[:type] = Decouplio::Const::Types::STEP_TYPE_TO_INNER_TYPE[stp[:type]]
|
561
|
-
elsif stp.dig(:step_to_resq, :action)
|
562
|
-
stp[:step_to_resq][:type] = Decouplio::Const::Types::STEP_TYPE_TO_INNER_TYPE[stp[:type]]
|
563
|
-
end
|
564
|
-
|
565
|
-
if stp.key?(:service)
|
566
|
-
stp[:type] = Decouplio::Const::Types::STEP_TYPE_TO_SERVICE_TYPE[stp[:type]]
|
567
|
-
elsif stp.dig(:step_to_resq, :service)
|
568
|
-
stp[:step_to_resq][:type] = Decouplio::Const::Types::STEP_TYPE_TO_SERVICE_TYPE[stp[:type]]
|
569
|
-
end
|
570
|
-
|
571
|
-
stp
|
572
|
-
end
|
573
|
-
|
574
|
-
def compose_strategy(stp, palps, next_steps, action_class)
|
575
|
-
return stp unless stp[:type] == Decouplio::Const::Types::OCTO_TYPE
|
576
|
-
|
577
|
-
stp[:hash_case] = stp[:hash_case].to_h do |strategy_key, options|
|
578
|
-
strategy_flow = compose(
|
579
|
-
logic_container_raw_data: palps[options[:palp]],
|
580
|
-
action_class: action_class,
|
581
|
-
palp_prefix: options[:palp],
|
582
|
-
parent_flow: stp[:flow],
|
583
|
-
next_steps: next_steps
|
584
|
-
)
|
585
|
-
[
|
586
|
-
strategy_key,
|
587
|
-
strategy_flow
|
588
|
-
]
|
589
|
-
end
|
590
|
-
stp
|
591
|
-
end
|
592
|
-
|
593
|
-
def compose_resq(stp, palp_prefix, flow)
|
594
|
-
return stp unless stp[:type] == Decouplio::Const::Types::RESQ_TYPE
|
595
|
-
|
596
|
-
options_for_resq = stp[:step_to_resq].slice(
|
597
|
-
:on_success,
|
598
|
-
:on_failure,
|
599
|
-
:on_error,
|
600
|
-
:finish_him,
|
601
|
-
:if,
|
602
|
-
:unless
|
603
|
-
)
|
604
|
-
stp[:step_id] = random_id(name: stp[:name], palp_prefix: palp_prefix, flow: flow)
|
605
|
-
stp[:flow] = {}
|
606
|
-
handler_hash = {}
|
607
|
-
stp[:handler_hash].each do |handler_method, error_classes|
|
608
|
-
[error_classes].flatten.each do |error_class|
|
609
|
-
handler_hash[error_class] = handler_method
|
610
|
-
end
|
611
|
-
end
|
612
|
-
stp[:handler_hash] = handler_hash
|
613
|
-
stp[:type] = Decouplio::Const::Types::STEP_TYPE_TO_RESQ_TYPE[stp[:step_to_resq][:type]]
|
614
|
-
stp.merge(options_for_resq)
|
615
|
-
end
|
616
|
-
|
617
|
-
def next_success_step(steps, idx, value)
|
618
|
-
steps_slice = steps[(idx + 1)..]
|
619
|
-
steps_slice.each_with_index do |stp, index|
|
620
|
-
if (
|
621
|
-
Decouplio::Const::Results::STEP_PASS == value &&
|
622
|
-
Decouplio::Const::Types::SUCCESS_TRACK_STEP_TYPES.include?(stp[:type])
|
623
|
-
) || (
|
624
|
-
Decouplio::Const::Results::STEP_FAIL == value &&
|
625
|
-
Decouplio::Const::Types::FAILURE_TRACK_STEP_TYPES.include?(stp[:type])
|
626
|
-
) || (
|
627
|
-
!value &&
|
628
|
-
Decouplio::Const::Types::SUCCESS_TRACK_STEP_TYPES.include?(stp[:type])
|
629
|
-
)
|
630
|
-
return stp[:step_id]
|
631
|
-
elsif value == stp[:name]
|
632
|
-
prev_step = steps_slice[index - 1]
|
633
|
-
if [
|
634
|
-
Decouplio::Const::Types::IF_TYPE_PASS,
|
635
|
-
Decouplio::Const::Types::UNLESS_TYPE_PASS
|
636
|
-
].include?(prev_step[:type])
|
637
|
-
return prev_step[:step_id]
|
638
|
-
else
|
639
|
-
return stp[:step_id]
|
640
|
-
end
|
641
|
-
end
|
642
|
-
end
|
643
|
-
|
644
|
-
Decouplio::Const::Results::NO_STEP
|
645
|
-
end
|
646
|
-
|
647
|
-
def next_failure_step(steps, idx, value)
|
648
|
-
steps_slice = steps[(idx + 1)..]
|
649
|
-
steps_slice.each_with_index do |stp, index|
|
650
|
-
if (
|
651
|
-
Decouplio::Const::Results::STEP_PASS == value &&
|
652
|
-
Decouplio::Const::Types::SUCCESS_TRACK_STEP_TYPES.include?(stp[:type])
|
653
|
-
) || (
|
654
|
-
Decouplio::Const::Results::STEP_FAIL == value &&
|
655
|
-
Decouplio::Const::Types::FAILURE_TRACK_STEP_TYPES.include?(stp[:type])
|
656
|
-
) || (
|
657
|
-
!value &&
|
658
|
-
Decouplio::Const::Types::FAILURE_TRACK_STEP_TYPES.include?(stp[:type])
|
659
|
-
)
|
660
|
-
return stp[:step_id]
|
661
|
-
elsif value == stp[:name]
|
662
|
-
prev_step = steps_slice[index - 1]
|
663
|
-
if [
|
664
|
-
Decouplio::Const::Types::IF_TYPE_FAIL,
|
665
|
-
Decouplio::Const::Types::UNLESS_TYPE_FAIL
|
666
|
-
].include?(prev_step[:type])
|
667
|
-
return prev_step[:step_id]
|
668
|
-
else
|
669
|
-
return stp[:step_id]
|
670
|
-
end
|
671
|
-
end
|
672
|
-
end
|
673
|
-
|
674
|
-
Decouplio::Const::Results::NO_STEP
|
675
|
-
end
|
676
|
-
|
677
|
-
def random_id(name:, palp_prefix:, flow:)
|
678
|
-
loop do
|
679
|
-
random_step_id =
|
680
|
-
"#{palp_prefix}_#{name}_#{random_value}#{random_value}#{random_value}#{random_value}#{random_value}".to_sym
|
681
|
-
|
682
|
-
break random_step_id if flow.select { |stp| stp[:step_id] == random_step_id }.empty?
|
683
|
-
end
|
684
|
-
end
|
685
|
-
|
686
|
-
def random_value
|
687
|
-
(10..99).to_a.sample
|
688
|
-
end
|
689
|
-
end
|
690
|
-
end
|
691
|
-
end
|