decouplio 1.0.0alpha4 → 1.0.0alpha8
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/.rubocop.yml +6 -11
- data/.ruby-version +1 -1
- data/decouplio.gemspec +1 -1
- data/lib/decouplio/action.rb +16 -42
- data/lib/decouplio/action_state_printer.rb +37 -0
- data/lib/decouplio/composer.rb +3 -76
- data/lib/decouplio/const/{doby_aide_options.rb → step_options.rb} +2 -1
- data/lib/decouplio/const/types.rb +7 -27
- data/lib/decouplio/default_meta_store.rb +39 -0
- data/lib/decouplio/logic_dsl.rb +53 -35
- data/lib/decouplio/options_validator.rb +1 -110
- data/lib/decouplio/steps/inner_action_fail.rb +5 -3
- data/lib/decouplio/steps/inner_action_pass.rb +7 -5
- data/lib/decouplio/steps/inner_action_step.rb +5 -3
- data/lib/decouplio/steps/service_fail.rb +4 -2
- data/lib/decouplio/steps/service_pass.rb +4 -2
- data/lib/decouplio/steps/service_step.rb +4 -2
- data/lib/decouplio/validators/condition.rb +0 -10
- data/lib/decouplio/version.rb +1 -1
- metadata +8 -18
- 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 -24
- 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/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/steps/aide.rb +0 -37
- data/lib/decouplio/steps/doby.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13faf170a6cfce8a57a5263eb8ba404ee1ceadcda93990c9c780987bd6a79a8e
|
4
|
+
data.tar.gz: 18e855d3cbf016a0e1976e72147309db0ec0e91d764b1c7988cdb7172868c804
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53426aa0ac2fdd513d7fb80dea55e4e5e1425b3ef08912fe53f3fefbdfa25773d8fa3dce9dc8a84efec89c8078f42756af1b741a34f9d937050a823f577bdfad
|
7
|
+
data.tar.gz: 5209925b7857efa198cae3f9e2ceb1341cd160944ab9855557fea6bacb1762c3239f0b08a33abf837d5d610de36d157a761c132b053eed25b07c676ceaaf191d
|
data/.rubocop.yml
CHANGED
@@ -75,7 +75,6 @@ Lint/ConstantDefinitionInBlock:
|
|
75
75
|
- spec/fail_spec.rb
|
76
76
|
- spec/palp_block_spec.rb
|
77
77
|
- spec/wrap_block_spec.rb
|
78
|
-
- spec/error_store_for_inner_step_spec.rb
|
79
78
|
|
80
79
|
RSpec/LeakyConstantDeclaration:
|
81
80
|
Exclude:
|
@@ -83,16 +82,6 @@ RSpec/LeakyConstantDeclaration:
|
|
83
82
|
- spec/fail_spec.rb
|
84
83
|
- spec/palp_block_spec.rb
|
85
84
|
- spec/wrap_block_spec.rb
|
86
|
-
- spec/error_store_for_inner_step_spec.rb
|
87
|
-
|
88
|
-
RSpec/FilePath:
|
89
|
-
Exclude:
|
90
|
-
- spec/default_error_handler_spec.rb
|
91
|
-
|
92
|
-
RSpec/ExampleLength:
|
93
|
-
Max: 15
|
94
|
-
Exclude:
|
95
|
-
- spec/default_error_handler_spec.rb
|
96
85
|
|
97
86
|
RSpec/MultipleExpectations:
|
98
87
|
Enabled: false
|
@@ -111,3 +100,9 @@ Naming/MethodParameterName:
|
|
111
100
|
|
112
101
|
Naming/RescuedExceptionsVariableName:
|
113
102
|
Enabled: false
|
103
|
+
|
104
|
+
Layout/LineContinuationSpacing:
|
105
|
+
Enabled: false
|
106
|
+
|
107
|
+
RSpec/ExampleLength:
|
108
|
+
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.7.
|
1
|
+
2.7.6
|
data/decouplio.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
|
13
13
|
spec.summary = 'Gem for business logic encapsulation'
|
14
14
|
spec.description = "Decouplio is a zero dependency, thread safe and framework agnostic gem designed to encapsulate application business logic. It's reverse engineered through TDD and inspired by such frameworks and gems like Trailblazer, Interactor."
|
15
|
-
spec.homepage = 'https://github.
|
15
|
+
spec.homepage = 'https://differencialx.github.io/decouplio.github.io/'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
18
18
|
if spec.respond_to?(:metadata)
|
data/lib/decouplio/action.rb
CHANGED
@@ -3,25 +3,23 @@
|
|
3
3
|
require 'forwardable'
|
4
4
|
require_relative 'flow'
|
5
5
|
require_relative 'processor'
|
6
|
-
require_relative '
|
6
|
+
require_relative 'default_meta_store'
|
7
|
+
require_relative 'action_state_printer'
|
7
8
|
require_relative 'errors/logic_redefinition_error'
|
8
9
|
require_relative 'errors/logic_is_not_defined_error'
|
9
|
-
require_relative 'errors/error_store_error'
|
10
10
|
require_relative 'errors/execution_error'
|
11
11
|
require_relative 'const/results'
|
12
12
|
|
13
13
|
module Decouplio
|
14
14
|
class Action
|
15
|
-
|
15
|
+
attr_reader :railway_flow, :ctx, :meta_store
|
16
16
|
|
17
|
-
|
18
|
-
def_delegators :@error_store, :errors, :add_error
|
19
|
-
attr_reader :railway_flow, :ctx, :error_store
|
17
|
+
alias ms meta_store
|
20
18
|
|
21
19
|
def initialize(
|
22
|
-
parent_railway_flow: nil, parent_ctx: nil,
|
20
|
+
parent_railway_flow: nil, parent_ctx: nil, meta_store:, **params
|
23
21
|
)
|
24
|
-
@
|
22
|
+
@meta_store = meta_store
|
25
23
|
@ctx = parent_ctx || params
|
26
24
|
@railway_flow = parent_railway_flow || []
|
27
25
|
@failure = false
|
@@ -47,39 +45,12 @@ module Decouplio
|
|
47
45
|
@failure = false
|
48
46
|
end
|
49
47
|
|
50
|
-
def previous_step
|
51
|
-
railway_flow[PREVIOUS_STEP_INDEX]
|
52
|
-
end
|
53
|
-
|
54
48
|
def append_railway_flow(stp)
|
55
49
|
railway_flow << stp
|
56
50
|
end
|
57
51
|
|
58
52
|
def inspect
|
59
|
-
|
60
|
-
Result: #{success? ? 'success' : 'failure'}
|
61
|
-
|
62
|
-
Railway Flow:
|
63
|
-
#{railway_flow.join(' -> ')}
|
64
|
-
|
65
|
-
Context:
|
66
|
-
#{ctx.map { |k, v| "#{k.inspect} => #{v.inspect}" }.join("\n ")}
|
67
|
-
|
68
|
-
Errors:
|
69
|
-
#{
|
70
|
-
if errors.is_a?(Hash)
|
71
|
-
if errors.empty?
|
72
|
-
'None'
|
73
|
-
else
|
74
|
-
errors.map do |k, v|
|
75
|
-
"#{k.inspect} => #{v.inspect}"
|
76
|
-
end.join("\n ")
|
77
|
-
end
|
78
|
-
else
|
79
|
-
errors
|
80
|
-
end
|
81
|
-
}
|
82
|
-
INSPECT
|
53
|
+
Decouplio::ActionStatePrinter.call(self)
|
83
54
|
end
|
84
55
|
|
85
56
|
def to_s
|
@@ -87,16 +58,19 @@ module Decouplio
|
|
87
58
|
end
|
88
59
|
|
89
60
|
class << self
|
90
|
-
attr_accessor :
|
61
|
+
attr_accessor :meta_store
|
91
62
|
|
92
|
-
def
|
93
|
-
self.
|
63
|
+
def meta_store_class(klass)
|
64
|
+
self.meta_store = klass
|
94
65
|
end
|
95
66
|
|
96
67
|
def call(**params)
|
97
|
-
instance = new(
|
68
|
+
instance = new(
|
69
|
+
**{
|
70
|
+
meta_store: meta_store.new
|
71
|
+
}.merge(**params)
|
72
|
+
)
|
98
73
|
Decouplio::Processor.call(instance: instance, **@flow)
|
99
|
-
# TODO: process block with after actions
|
100
74
|
instance
|
101
75
|
end
|
102
76
|
|
@@ -114,7 +88,7 @@ module Decouplio
|
|
114
88
|
private
|
115
89
|
|
116
90
|
def inherited(child_class)
|
117
|
-
child_class.
|
91
|
+
child_class.meta_store = meta_store || Decouplio::DefaultMetaStore
|
118
92
|
end
|
119
93
|
|
120
94
|
def logic(&block)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decouplio
|
4
|
+
class ActionStatePrinter
|
5
|
+
def self.call(action)
|
6
|
+
<<~INSPECT
|
7
|
+
|
8
|
+
Result: #{result(action)}
|
9
|
+
|
10
|
+
RailwayFlow:
|
11
|
+
#{railway_flow(action)}
|
12
|
+
|
13
|
+
Context:
|
14
|
+
#{action_context(action)}
|
15
|
+
|
16
|
+
#{meta_store(action)}
|
17
|
+
|
18
|
+
INSPECT
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.result(action)
|
22
|
+
action.success? ? 'success' : 'failure'
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.railway_flow(action)
|
26
|
+
action.railway_flow.join(' -> ')
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.action_context(action)
|
30
|
+
action.ctx.map { |k, v| "#{k.inspect} => #{v.inspect}" }.join("\n ")
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.meta_store(action)
|
34
|
+
action.ms.to_s
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/decouplio/composer.rb
CHANGED
@@ -20,8 +20,6 @@ require_relative 'steps/inner_action_pass'
|
|
20
20
|
require_relative 'steps/service_step'
|
21
21
|
require_relative 'steps/service_fail'
|
22
22
|
require_relative 'steps/service_pass'
|
23
|
-
require_relative 'steps/doby'
|
24
|
-
require_relative 'steps/aide'
|
25
23
|
require_relative 'options_validator'
|
26
24
|
require_relative 'validators/condition'
|
27
25
|
|
@@ -129,10 +127,6 @@ module Decouplio
|
|
129
127
|
create_inner_service_fail(stp, flow)
|
130
128
|
when Decouplio::Const::Types::SERVICE_TYPE_PASS
|
131
129
|
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
130
|
end
|
137
131
|
end
|
138
132
|
|
@@ -249,6 +243,7 @@ module Decouplio
|
|
249
243
|
Decouplio::Steps::ServiceStep.new(
|
250
244
|
name: stp[:name],
|
251
245
|
service: stp[:service],
|
246
|
+
args: stp[:_args],
|
252
247
|
on_success_type: success_type(flow, stp),
|
253
248
|
on_failure_type: failure_type(flow, stp)
|
254
249
|
)
|
@@ -258,6 +253,7 @@ module Decouplio
|
|
258
253
|
Decouplio::Steps::ServiceFail.new(
|
259
254
|
name: stp[:name],
|
260
255
|
service: stp[:service],
|
256
|
+
args: stp[:_args],
|
261
257
|
on_success_type: success_type(flow, stp),
|
262
258
|
on_failure_type: failure_type(flow, stp)
|
263
259
|
)
|
@@ -267,26 +263,7 @@ module Decouplio
|
|
267
263
|
Decouplio::Steps::ServicePass.new(
|
268
264
|
name: stp[:name],
|
269
265
|
service: stp[:service],
|
270
|
-
|
271
|
-
on_failure_type: failure_type(flow, stp)
|
272
|
-
)
|
273
|
-
end
|
274
|
-
|
275
|
-
def create_doby(stp, flow)
|
276
|
-
Decouplio::Steps::Doby.new(
|
277
|
-
name: stp[:name],
|
278
|
-
doby_class: stp[:doby_class],
|
279
|
-
doby_options: stp[:doby_options],
|
280
|
-
on_success_type: success_type(flow, stp),
|
281
|
-
on_failure_type: failure_type(flow, stp)
|
282
|
-
)
|
283
|
-
end
|
284
|
-
|
285
|
-
def create_aide(stp, flow)
|
286
|
-
Decouplio::Steps::Aide.new(
|
287
|
-
name: stp[:name],
|
288
|
-
aide_class: stp[:aide_class],
|
289
|
-
aide_options: stp[:aide_options],
|
266
|
+
args: stp[:_args],
|
290
267
|
on_success_type: success_type(flow, stp),
|
291
268
|
on_failure_type: failure_type(flow, stp)
|
292
269
|
)
|
@@ -310,10 +287,6 @@ module Decouplio
|
|
310
287
|
Decouplio::Const::Types::ACTION_TYPE_FAIL,
|
311
288
|
Decouplio::Const::Types::SERVICE_TYPE_FAIL
|
312
289
|
compose_fail_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
313
|
-
when Decouplio::Const::Types::DOBY_TYPE
|
314
|
-
compose_doby_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
315
|
-
when Decouplio::Const::Types::AIDE_TYPE
|
316
|
-
compose_aide_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
317
290
|
when Decouplio::Const::Types::IF_TYPE_PASS, Decouplio::Const::Types::UNLESS_TYPE_PASS
|
318
291
|
compose_pass_condition_flow(stp, flow, idx, flow_hash)
|
319
292
|
when Decouplio::Const::Types::IF_TYPE_FAIL, Decouplio::Const::Types::UNLESS_TYPE_FAIL
|
@@ -347,52 +320,6 @@ module Decouplio
|
|
347
320
|
stp[:flow][Decouplio::Const::Results::FINISH_HIM] = Decouplio::Const::Results::NO_STEP
|
348
321
|
end
|
349
322
|
|
350
|
-
def compose_doby_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
351
|
-
flow_values = flow.values + (next_steps&.values || [])
|
352
|
-
stp[:flow][Decouplio::Const::Results::PASS] = next_success_step(
|
353
|
-
flow_values,
|
354
|
-
idx,
|
355
|
-
flow[step_id][:on_success]
|
356
|
-
)
|
357
|
-
stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(
|
358
|
-
flow_values,
|
359
|
-
idx,
|
360
|
-
flow[step_id][:on_failure]
|
361
|
-
)
|
362
|
-
stp[:flow][Decouplio::Const::Results::ERROR] = next_failure_step(
|
363
|
-
flow_values,
|
364
|
-
idx,
|
365
|
-
flow[step_id][:on_error]
|
366
|
-
)
|
367
|
-
stp[:flow][Decouplio::Const::Results::PASS] ||= flow_hash[Decouplio::Const::Results::PASS]
|
368
|
-
stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
|
369
|
-
stp[:flow][Decouplio::Const::Results::ERROR] ||= flow_hash[Decouplio::Const::Results::ERROR]
|
370
|
-
stp[:flow][Decouplio::Const::Results::FINISH_HIM] = Decouplio::Const::Results::NO_STEP
|
371
|
-
end
|
372
|
-
|
373
|
-
def compose_aide_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
374
|
-
flow_values = flow.values + (next_steps&.values || [])
|
375
|
-
stp[:flow][Decouplio::Const::Results::PASS] = next_failure_step(
|
376
|
-
flow_values,
|
377
|
-
idx,
|
378
|
-
flow[step_id][:on_success]
|
379
|
-
)
|
380
|
-
stp[:flow][Decouplio::Const::Results::FAIL] = next_failure_step(
|
381
|
-
flow_values,
|
382
|
-
idx,
|
383
|
-
flow[step_id][:on_failure]
|
384
|
-
)
|
385
|
-
stp[:flow][Decouplio::Const::Results::ERROR] = next_failure_step(
|
386
|
-
flow_values,
|
387
|
-
idx,
|
388
|
-
flow[step_id][:on_error]
|
389
|
-
)
|
390
|
-
stp[:flow][Decouplio::Const::Results::PASS] ||= flow_hash[Decouplio::Const::Results::FAIL]
|
391
|
-
stp[:flow][Decouplio::Const::Results::FAIL] ||= flow_hash[Decouplio::Const::Results::FAIL]
|
392
|
-
stp[:flow][Decouplio::Const::Results::ERROR] ||= flow_hash[Decouplio::Const::Results::ERROR]
|
393
|
-
stp[:flow][Decouplio::Const::Results::FINISH_HIM] = Decouplio::Const::Results::NO_STEP
|
394
|
-
end
|
395
|
-
|
396
323
|
def compose_fail_flow(stp, step_id, flow, idx, flow_hash, next_steps)
|
397
324
|
flow_values = flow.values + (next_steps&.values || [])
|
398
325
|
stp[:flow][Decouplio::Const::Results::PASS] = next_failure_step(
|
@@ -13,8 +13,6 @@ module Decouplio
|
|
13
13
|
IF_TYPE_FAIL = :if_fail
|
14
14
|
UNLESS_TYPE_FAIL = :unless_fail
|
15
15
|
OCTO_TYPE = :octo
|
16
|
-
DOBY_TYPE = :doby
|
17
|
-
AIDE_TYPE = :aide
|
18
16
|
ACTION_TYPE_STEP = :action_step
|
19
17
|
ACTION_TYPE_FAIL = :action_fail
|
20
18
|
ACTION_TYPE_PASS = :action_pass
|
@@ -82,14 +80,6 @@ module Decouplio
|
|
82
80
|
SERVICE_TYPE_PASS => {
|
83
81
|
IF_TYPE => IF_TYPE_PASS,
|
84
82
|
UNLESS_TYPE => UNLESS_TYPE_PASS
|
85
|
-
},
|
86
|
-
DOBY_TYPE => {
|
87
|
-
IF_TYPE => IF_TYPE_PASS,
|
88
|
-
UNLESS_TYPE => UNLESS_TYPE_PASS
|
89
|
-
},
|
90
|
-
AIDE_TYPE => {
|
91
|
-
IF_TYPE => IF_TYPE_FAIL,
|
92
|
-
UNLESS_TYPE => UNLESS_TYPE_FAIL
|
93
83
|
}
|
94
84
|
}.freeze
|
95
85
|
STEP_TYPE_TO_RESQ_TYPE = {
|
@@ -101,9 +91,7 @@ module Decouplio
|
|
101
91
|
IF_TYPE_PASS => RESQ_TYPE_STEP,
|
102
92
|
UNLESS_TYPE_PASS => RESQ_TYPE_STEP,
|
103
93
|
IF_TYPE_FAIL => RESQ_TYPE_FAIL,
|
104
|
-
UNLESS_TYPE_FAIL => RESQ_TYPE_FAIL
|
105
|
-
DOBY_TYPE => RESQ_TYPE_STEP,
|
106
|
-
AIDE_TYPE => RESQ_TYPE_FAIL
|
94
|
+
UNLESS_TYPE_FAIL => RESQ_TYPE_FAIL
|
107
95
|
}.freeze
|
108
96
|
STEP_TYPE_TO_INNER_TYPE = {
|
109
97
|
STEP_TYPE => ACTION_TYPE_STEP,
|
@@ -124,9 +112,7 @@ module Decouplio
|
|
124
112
|
ACTION_NOT_ALLOWED_STEPS = [
|
125
113
|
OCTO_TYPE,
|
126
114
|
WRAP_TYPE,
|
127
|
-
RESQ_TYPE
|
128
|
-
DOBY_TYPE,
|
129
|
-
AIDE_TYPE
|
115
|
+
RESQ_TYPE
|
130
116
|
].freeze
|
131
117
|
PASS_FLOW = [
|
132
118
|
STEP_TYPE,
|
@@ -138,25 +124,21 @@ module Decouplio
|
|
138
124
|
ACTION_TYPE_PASS,
|
139
125
|
ACTION_TYPE_STEP,
|
140
126
|
SERVICE_TYPE_STEP,
|
141
|
-
SERVICE_TYPE_PASS
|
142
|
-
DOBY_TYPE
|
127
|
+
SERVICE_TYPE_PASS
|
143
128
|
].freeze
|
144
129
|
FAIL_FLOW = [
|
145
130
|
FAIL_TYPE,
|
146
131
|
IF_TYPE_FAIL,
|
147
132
|
UNLESS_TYPE_FAIL,
|
148
133
|
ACTION_TYPE_FAIL,
|
149
|
-
SERVICE_TYPE_FAIL
|
150
|
-
AIDE_TYPE
|
134
|
+
SERVICE_TYPE_FAIL
|
151
135
|
].freeze
|
152
136
|
|
153
137
|
MAIN_FLOW_TYPES = [
|
154
138
|
STEP_TYPE,
|
155
139
|
FAIL_TYPE,
|
156
140
|
PASS_TYPE,
|
157
|
-
WRAP_TYPE
|
158
|
-
DOBY_TYPE,
|
159
|
-
AIDE_TYPE
|
141
|
+
WRAP_TYPE
|
160
142
|
].freeze
|
161
143
|
SUCCESS_TRACK_STEP_TYPES = [
|
162
144
|
STEP_TYPE,
|
@@ -170,8 +152,7 @@ module Decouplio
|
|
170
152
|
SERVICE_TYPE_PASS,
|
171
153
|
RESQ_TYPE_STEP,
|
172
154
|
RESQ_TYPE_PASS,
|
173
|
-
OCTO_TYPE
|
174
|
-
DOBY_TYPE
|
155
|
+
OCTO_TYPE
|
175
156
|
].freeze
|
176
157
|
FAILURE_TRACK_STEP_TYPES = [
|
177
158
|
FAIL_TYPE,
|
@@ -179,8 +160,7 @@ module Decouplio
|
|
179
160
|
UNLESS_TYPE_FAIL,
|
180
161
|
RESQ_TYPE_FAIL,
|
181
162
|
ACTION_TYPE_FAIL,
|
182
|
-
SERVICE_TYPE_FAIL
|
183
|
-
AIDE_TYPE
|
163
|
+
SERVICE_TYPE_FAIL
|
184
164
|
].freeze
|
185
165
|
end
|
186
166
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decouplio
|
4
|
+
class DefaultMetaStore
|
5
|
+
attr_accessor :status
|
6
|
+
attr_reader :errors
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@errors = {}
|
10
|
+
@status = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_error(key, messages)
|
14
|
+
@errors.store(
|
15
|
+
key,
|
16
|
+
(@errors[key] || []) + [messages].flatten
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
<<~METASTORE
|
22
|
+
Status: #{@status || 'NONE'}
|
23
|
+
|
24
|
+
Errors:
|
25
|
+
#{errors_string}
|
26
|
+
METASTORE
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def errors_string
|
32
|
+
return 'NONE' if @errors.empty?
|
33
|
+
|
34
|
+
@errors.map do |k, v|
|
35
|
+
"#{k.inspect} => #{v.inspect}"
|
36
|
+
end.join("\n ")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/decouplio/logic_dsl.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'flow'
|
4
4
|
require_relative 'const/types'
|
5
|
-
require_relative 'const/
|
5
|
+
require_relative 'const/step_options'
|
6
6
|
require_relative 'octo_hash_case'
|
7
7
|
require_relative 'errors/options_validation_error'
|
8
8
|
require_relative 'errors/palp_validation_error'
|
@@ -10,7 +10,6 @@ require_relative 'errors/resq_definition_error'
|
|
10
10
|
require_relative 'errors/wrap_block_is_not_defined_error'
|
11
11
|
require_relative 'errors/palp_block_is_not_defined_error'
|
12
12
|
require_relative 'errors/fail_can_not_be_first_step_error'
|
13
|
-
require_relative 'errors/aide_can_not_be_first_step_error'
|
14
13
|
require_relative 'errors/octo_block_is_not_defined_error'
|
15
14
|
|
16
15
|
module Decouplio
|
@@ -30,17 +29,61 @@ module Decouplio
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def step(stp, **options)
|
33
|
-
|
32
|
+
if stp.is_a?(Class) && !(stp < Decouplio::Action)
|
33
|
+
step_options = {}
|
34
|
+
|
35
|
+
options.each_key do |key|
|
36
|
+
step_options[key] = options.delete(key) if Decouplio::Const::StepOptions::ALLOWED.include?(key)
|
37
|
+
end
|
38
|
+
|
39
|
+
@steps << {
|
40
|
+
type: Decouplio::Const::Types::STEP_TYPE,
|
41
|
+
name: stp,
|
42
|
+
_args: options,
|
43
|
+
**step_options
|
44
|
+
}
|
45
|
+
else
|
46
|
+
@steps << options.merge(type: Decouplio::Const::Types::STEP_TYPE, name: stp)
|
47
|
+
end
|
34
48
|
end
|
35
49
|
|
36
50
|
def fail(stp, **options)
|
37
51
|
raise Decouplio::Errors::FailCanNotBeFirstStepError if @steps.empty?
|
38
52
|
|
39
|
-
|
53
|
+
if stp.is_a?(Class) && !(stp < Decouplio::Action)
|
54
|
+
step_options = {}
|
55
|
+
options.each_key do |key|
|
56
|
+
step_options[key] = options.delete(key) if Decouplio::Const::StepOptions::ALLOWED.include?(key)
|
57
|
+
end
|
58
|
+
|
59
|
+
@steps << {
|
60
|
+
type: Decouplio::Const::Types::FAIL_TYPE,
|
61
|
+
name: stp,
|
62
|
+
_args: options,
|
63
|
+
**step_options
|
64
|
+
}
|
65
|
+
else
|
66
|
+
@steps << options.merge(type: Decouplio::Const::Types::FAIL_TYPE, name: stp)
|
67
|
+
end
|
40
68
|
end
|
41
69
|
|
42
70
|
def pass(stp, **options)
|
43
|
-
|
71
|
+
if stp.is_a?(Class) && !(stp < Decouplio::Action)
|
72
|
+
step_options = {}
|
73
|
+
|
74
|
+
options.each_key do |key|
|
75
|
+
step_options[key] = options.delete(key) if Decouplio::Const::StepOptions::ALLOWED.include?(key)
|
76
|
+
end
|
77
|
+
|
78
|
+
@steps << {
|
79
|
+
type: Decouplio::Const::Types::PASS_TYPE,
|
80
|
+
name: stp,
|
81
|
+
_args: options,
|
82
|
+
**step_options
|
83
|
+
}
|
84
|
+
else
|
85
|
+
@steps << options.merge(type: Decouplio::Const::Types::PASS_TYPE, name: stp)
|
86
|
+
end
|
44
87
|
end
|
45
88
|
|
46
89
|
def octo(octo_name, **options, &block)
|
@@ -85,38 +128,13 @@ module Decouplio
|
|
85
128
|
)
|
86
129
|
end
|
87
130
|
|
88
|
-
def doby(
|
89
|
-
|
90
|
-
|
91
|
-
step_options[key] = options.delete(key) if Decouplio::Const::DobyAideOptions::ALLOWED.include?(key)
|
92
|
-
end
|
93
|
-
doby_options = options
|
94
|
-
|
95
|
-
@steps << {
|
96
|
-
type: Decouplio::Const::Types::DOBY_TYPE,
|
97
|
-
name: doby_class.name.to_sym,
|
98
|
-
doby_class: doby_class,
|
99
|
-
doby_options: doby_options,
|
100
|
-
**step_options
|
101
|
-
}
|
131
|
+
def doby(_doby_class, **_options)
|
132
|
+
raise '"doby" step is deprecated. Please use "step" or "pass" instead. ' \
|
133
|
+
'Just simply replace "doby " with "step " or "pass "'
|
102
134
|
end
|
103
135
|
|
104
|
-
def aide(
|
105
|
-
raise
|
106
|
-
|
107
|
-
step_options = {}
|
108
|
-
options.each_key do |key|
|
109
|
-
step_options[key] = options.delete(key) if Decouplio::Const::DobyAideOptions::ALLOWED.include?(key)
|
110
|
-
end
|
111
|
-
aide_options = options
|
112
|
-
|
113
|
-
@steps << {
|
114
|
-
type: Decouplio::Const::Types::AIDE_TYPE,
|
115
|
-
name: aide_class.name.to_sym,
|
116
|
-
aide_class: aide_class,
|
117
|
-
aide_options: aide_options,
|
118
|
-
**step_options
|
119
|
-
}
|
136
|
+
def aide(_aide_class, **_options)
|
137
|
+
raise '"aide" step is deprecated. Please use "fail". Just simply replace "aide " with "fail "'
|
120
138
|
end
|
121
139
|
end
|
122
140
|
end
|