decouplio 1.0.0alpha8 → 1.0.0rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +313 -15
  3. data/decouplio.gemspec +8 -2
  4. data/lib/decouplio/action.rb +24 -40
  5. data/lib/decouplio/action_state_printer.rb +2 -5
  6. data/lib/decouplio/const/flows.rb +59 -0
  7. data/lib/decouplio/const/reserved_methods.rb +6 -13
  8. data/lib/decouplio/const/types.rb +0 -144
  9. data/lib/decouplio/const/validations/common.rb +10 -0
  10. data/lib/decouplio/const/validations/octo.rb +16 -0
  11. data/lib/decouplio/const/validations/resq.rb +12 -1
  12. data/lib/decouplio/ctx.rb +13 -0
  13. data/lib/decouplio/default_meta_store.rb +2 -4
  14. data/lib/decouplio/errors/action_class_error.rb +0 -3
  15. data/lib/decouplio/errors/base_error.rb +0 -3
  16. data/lib/decouplio/errors/execution_error.rb +0 -2
  17. data/lib/decouplio/errors/extra_key_for_pass_error.rb +0 -3
  18. data/lib/decouplio/errors/fail_can_not_be_first_step_error.rb +0 -3
  19. data/lib/decouplio/errors/fail_controversial_keys_error.rb +0 -3
  20. data/lib/decouplio/errors/fail_finish_him_error.rb +0 -3
  21. data/lib/decouplio/errors/invalid_error_class_error.rb +0 -3
  22. data/lib/decouplio/errors/invalid_options_for_resq_step.rb +18 -0
  23. data/lib/decouplio/errors/invalid_wrap_name_error.rb +0 -3
  24. data/lib/decouplio/errors/logic_is_not_defined_error.rb +0 -3
  25. data/lib/decouplio/errors/logic_redefinition_error.rb +0 -3
  26. data/lib/decouplio/errors/octo_block_is_not_defined_error.rb +0 -3
  27. data/lib/decouplio/errors/octo_case_is_not_defined_error.rb +19 -0
  28. data/lib/decouplio/errors/octo_controversial_keys_error.rb +0 -3
  29. data/lib/decouplio/errors/{error_store_error.rb → octo_finish_him_is_not_allowed_error.rb} +2 -4
  30. data/lib/decouplio/errors/options_validation_error.rb +13 -1
  31. data/lib/decouplio/errors/palp_block_is_not_defined_error.rb +0 -3
  32. data/lib/decouplio/errors/palp_validation_error.rb +0 -3
  33. data/lib/decouplio/errors/pass_controversial_keys_error.rb +0 -3
  34. data/lib/decouplio/errors/pass_finish_him_error.rb +0 -3
  35. data/lib/decouplio/errors/required_options_is_missing_for_octo_error.rb +0 -3
  36. data/lib/decouplio/errors/resq_definition_error.rb +0 -3
  37. data/lib/decouplio/errors/resq_error_class_error.rb +0 -3
  38. data/lib/decouplio/errors/resq_handler_method_error.rb +0 -3
  39. data/lib/decouplio/errors/step_controversial_keys_error.rb +0 -3
  40. data/lib/decouplio/errors/step_definition_error.rb +17 -0
  41. data/lib/decouplio/errors/step_finish_him_error.rb +0 -3
  42. data/lib/decouplio/errors/step_is_not_defined_for_fail_error.rb +0 -3
  43. data/lib/decouplio/errors/step_is_not_defined_for_pass_error.rb +0 -4
  44. data/lib/decouplio/errors/step_is_not_defined_for_step_error.rb +0 -4
  45. data/lib/decouplio/errors/step_is_not_defined_for_wrap_error.rb +0 -3
  46. data/lib/decouplio/errors/step_name_error.rb +0 -3
  47. data/lib/decouplio/errors/wrap_block_is_not_defined_error.rb +0 -3
  48. data/lib/decouplio/errors/wrap_controversial_keys_error.rb +0 -3
  49. data/lib/decouplio/errors/wrap_finish_him_error.rb +0 -3
  50. data/lib/decouplio/errors/wrap_klass_method_error.rb +0 -3
  51. data/lib/decouplio/graph.rb +9 -0
  52. data/lib/decouplio/logic_dsl.rb +340 -79
  53. data/lib/decouplio/new_flow.rb +283 -0
  54. data/lib/decouplio/octo_hash_case.rb +20 -5
  55. data/lib/decouplio/octo_options_validator.rb +10 -64
  56. data/lib/decouplio/step_validator.rb +200 -0
  57. data/lib/decouplio/steps/base_condition.rb +21 -0
  58. data/lib/decouplio/steps/base_if_condition.rb +11 -0
  59. data/lib/decouplio/steps/base_inner_action.rb +42 -0
  60. data/lib/decouplio/steps/base_octo.rb +26 -0
  61. data/lib/decouplio/steps/base_resq.rb +25 -28
  62. data/lib/decouplio/steps/base_resq_with_mapping.rb +34 -0
  63. data/lib/decouplio/steps/base_service_step.rb +39 -0
  64. data/lib/decouplio/steps/base_step.rb +33 -6
  65. data/lib/decouplio/steps/base_unless_condition.rb +11 -0
  66. data/lib/decouplio/steps/base_wrap.rb +27 -0
  67. data/lib/decouplio/steps/fail.rb +1 -28
  68. data/lib/decouplio/steps/if_condition_fail.rb +1 -21
  69. data/lib/decouplio/steps/if_condition_pass.rb +1 -19
  70. data/lib/decouplio/steps/inner_action_fail.rb +1 -35
  71. data/lib/decouplio/steps/inner_action_pass.rb +9 -29
  72. data/lib/decouplio/steps/inner_action_step.rb +1 -35
  73. data/lib/decouplio/steps/octo_by_key.rb +31 -0
  74. data/lib/decouplio/steps/octo_by_method.rb +31 -0
  75. data/lib/decouplio/steps/pass.rb +5 -26
  76. data/lib/decouplio/steps/resq_fail.rb +0 -2
  77. data/lib/decouplio/steps/resq_pass.rb +1 -3
  78. data/lib/decouplio/steps/resq_with_mapping_fail.rb +8 -0
  79. data/lib/decouplio/steps/resq_with_mapping_pass.rb +8 -0
  80. data/lib/decouplio/steps/service_as_fail.rb +8 -0
  81. data/lib/decouplio/steps/service_as_pass.rb +16 -0
  82. data/lib/decouplio/steps/service_as_step.rb +8 -0
  83. data/lib/decouplio/steps/step.rb +0 -24
  84. data/lib/decouplio/steps/unless_condition_fail.rb +1 -21
  85. data/lib/decouplio/steps/unless_condition_pass.rb +1 -19
  86. data/lib/decouplio/steps/wrap.rb +25 -37
  87. data/lib/decouplio/steps/wrap_with_class.rb +43 -0
  88. data/lib/decouplio/steps/wrap_with_class_method.rb +45 -0
  89. data/lib/decouplio/utils/prepare_resq_mappings.rb +17 -0
  90. data/lib/decouplio/version.rb +1 -1
  91. data/lib/decouplio.rb +93 -0
  92. metadata +30 -42
  93. data/.circleci/config.yml +0 -63
  94. data/.dockerignore +0 -12
  95. data/.gitignore +0 -13
  96. data/.rspec +0 -3
  97. data/.rubocop.yml +0 -108
  98. data/.rubocop_todo.yml +0 -147
  99. data/.ruby-version +0 -1
  100. data/.vscode/settings.json +0 -3
  101. data/Dockerfile +0 -12
  102. data/Gemfile +0 -8
  103. data/benchmarks/.ruby-version +0 -1
  104. data/benchmarks/Dockerfile +0 -12
  105. data/benchmarks/Gemfile +0 -12
  106. data/benchmarks/multi_step_benchmark.rb +0 -336
  107. data/benchmarks/single_step_benchmark.rb +0 -159
  108. data/bin/console +0 -15
  109. data/bin/setup +0 -8
  110. data/docker-compose.yml +0 -29
  111. data/lib/decouplio/composer.rb +0 -615
  112. data/lib/decouplio/const/colors.rb +0 -25
  113. data/lib/decouplio/const/results.rb +0 -15
  114. data/lib/decouplio/const/step_options.rb +0 -16
  115. data/lib/decouplio/errors/extra_key_for_fail_error.rb +0 -26
  116. data/lib/decouplio/errors/extra_key_for_octo_error.rb +0 -26
  117. data/lib/decouplio/errors/extra_key_for_resq_error.rb +0 -29
  118. data/lib/decouplio/errors/extra_key_for_step_error.rb +0 -23
  119. data/lib/decouplio/errors/extra_key_for_wrap_error.rb +0 -23
  120. data/lib/decouplio/errors/palp_is_not_defined_error.rb +0 -26
  121. data/lib/decouplio/flow.rb +0 -17
  122. data/lib/decouplio/options_validator.rb +0 -606
  123. data/lib/decouplio/processor.rb +0 -20
  124. data/lib/decouplio/steps/octo.rb +0 -27
  125. data/lib/decouplio/steps/service_fail.rb +0 -41
  126. data/lib/decouplio/steps/service_pass.rb +0 -41
  127. data/lib/decouplio/steps/service_step.rb +0 -41
  128. data/lib/decouplio/steps/shared/fail_resolver.rb +0 -40
  129. data/lib/decouplio/steps/shared/step_resolver.rb +0 -43
  130. data/lib/decouplio/validators/condition.rb +0 -49
@@ -1,615 +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 'options_validator'
24
- require_relative 'validators/condition'
25
-
26
- module Decouplio
27
- class Composer
28
- class << self
29
- def compose(logic_container_raw_data:, action_class:, palp_prefix: :root, parent_flow: {}, next_steps: nil)
30
- flow = logic_container_raw_data.steps
31
- palps = logic_container_raw_data.palps
32
-
33
- steps_pool = {}
34
- steps_flow = {}
35
-
36
- flow = prepare_raw_data(flow, palp_prefix, action_class)
37
- validate_flow(flow, palps, next_steps, action_class)
38
- flow = compose_flow(flow, palps, next_steps, action_class, parent_flow)
39
-
40
- flow.each do |step_id, stp|
41
- steps_flow[step_id] = stp[:flow]
42
- steps_flow.merge!(extract_palp_flow(stp))
43
- steps_pool[step_id] = create_step_instance(stp, flow)
44
- steps_pool.merge!(extract_palp_pool(stp))
45
- end
46
-
47
- {
48
- first_step: steps_pool.keys.first,
49
- steps_pool: steps_pool.freeze,
50
- steps_flow: steps_flow.freeze
51
- }
52
- end
53
-
54
- private
55
-
56
- def prepare_raw_data(flow, palp_prefix, action_class)
57
- flow = flow.map do |stp|
58
- stp[:step_id] = random_id(name: stp[:name], palp_prefix: palp_prefix, flow: flow)
59
- stp[:flow] = {}
60
- stp = compose_resq(stp, palp_prefix, flow)
61
- stp = compose_action(stp)
62
- stp = compose_wrap(stp, action_class)
63
- condition = compose_condition(stp, palp_prefix, flow)
64
-
65
- [condition, stp].compact
66
- end.flatten
67
-
68
- flow.to_h do |stp|
69
- [stp[:step_id], stp]
70
- end
71
- end
72
-
73
- def validate_flow(flow, palps, next_steps, action_class)
74
- OptionsValidator.new(
75
- flow: flow,
76
- palps: palps,
77
- next_steps: next_steps,
78
- action_class: action_class
79
- ).call
80
- end
81
-
82
- def extract_palp_flow(stp)
83
- return {} unless stp[:type] == Decouplio::Const::Types::OCTO_TYPE
84
-
85
- stp[:hash_case].values.map { |composer_output| composer_output[:steps_flow] }.reduce({}, :merge)
86
- end
87
-
88
- def extract_palp_pool(stp)
89
- return {} unless stp[:type] == Decouplio::Const::Types::OCTO_TYPE
90
-
91
- stp[:hash_case].values.map { |composer_output| composer_output[:steps_pool] }.reduce({}, :merge)
92
- end
93
-
94
- def create_step_instance(stp, flow)
95
- case stp[:type]
96
- when Decouplio::Const::Types::STEP_TYPE
97
- create_step(stp, flow)
98
- when Decouplio::Const::Types::FAIL_TYPE
99
- create_fail(stp, flow)
100
- when Decouplio::Const::Types::PASS_TYPE
101
- create_pass(stp, flow)
102
- when Decouplio::Const::Types::IF_TYPE_PASS
103
- create_if_condition_pass(stp)
104
- when Decouplio::Const::Types::IF_TYPE_FAIL
105
- create_if_condition_fail(stp)
106
- when Decouplio::Const::Types::UNLESS_TYPE_PASS
107
- create_unless_condition_pass(stp)
108
- when Decouplio::Const::Types::UNLESS_TYPE_FAIL
109
- create_unless_condition_fail(stp)
110
- when Decouplio::Const::Types::OCTO_TYPE
111
- create_octo(stp)
112
- when Decouplio::Const::Types::WRAP_TYPE
113
- create_wrap(flow, stp)
114
- when Decouplio::Const::Types::RESQ_TYPE_STEP, Decouplio::Const::Types::RESQ_TYPE_PASS
115
- create_resq_pass(stp, flow)
116
- when Decouplio::Const::Types::RESQ_TYPE_FAIL
117
- create_resq_fail(stp, flow)
118
- when Decouplio::Const::Types::ACTION_TYPE_STEP
119
- create_inner_action_step(stp, flow)
120
- when Decouplio::Const::Types::ACTION_TYPE_FAIL
121
- create_inner_action_fail(stp, flow)
122
- when Decouplio::Const::Types::ACTION_TYPE_PASS
123
- create_inner_action_pass(stp, flow)
124
- when Decouplio::Const::Types::SERVICE_TYPE_STEP
125
- create_inner_service_step(stp, flow)
126
- when Decouplio::Const::Types::SERVICE_TYPE_FAIL
127
- create_inner_service_fail(stp, flow)
128
- when Decouplio::Const::Types::SERVICE_TYPE_PASS
129
- create_inner_service_pass(stp, flow)
130
- end
131
- end
132
-
133
- def create_step(stp, flow)
134
- Decouplio::Steps::Step.new(
135
- name: stp[:name],
136
- on_success_type: success_type(flow, stp),
137
- on_failure_type: failure_type(flow, stp)
138
- )
139
- end
140
-
141
- def create_fail(stp, flow)
142
- Decouplio::Steps::Fail.new(
143
- name: stp[:name],
144
- on_success_type: success_type(flow, stp),
145
- on_failure_type: failure_type(flow, stp)
146
- )
147
- end
148
-
149
- def create_pass(stp, flow)
150
- Decouplio::Steps::Pass.new(
151
- name: stp[:name],
152
- on_success_type: success_type(flow, stp)
153
- )
154
- end
155
-
156
- def create_if_condition_pass(stp)
157
- Decouplio::Steps::IfConditionPass.new(
158
- name: stp[:name]
159
- )
160
- end
161
-
162
- def create_if_condition_fail(stp)
163
- Decouplio::Steps::IfConditionFail.new(
164
- name: stp[:name]
165
- )
166
- end
167
-
168
- def create_unless_condition_pass(stp)
169
- Decouplio::Steps::UnlessConditionPass.new(
170
- name: stp[:name]
171
- )
172
- end
173
-
174
- def create_unless_condition_fail(stp)
175
- Decouplio::Steps::UnlessConditionFail.new(
176
- name: stp[:name]
177
- )
178
- end
179
-
180
- def create_octo(stp)
181
- Decouplio::Steps::Octo.new(
182
- name: stp[:name],
183
- ctx_key: stp[:ctx_key],
184
- method: stp[:method]
185
- )
186
- end
187
-
188
- def create_wrap(flow, stp)
189
- Decouplio::Steps::Wrap.new(
190
- name: stp[:name],
191
- klass: stp[:klass],
192
- method: stp[:method],
193
- wrap_flow: stp[:wrap_flow],
194
- on_success_type: success_type(flow, stp),
195
- on_failure_type: failure_type(flow, stp)
196
- )
197
- end
198
-
199
- def create_resq_pass(stp, flow)
200
- Decouplio::Steps::ResqPass.new(
201
- handler_hash: stp[:handler_hash],
202
- step_to_resq: create_step_instance(stp[:step_to_resq], flow),
203
- on_error_type: error_type(flow, stp)
204
- )
205
- end
206
-
207
- def create_resq_fail(stp, flow)
208
- Decouplio::Steps::ResqFail.new(
209
- handler_hash: stp[:handler_hash],
210
- step_to_resq: create_step_instance(stp[:step_to_resq], flow),
211
- on_error_type: error_type(flow, stp)
212
- )
213
- end
214
-
215
- def create_inner_action_step(stp, flow)
216
- Decouplio::Steps::InnerActionStep.new(
217
- name: stp[:name],
218
- action: stp[:action],
219
- on_success_type: success_type(flow, stp),
220
- on_failure_type: failure_type(flow, stp)
221
- )
222
- end
223
-
224
- def create_inner_action_fail(stp, flow)
225
- Decouplio::Steps::InnerActionFail.new(
226
- name: stp[:name],
227
- action: stp[:action],
228
- on_success_type: success_type(flow, stp),
229
- on_failure_type: failure_type(flow, stp)
230
- )
231
- end
232
-
233
- def create_inner_action_pass(stp, flow)
234
- Decouplio::Steps::InnerActionPass.new(
235
- name: stp[:name],
236
- action: stp[:action],
237
- on_success_type: success_type(flow, stp),
238
- on_failure_type: failure_type(flow, stp)
239
- )
240
- end
241
-
242
- def create_inner_service_step(stp, flow)
243
- Decouplio::Steps::ServiceStep.new(
244
- name: stp[:name],
245
- service: stp[:service],
246
- args: stp[:_args],
247
- on_success_type: success_type(flow, stp),
248
- on_failure_type: failure_type(flow, stp)
249
- )
250
- end
251
-
252
- def create_inner_service_fail(stp, flow)
253
- Decouplio::Steps::ServiceFail.new(
254
- name: stp[:name],
255
- service: stp[:service],
256
- args: stp[:_args],
257
- on_success_type: success_type(flow, stp),
258
- on_failure_type: failure_type(flow, stp)
259
- )
260
- end
261
-
262
- def create_inner_service_pass(stp, flow)
263
- Decouplio::Steps::ServicePass.new(
264
- name: stp[:name],
265
- service: stp[:service],
266
- args: stp[:_args],
267
- on_success_type: success_type(flow, stp),
268
- on_failure_type: failure_type(flow, stp)
269
- )
270
- end
271
-
272
- def compose_flow(flow, palps, next_steps, action_class, flow_hash = {})
273
- flow.each_with_index do |(step_id, stp), idx|
274
- case stp[:type]
275
- when Decouplio::Const::Types::STEP_TYPE,
276
- Decouplio::Const::Types::PASS_TYPE,
277
- Decouplio::Const::Types::WRAP_TYPE,
278
- Decouplio::Const::Types::ACTION_TYPE_STEP,
279
- Decouplio::Const::Types::ACTION_TYPE_PASS,
280
- Decouplio::Const::Types::SERVICE_TYPE_STEP,
281
- Decouplio::Const::Types::SERVICE_TYPE_PASS,
282
- Decouplio::Const::Types::RESQ_TYPE_STEP,
283
- Decouplio::Const::Types::RESQ_TYPE_PASS
284
- compose_step_flow(stp, step_id, flow, idx, flow_hash, next_steps)
285
- when Decouplio::Const::Types::FAIL_TYPE,
286
- Decouplio::Const::Types::RESQ_TYPE_FAIL,
287
- Decouplio::Const::Types::ACTION_TYPE_FAIL,
288
- Decouplio::Const::Types::SERVICE_TYPE_FAIL
289
- compose_fail_flow(stp, step_id, flow, idx, flow_hash, next_steps)
290
- when Decouplio::Const::Types::IF_TYPE_PASS, Decouplio::Const::Types::UNLESS_TYPE_PASS
291
- compose_pass_condition_flow(stp, flow, idx, flow_hash)
292
- when Decouplio::Const::Types::IF_TYPE_FAIL, Decouplio::Const::Types::UNLESS_TYPE_FAIL
293
- compose_fail_condition_flow(stp, flow, idx, flow_hash)
294
- when Decouplio::Const::Types::OCTO_TYPE
295
- compose_octo_flow(stp, step_id, idx, flow, palps, flow_hash, action_class)
296
- end
297
- end
298
- end
299
-
300
- def compose_step_flow(stp, step_id, flow, idx, flow_hash, next_steps)
301
- flow_values = flow.values + (next_steps&.values || [])
302
- stp[:flow][Decouplio::Const::Results::PASS] = next_success_step(
303
- flow_values,
304
- idx,
305
- flow[step_id][:on_success]
306
- )
307
- stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(
308
- flow_values,
309
- idx,
310
- flow[step_id][:on_failure]
311
- )
312
- stp[:flow][Decouplio::Const::Results::ERROR] = next_failure_step(
313
- flow_values,
314
- idx,
315
- flow[step_id][:on_error]
316
- )
317
- stp[:flow][Decouplio::Const::Results::PASS] ||= flow_hash[Decouplio::Const::Results::PASS]
318
- stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
319
- stp[:flow][Decouplio::Const::Results::ERROR] ||= flow_hash[Decouplio::Const::Results::ERROR]
320
- stp[:flow][Decouplio::Const::Results::FINISH_HIM] = Decouplio::Const::Results::NO_STEP
321
- end
322
-
323
- def compose_fail_flow(stp, step_id, flow, idx, flow_hash, next_steps)
324
- flow_values = flow.values + (next_steps&.values || [])
325
- stp[:flow][Decouplio::Const::Results::PASS] = next_failure_step(
326
- flow_values,
327
- idx,
328
- flow[step_id][:on_success]
329
- )
330
- stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(
331
- flow_values,
332
- idx,
333
- flow[step_id][:on_failure]
334
- )
335
- stp[:flow][Decouplio::Const::Results::ERROR] = next_failure_step(
336
- flow_values,
337
- idx,
338
- flow[step_id][:on_error]
339
- )
340
- stp[:flow][Decouplio::Const::Results::PASS] ||= flow_hash[Decouplio::Const::Results::FAIL]
341
- stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
342
- stp[:flow][Decouplio::Const::Results::ERROR] ||= flow_hash[Decouplio::Const::Results::ERROR]
343
- stp[:flow][Decouplio::Const::Results::FINISH_HIM] = Decouplio::Const::Results::NO_STEP
344
- end
345
-
346
- def compose_pass_condition_flow(stp, flow, idx, flow_hash)
347
- stp[:flow][Decouplio::Const::Results::PASS] = next_success_step(flow.values, idx, nil)
348
- stp[:flow][Decouplio::Const::Results::FAIL] = next_success_step(flow.values, idx + 1, nil)
349
- stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::PASS]
350
- end
351
-
352
- def compose_fail_condition_flow(stp, flow, idx, flow_hash)
353
- stp[:flow][Decouplio::Const::Results::PASS] = next_failure_step(flow.values, idx, nil)
354
- stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(flow.values, idx + 1, nil)
355
- stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
356
- end
357
-
358
- def compose_octo_flow(stp, step_id, idx, flow, palps, flow_hash, action_class)
359
- stp[:flow][Decouplio::Const::Results::PASS] = next_success_step(
360
- flow.values,
361
- idx,
362
- flow[step_id][:on_success]
363
- )
364
- stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(
365
- flow.values,
366
- idx,
367
- flow[step_id][:on_failure]
368
- )
369
- stp[:flow][Decouplio::Const::Results::PASS] ||= flow_hash[Decouplio::Const::Results::PASS]
370
- stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
371
- stp[:flow][Decouplio::Const::Results::FINISH_HIM] = Decouplio::Const::Results::NO_STEP
372
- stp = compose_strategy(stp, palps, flow.to_a[(idx + 1)..].to_h, action_class)
373
- stp[:hash_case].each do |strategy_key, strategy_raw_data|
374
- stp[:flow][strategy_key] = strategy_raw_data[:first_step]
375
- end
376
- end
377
-
378
- def success_type(flow, stp)
379
- return :finish_him if [:on_success, true].include?(finish_him(stp))
380
-
381
- step_id = stp.dig(:flow, Decouplio::Const::Results::PASS)
382
- if step_id.nil? && Decouplio::Const::Results::STEP_PASS == stp[:on_success]
383
- Decouplio::Const::Results::STEP_PASS
384
- elsif step_id.nil? && Decouplio::Const::Results::STEP_FAIL == stp[:on_success]
385
- Decouplio::Const::Results::STEP_FAIL
386
- else
387
- Decouplio::Const::Types::PASS_FLOW.include?(
388
- flow[step_id]&.[](:type)
389
- )
390
- end
391
- end
392
-
393
- def failure_type(flow, stp)
394
- return :finish_him if [:on_failure, true].include?(finish_him(stp))
395
-
396
- step_id = stp.dig(:flow, Decouplio::Const::Results::FAIL)
397
- if step_id.nil? && Decouplio::Const::Results::STEP_PASS == stp[:on_failure]
398
- Decouplio::Const::Results::STEP_PASS
399
- elsif step_id.nil? && Decouplio::Const::Results::STEP_FAIL == stp[:on_failure]
400
- Decouplio::Const::Results::STEP_FAIL
401
- else
402
- Decouplio::Const::Types::FAIL_FLOW.include?(
403
- flow[step_id]&.[](:type)
404
- )
405
- end
406
- end
407
-
408
- def error_type(flow, stp)
409
- return :finish_him if [:on_error].include?(finish_him(stp))
410
-
411
- step_id = stp.dig(:flow, Decouplio::Const::Results::ERROR)
412
- if step_id.nil? && Decouplio::Const::Results::STEP_PASS == stp[:on_error]
413
- Decouplio::Const::Results::STEP_PASS
414
- elsif step_id.nil? && Decouplio::Const::Results::STEP_FAIL == stp[:on_error]
415
- Decouplio::Const::Results::STEP_FAIL
416
- else
417
- Decouplio::Const::Types::FAIL_FLOW.include?(
418
- flow[step_id]&.[](:type)
419
- )
420
- end
421
- end
422
-
423
- def finish_him(stp)
424
- if stp[:on_success] == :finish_him
425
- :on_success
426
- elsif stp[:on_failure] == :finish_him
427
- :on_failure
428
- elsif stp.key?(:finish_him)
429
- stp[:finish_him]
430
- end
431
- end
432
-
433
- def compose_wrap(stp, action_class)
434
- if Decouplio::Const::Types::WRAP_TYPE == stp[:type]
435
- stp[:wrap_flow] = Flow.call(logic: stp[:wrap_flow], action_class: action_class)
436
- elsif Decouplio::Const::Types::WRAP_TYPE == stp.dig(:step_to_resq, :type)
437
- stp[:step_to_resq][:wrap_flow] = Flow.call(logic: stp[:step_to_resq][:wrap_flow], action_class: action_class)
438
- end
439
-
440
- stp
441
- end
442
-
443
- def compose_condition(stp, palp_prefix, flow)
444
- condition_options = stp.slice(:if, :unless)
445
-
446
- return if condition_options.empty?
447
-
448
- Decouplio::Validators::Condition.validate(
449
- condition_options: condition_options,
450
- type: stp[:type]
451
- )
452
-
453
- condition = ([%i[name type]] + condition_options.invert.to_a).transpose.to_h
454
- condition[:step_id] = random_id(name: condition[:name], palp_prefix: palp_prefix, flow: flow)
455
- condition[:type] = Decouplio::Const::Types::STEP_TYPE_TO_CONDITION_TYPE.dig(stp[:type], condition[:type])
456
- condition[:flow] = {}
457
- condition
458
- end
459
-
460
- def compose_action(stp)
461
- return stp if Decouplio::Const::Types::ACTION_NOT_ALLOWED_STEPS.include?(stp[:type])
462
-
463
- if !stp[:name].is_a?(Symbol) && stp[:name] < Decouplio::Action
464
- stp[:action] = stp[:name]
465
- stp[:name] = stp[:name].name.to_sym
466
- elsif stp[:name].is_a?(Class) && stp[:name].respond_to?(:call)
467
- stp[:service] = stp[:name]
468
- stp[:name] = stp[:name].name.to_sym
469
- elsif stp.dig(:step_to_resq, :name) &&
470
- !stp.dig(:step_to_resq, :name).is_a?(Symbol) &&
471
- stp.dig(:step_to_resq, :name) < Decouplio::Action
472
- stp[:step_to_resq][:action] = stp[:step_to_resq][:name]
473
- stp[:step_to_resq][:name] = stp[:step_to_resq][:name].name.to_sym
474
- elsif stp.dig(:step_to_resq, :name).is_a?(Class) && stp.dig(:step_to_resq, :name).respond_to?(:call)
475
- stp[:step_to_resq][:service] = stp[:step_to_resq][:name]
476
- stp[:step_to_resq][:name] = stp[:step_to_resq][:name].name.to_sym
477
- elsif stp[:name].is_a?(Class)
478
- stp[:action] = stp[:name]
479
- elsif stp.dig(:step_to_resq, :name).is_a?(Class)
480
- stp[:step_to_resq][:action] = stp.dig(:step_to_resq, :name)
481
- end
482
-
483
- if stp.key?(:action)
484
- stp[:type] = Decouplio::Const::Types::STEP_TYPE_TO_INNER_TYPE[stp[:type]]
485
- elsif stp.dig(:step_to_resq, :action)
486
- stp[:step_to_resq][:type] = Decouplio::Const::Types::STEP_TYPE_TO_INNER_TYPE[stp[:type]]
487
- end
488
-
489
- if stp.key?(:service)
490
- stp[:type] = Decouplio::Const::Types::STEP_TYPE_TO_SERVICE_TYPE[stp[:type]]
491
- elsif stp.dig(:step_to_resq, :service)
492
- stp[:step_to_resq][:type] = Decouplio::Const::Types::STEP_TYPE_TO_SERVICE_TYPE[stp[:type]]
493
- end
494
-
495
- stp
496
- end
497
-
498
- def compose_strategy(stp, palps, next_steps, action_class)
499
- return stp unless stp[:type] == Decouplio::Const::Types::OCTO_TYPE
500
-
501
- stp[:hash_case] = stp[:hash_case].to_h do |strategy_key, options|
502
- strategy_flow = compose(
503
- logic_container_raw_data: palps[options[:palp]],
504
- action_class: action_class,
505
- palp_prefix: options[:palp],
506
- parent_flow: stp[:flow],
507
- next_steps: next_steps
508
- )
509
- [
510
- strategy_key,
511
- strategy_flow
512
- ]
513
- end
514
- stp
515
- end
516
-
517
- def compose_resq(stp, palp_prefix, flow)
518
- return stp unless stp[:type] == Decouplio::Const::Types::RESQ_TYPE
519
-
520
- options_for_resq = stp[:step_to_resq].slice(
521
- :on_success,
522
- :on_failure,
523
- :on_error,
524
- :finish_him,
525
- :if,
526
- :unless
527
- )
528
- stp[:step_id] = random_id(name: stp[:name], palp_prefix: palp_prefix, flow: flow)
529
- stp[:flow] = {}
530
- handler_hash = {}
531
- stp[:handler_hash].each do |handler_method, error_classes|
532
- [error_classes].flatten.each do |error_class|
533
- handler_hash[error_class] = handler_method
534
- end
535
- end
536
- stp[:handler_hash] = handler_hash
537
- stp[:type] = Decouplio::Const::Types::STEP_TYPE_TO_RESQ_TYPE[stp[:step_to_resq][:type]]
538
- stp.merge(options_for_resq)
539
- end
540
-
541
- def next_success_step(steps, idx, value)
542
- steps_slice = steps[(idx + 1)..]
543
- steps_slice.each_with_index do |stp, index|
544
- if (
545
- Decouplio::Const::Results::STEP_PASS == value &&
546
- Decouplio::Const::Types::SUCCESS_TRACK_STEP_TYPES.include?(stp[:type])
547
- ) || (
548
- Decouplio::Const::Results::STEP_FAIL == value &&
549
- Decouplio::Const::Types::FAILURE_TRACK_STEP_TYPES.include?(stp[:type])
550
- ) || (
551
- !value &&
552
- Decouplio::Const::Types::SUCCESS_TRACK_STEP_TYPES.include?(stp[:type])
553
- )
554
- return stp[:step_id]
555
- elsif value == stp[:name]
556
- prev_step = steps_slice[index - 1]
557
- if [
558
- Decouplio::Const::Types::IF_TYPE_PASS,
559
- Decouplio::Const::Types::UNLESS_TYPE_PASS
560
- ].include?(prev_step[:type])
561
- return prev_step[:step_id]
562
- else
563
- return stp[:step_id]
564
- end
565
- end
566
- end
567
-
568
- Decouplio::Const::Results::NO_STEP
569
- end
570
-
571
- def next_failure_step(steps, idx, value)
572
- steps_slice = steps[(idx + 1)..]
573
- steps_slice.each_with_index do |stp, index|
574
- if (
575
- Decouplio::Const::Results::STEP_PASS == value &&
576
- Decouplio::Const::Types::SUCCESS_TRACK_STEP_TYPES.include?(stp[:type])
577
- ) || (
578
- Decouplio::Const::Results::STEP_FAIL == value &&
579
- Decouplio::Const::Types::FAILURE_TRACK_STEP_TYPES.include?(stp[:type])
580
- ) || (
581
- !value &&
582
- Decouplio::Const::Types::FAILURE_TRACK_STEP_TYPES.include?(stp[:type])
583
- )
584
- return stp[:step_id]
585
- elsif value == stp[:name]
586
- prev_step = steps_slice[index - 1]
587
- if [
588
- Decouplio::Const::Types::IF_TYPE_FAIL,
589
- Decouplio::Const::Types::UNLESS_TYPE_FAIL
590
- ].include?(prev_step[:type])
591
- return prev_step[:step_id]
592
- else
593
- return stp[:step_id]
594
- end
595
- end
596
- end
597
-
598
- Decouplio::Const::Results::NO_STEP
599
- end
600
-
601
- def random_id(name:, palp_prefix:, flow:)
602
- loop do
603
- random_step_id =
604
- "#{palp_prefix}_#{name}_#{random_value}#{random_value}#{random_value}#{random_value}#{random_value}".to_sym
605
-
606
- break random_step_id if flow.select { |stp| stp[:step_id] == random_step_id }.empty?
607
- end
608
- end
609
-
610
- def random_value
611
- (10..99).to_a.sample
612
- end
613
- end
614
- end
615
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decouplio
4
- module Const
5
- module Colors
6
- BLACK = "\033[0;30m"
7
- DARK_GRAY = "\033[1;30m"
8
- RED = "\033[0;31m"
9
- LIGHT_RED = "\033[1;31m"
10
- GREEN = "\033[0;32m"
11
- LIGHT_GREEN = "\033[1;32m"
12
- BROWN_ORANGE = "\033[0;33m"
13
- YELLOW = "\033[1;33m"
14
- BLUE = "\033[0;34m"
15
- LIGHT_BLUE = "\033[1;34m"
16
- PURPLE = "\033[0;35m"
17
- LIGHT_PURPLE = "\033[1;35m"
18
- CYAN = "\033[0;36m"
19
- LIGHT_CYAN = "\033[1;36m"
20
- LIGHT_GRAY = "\033[0;37m"
21
- WHITE = "\033[1;37m"
22
- NO_COLOR = "\033[0m"
23
- end
24
- end
25
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decouplio
4
- module Const
5
- module Results
6
- PASS = true
7
- FAIL = false
8
- ERROR = :error
9
- FINISH_HIM = :finish_him
10
- NO_STEP = nil
11
- STEP_PASS = :PASS
12
- STEP_FAIL = :FAIL
13
- end
14
- end
15
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decouplio
4
- module Const
5
- module StepOptions
6
- ALLOWED = %i[
7
- on_success
8
- on_failure
9
- on_error
10
- finish_him
11
- if
12
- unless
13
- ].freeze
14
- end
15
- end
16
- end
@@ -1,26 +0,0 @@
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 ExtraKeyForFailError < Decouplio::Errors::BaseError
9
- def template
10
- Decouplio::Const::Validations::Fail::VALIDATION_ERROR_MESSAGE
11
- end
12
-
13
- def interpolation_values
14
- [
15
- @errored_option,
16
- format(
17
- Decouplio::Const::Validations::Fail::OPTIONS_IS_NOT_ALLOWED,
18
- @details
19
- ),
20
- Decouplio::Const::Validations::Fail::ALLOWED_OPTIONS_MESSAGE,
21
- Decouplio::Const::Validations::Fail::MANUAL_URL
22
- ]
23
- end
24
- end
25
- end
26
- end