decouplio 1.0.0alpha2 → 1.0.0alpha5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +11 -1
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -1
- data/README.md +2 -17
- data/benchmarks/multi_step_benchmark.rb +11 -10
- data/benchmarks/single_step_benchmark.rb +1 -1
- data/decouplio.gemspec +4 -4
- data/lib/decouplio/action.rb +12 -0
- data/lib/decouplio/composer.rb +47 -24
- data/lib/decouplio/const/doby_aide_options.rb +16 -0
- data/lib/decouplio/const/error_messages.rb +9 -0
- data/lib/decouplio/const/types.rb +14 -6
- data/lib/decouplio/const/validations/aide.rb +38 -0
- data/lib/decouplio/const/validations/doby.rb +36 -0
- data/lib/decouplio/const/validations/fail.rb +4 -0
- data/lib/decouplio/const/validations/octo.rb +2 -1
- data/lib/decouplio/errors/{deny_can_not_be_first_step_error.rb → aide_can_not_be_first_step_error.rb} +3 -3
- data/lib/decouplio/errors/aide_controversial_keys_error.rb +26 -0
- data/lib/decouplio/errors/aide_finish_him_error.rb +26 -0
- data/lib/decouplio/errors/doby_controversial_keys_error.rb +26 -0
- data/lib/decouplio/errors/doby_finish_him_error.rb +26 -0
- data/lib/decouplio/errors/execution_error.rb +20 -0
- data/lib/decouplio/errors/step_is_not_defined_for_aide_error.rb +26 -0
- data/lib/decouplio/errors/step_is_not_defined_for_doby_error.rb +27 -0
- data/lib/decouplio/errors/step_is_not_defined_for_pass_error.rb +27 -0
- data/lib/decouplio/logic_dsl.rb +23 -8
- data/lib/decouplio/options_validator.rb +157 -13
- data/lib/decouplio/steps/aide.rb +37 -0
- data/lib/decouplio/steps/base_resq.rb +13 -3
- data/lib/decouplio/steps/doby.rb +9 -8
- data/lib/decouplio/steps/octo.rb +7 -2
- data/lib/decouplio/validators/condition.rb +10 -0
- data/lib/decouplio/version.rb +1 -1
- metadata +24 -42
- data/docs/_config.yml +0 -1
- data/docs/benchmarks.md +0 -1
- data/docs/context.md +0 -74
- data/docs/context.rb +0 -62
- data/docs/deny.rb +0 -59
- data/docs/doby.rb +0 -38
- data/docs/doby_deny.md +0 -171
- data/docs/error_store.md +0 -347
- data/docs/error_store.rb +0 -202
- data/docs/fail.md +0 -1159
- data/docs/fail.rb +0 -859
- data/docs/index.md +0 -25
- data/docs/inner_action.md +0 -63
- data/docs/inner_action.rb +0 -43
- data/docs/logic_block.md +0 -25
- data/docs/octo.md +0 -269
- data/docs/octo.rb +0 -164
- data/docs/pass.md +0 -309
- data/docs/pass.rb +0 -213
- data/docs/quick_start.md +0 -71
- data/docs/quick_start.rb +0 -38
- data/docs/resq.md +0 -263
- data/docs/resq.rb +0 -176
- data/docs/step.md +0 -885
- data/docs/step.rb +0 -627
- data/docs/step_as_a_service.md +0 -123
- data/docs/step_as_a_service.rb +0 -77
- data/docs/wrap.md +0 -240
- data/docs/wrap.rb +0 -137
- data/lib/decouplio/const/validations/deny.rb +0 -11
- data/lib/decouplio/steps/deny.rb +0 -31
data/lib/decouplio/steps/octo.rb
CHANGED
@@ -7,15 +7,20 @@ module Decouplio
|
|
7
7
|
class Octo < BaseStep
|
8
8
|
attr_accessor :hash_case
|
9
9
|
|
10
|
-
def initialize(name:, ctx_key:)
|
10
|
+
def initialize(name:, ctx_key:, method:)
|
11
11
|
super()
|
12
12
|
@name = name
|
13
13
|
@ctx_key = ctx_key
|
14
|
+
@method = method
|
14
15
|
end
|
15
16
|
|
16
17
|
def process(instance:)
|
17
18
|
instance.append_railway_flow(@name)
|
18
|
-
|
19
|
+
if @method
|
20
|
+
instance.send(@method, **instance.ctx)
|
21
|
+
else
|
22
|
+
instance[@ctx_key]
|
23
|
+
end
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
@@ -42,6 +42,16 @@ module Decouplio
|
|
42
42
|
errored_option: condition_options.to_s,
|
43
43
|
details: %i[if unless]
|
44
44
|
)
|
45
|
+
when Decouplio::Const::Types::DOBY_TYPE
|
46
|
+
raise Decouplio::Errors::DobyControversialKeysError.new(
|
47
|
+
errored_option: condition_options.to_s,
|
48
|
+
details: %i[if unless]
|
49
|
+
)
|
50
|
+
when Decouplio::Const::Types::AIDE_TYPE
|
51
|
+
raise Decouplio::Errors::AideControversialKeysError.new(
|
52
|
+
errored_option: condition_options.to_s,
|
53
|
+
details: %i[if unless]
|
54
|
+
)
|
45
55
|
end
|
46
56
|
end
|
47
57
|
end
|
data/lib/decouplio/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decouplio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.0alpha5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Bal
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
61
|
+
version: '3.10'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
68
|
+
version: '3.10'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,45 +126,19 @@ files:
|
|
126
126
|
- bin/setup
|
127
127
|
- decouplio.gemspec
|
128
128
|
- docker-compose.yml
|
129
|
-
- docs/_config.yml
|
130
|
-
- docs/benchmarks.md
|
131
|
-
- docs/context.md
|
132
|
-
- docs/context.rb
|
133
|
-
- docs/deny.rb
|
134
|
-
- docs/doby.rb
|
135
|
-
- docs/doby_deny.md
|
136
|
-
- docs/error_store.md
|
137
|
-
- docs/error_store.rb
|
138
|
-
- docs/fail.md
|
139
|
-
- docs/fail.rb
|
140
|
-
- docs/index.md
|
141
|
-
- docs/inner_action.md
|
142
|
-
- docs/inner_action.rb
|
143
|
-
- docs/logic_block.md
|
144
|
-
- docs/octo.md
|
145
|
-
- docs/octo.rb
|
146
|
-
- docs/pass.md
|
147
|
-
- docs/pass.rb
|
148
|
-
- docs/quick_start.md
|
149
|
-
- docs/quick_start.rb
|
150
|
-
- docs/resq.md
|
151
|
-
- docs/resq.rb
|
152
|
-
- docs/step.md
|
153
|
-
- docs/step.rb
|
154
|
-
- docs/step_as_a_service.md
|
155
|
-
- docs/step_as_a_service.rb
|
156
|
-
- docs/wrap.md
|
157
|
-
- docs/wrap.rb
|
158
129
|
- lib/decouplio.rb
|
159
130
|
- lib/decouplio/action.rb
|
160
131
|
- lib/decouplio/composer.rb
|
161
132
|
- lib/decouplio/const/colors.rb
|
133
|
+
- lib/decouplio/const/doby_aide_options.rb
|
134
|
+
- lib/decouplio/const/error_messages.rb
|
162
135
|
- lib/decouplio/const/reserved_methods.rb
|
163
136
|
- lib/decouplio/const/results.rb
|
164
137
|
- lib/decouplio/const/types.rb
|
165
138
|
- lib/decouplio/const/validations/action_option_class.rb
|
139
|
+
- lib/decouplio/const/validations/aide.rb
|
166
140
|
- lib/decouplio/const/validations/common.rb
|
167
|
-
- lib/decouplio/const/validations/
|
141
|
+
- lib/decouplio/const/validations/doby.rb
|
168
142
|
- lib/decouplio/const/validations/fail.rb
|
169
143
|
- lib/decouplio/const/validations/logic.rb
|
170
144
|
- lib/decouplio/const/validations/octo.rb
|
@@ -175,9 +149,14 @@ files:
|
|
175
149
|
- lib/decouplio/const/validations/wrap.rb
|
176
150
|
- lib/decouplio/default_error_handler.rb
|
177
151
|
- lib/decouplio/errors/action_class_error.rb
|
152
|
+
- lib/decouplio/errors/aide_can_not_be_first_step_error.rb
|
153
|
+
- lib/decouplio/errors/aide_controversial_keys_error.rb
|
154
|
+
- lib/decouplio/errors/aide_finish_him_error.rb
|
178
155
|
- lib/decouplio/errors/base_error.rb
|
179
|
-
- lib/decouplio/errors/
|
156
|
+
- lib/decouplio/errors/doby_controversial_keys_error.rb
|
157
|
+
- lib/decouplio/errors/doby_finish_him_error.rb
|
180
158
|
- lib/decouplio/errors/error_store_error.rb
|
159
|
+
- lib/decouplio/errors/execution_error.rb
|
181
160
|
- lib/decouplio/errors/extra_key_for_fail_error.rb
|
182
161
|
- lib/decouplio/errors/extra_key_for_octo_error.rb
|
183
162
|
- lib/decouplio/errors/extra_key_for_pass_error.rb
|
@@ -205,7 +184,10 @@ files:
|
|
205
184
|
- lib/decouplio/errors/resq_handler_method_error.rb
|
206
185
|
- lib/decouplio/errors/step_controversial_keys_error.rb
|
207
186
|
- lib/decouplio/errors/step_finish_him_error.rb
|
187
|
+
- lib/decouplio/errors/step_is_not_defined_for_aide_error.rb
|
188
|
+
- lib/decouplio/errors/step_is_not_defined_for_doby_error.rb
|
208
189
|
- lib/decouplio/errors/step_is_not_defined_for_fail_error.rb
|
190
|
+
- lib/decouplio/errors/step_is_not_defined_for_pass_error.rb
|
209
191
|
- lib/decouplio/errors/step_is_not_defined_for_step_error.rb
|
210
192
|
- lib/decouplio/errors/step_is_not_defined_for_wrap_error.rb
|
211
193
|
- lib/decouplio/errors/step_name_error.rb
|
@@ -219,9 +201,9 @@ files:
|
|
219
201
|
- lib/decouplio/octo_options_validator.rb
|
220
202
|
- lib/decouplio/options_validator.rb
|
221
203
|
- lib/decouplio/processor.rb
|
204
|
+
- lib/decouplio/steps/aide.rb
|
222
205
|
- lib/decouplio/steps/base_resq.rb
|
223
206
|
- lib/decouplio/steps/base_step.rb
|
224
|
-
- lib/decouplio/steps/deny.rb
|
225
207
|
- lib/decouplio/steps/doby.rb
|
226
208
|
- lib/decouplio/steps/fail.rb
|
227
209
|
- lib/decouplio/steps/if_condition_fail.rb
|
@@ -244,13 +226,13 @@ files:
|
|
244
226
|
- lib/decouplio/steps/wrap.rb
|
245
227
|
- lib/decouplio/validators/condition.rb
|
246
228
|
- lib/decouplio/version.rb
|
247
|
-
homepage: https://github.com/differencialx/decouplio
|
229
|
+
homepage: https://github.com/differencialx/decouplio/blob/master/docs
|
248
230
|
licenses:
|
249
231
|
- MIT
|
250
232
|
metadata:
|
251
|
-
homepage_uri: https://github.com/differencialx/decouplio
|
252
|
-
source_code_uri: https://github.com/differencialx/decouplio
|
253
|
-
changelog_uri: https://github.com/differencialx/decouplio/CHANGELOG.md
|
233
|
+
homepage_uri: https://github.com/differencialx/decouplio/blob/master/docs
|
234
|
+
source_code_uri: https://github.com/differencialx/decouplio/blob/master/docs
|
235
|
+
changelog_uri: https://github.com/differencialx/decouplio/blob/master/docs/CHANGELOG.md
|
254
236
|
post_install_message:
|
255
237
|
rdoc_options: []
|
256
238
|
require_paths:
|
data/docs/_config.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
theme: jekyll-theme-cayman
|
data/docs/benchmarks.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
## Benchmarks
|
data/docs/context.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Context
|
2
|
-
|
3
|
-
Currently context is a simple `Hash` which can be accessed by step methods.
|
4
|
-
|
5
|
-
```ruby
|
6
|
-
require 'decouplio'
|
7
|
-
|
8
|
-
class SomeAction < Decouplio::Action
|
9
|
-
logic do
|
10
|
-
step :step_one
|
11
|
-
step :step_two
|
12
|
-
end
|
13
|
-
|
14
|
-
def step_one(**)
|
15
|
-
ctx[:step_one] = 'Step one ctx value'
|
16
|
-
end
|
17
|
-
|
18
|
-
# step method receives ctx as an argument
|
19
|
-
def step_two(step_one:, **)
|
20
|
-
ctx[:step_two] = step_one
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
action = SomeAction.call
|
25
|
-
|
26
|
-
action # =>
|
27
|
-
# Result: success
|
28
|
-
|
29
|
-
# Railway Flow:
|
30
|
-
# step_one -> step_two
|
31
|
-
|
32
|
-
# Context:
|
33
|
-
# {:step_one=>"Step one ctx value", :step_two=>"Step one ctx value"}
|
34
|
-
|
35
|
-
# Errors:
|
36
|
-
# {}
|
37
|
-
```
|
38
|
-
|
39
|
-
All key values passed into `call` method will be automatically assigned to action context.
|
40
|
-
|
41
|
-
```ruby
|
42
|
-
require 'decouplio'
|
43
|
-
|
44
|
-
class SomeActionCtx < Decouplio::Action
|
45
|
-
logic do
|
46
|
-
step :step_one
|
47
|
-
end
|
48
|
-
|
49
|
-
def step_one(**)
|
50
|
-
puts ctx
|
51
|
-
ctx[:result] = ctx[:one] + ctx[:two]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
action = SomeActionCtx.call(
|
56
|
-
one: 1,
|
57
|
-
two: 2
|
58
|
-
) # =>
|
59
|
-
# {:one=>1, :two=>2}
|
60
|
-
|
61
|
-
action[:result] # => 3
|
62
|
-
|
63
|
-
action # =>
|
64
|
-
# Result: success
|
65
|
-
|
66
|
-
# Railway Flow:
|
67
|
-
# step_one
|
68
|
-
|
69
|
-
# Context:
|
70
|
-
# {:one=>1, :two=>2, :result=>3}
|
71
|
-
|
72
|
-
# Errors:
|
73
|
-
# {}
|
74
|
-
```
|
data/docs/context.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require_relative '../lib/decouplio'
|
2
|
-
|
3
|
-
class SomeAction < Decouplio::Action
|
4
|
-
logic do
|
5
|
-
step :step_one
|
6
|
-
step :step_two
|
7
|
-
end
|
8
|
-
|
9
|
-
def step_one(**)
|
10
|
-
ctx[:step_one] = 'Step one ctx value'
|
11
|
-
end
|
12
|
-
|
13
|
-
# step method receives ctx as an argument
|
14
|
-
def step_two(step_one:, **)
|
15
|
-
ctx[:step_two] = step_one
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
action = SomeAction.call
|
20
|
-
|
21
|
-
puts action # =>
|
22
|
-
# Result: success
|
23
|
-
|
24
|
-
# Railway Flow:
|
25
|
-
# step_one -> step_two
|
26
|
-
|
27
|
-
# Context:
|
28
|
-
# {:step_one=>"Step one ctx value", :step_two=>"Step one ctx value"}
|
29
|
-
|
30
|
-
# Errors:
|
31
|
-
# {}
|
32
|
-
|
33
|
-
|
34
|
-
class SomeActionCtx < Decouplio::Action
|
35
|
-
logic do
|
36
|
-
step :step_one
|
37
|
-
end
|
38
|
-
|
39
|
-
def step_one(**)
|
40
|
-
puts ctx
|
41
|
-
ctx[:result] = ctx[:one] + ctx[:two]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
action = SomeActionCtx.call(
|
46
|
-
one: 1,
|
47
|
-
two: 2
|
48
|
-
)
|
49
|
-
|
50
|
-
action[:result] # => 3
|
51
|
-
|
52
|
-
puts action # =>
|
53
|
-
# Result: success
|
54
|
-
|
55
|
-
# Railway Flow:
|
56
|
-
# step_one
|
57
|
-
|
58
|
-
# Context:
|
59
|
-
# {:one=>1, :two=>2, :result=>3}
|
60
|
-
|
61
|
-
# Errors:
|
62
|
-
# {}
|
data/docs/deny.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require_relative '../lib/decouplio'
|
2
|
-
|
3
|
-
class SemanticDeny
|
4
|
-
def self.call(ctx:, error_store:, semantic:, error_message:)
|
5
|
-
ctx[:semantic] = semantic
|
6
|
-
error_store.add_error(semantic, error_message)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class SomeAction < Decouplio::Action
|
11
|
-
logic do
|
12
|
-
step :step_one
|
13
|
-
deny SemanticDeny, semantic: :bad_request, error_message: 'Bad request'
|
14
|
-
step :step_two
|
15
|
-
end
|
16
|
-
|
17
|
-
def step_one(step_one_param:, **)
|
18
|
-
ctx[:step_one] = step_one_param
|
19
|
-
end
|
20
|
-
|
21
|
-
def step_two(**)
|
22
|
-
ctx[:step_two] = 'Success'
|
23
|
-
end
|
24
|
-
|
25
|
-
def fail_one(**)
|
26
|
-
ctx[:fail_one] = 'Failure'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
success_action = SomeAction.call(step_one_param: true)
|
31
|
-
failure_action = SomeAction.call(step_one_param: false)
|
32
|
-
|
33
|
-
success_action # =>
|
34
|
-
# Result: success
|
35
|
-
|
36
|
-
# Railway Flow:
|
37
|
-
# step_one -> step_two
|
38
|
-
|
39
|
-
# Context:
|
40
|
-
# :step_one_param => true
|
41
|
-
# :step_one => true
|
42
|
-
# :step_two => "Success"
|
43
|
-
|
44
|
-
# Errors:
|
45
|
-
# None
|
46
|
-
|
47
|
-
failure_action # =>
|
48
|
-
# Result: failure
|
49
|
-
|
50
|
-
# Railway Flow:
|
51
|
-
# step_one -> SemanticDeny
|
52
|
-
|
53
|
-
# Context:
|
54
|
-
# :step_one_param => false
|
55
|
-
# :step_one => false
|
56
|
-
# :semantic => :bad_request
|
57
|
-
|
58
|
-
# Errors:
|
59
|
-
# :bad_request => ["Bad request"]
|
data/docs/doby.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require_relative '../lib/decouplio'
|
2
|
-
|
3
|
-
class AssignDoby
|
4
|
-
def self.call(ctx:, to:, from: nil, value: nil, **)
|
5
|
-
raise 'from/value is empty' unless from || value
|
6
|
-
|
7
|
-
ctx[to] = value || ctx[from]
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class SomeAction < Decouplio::Action
|
12
|
-
logic do
|
13
|
-
step :user
|
14
|
-
doby AssignDoby, to: :current_user, from: :user
|
15
|
-
end
|
16
|
-
|
17
|
-
def user(id:, **)
|
18
|
-
ctx[:user] = "User with id: #{id}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
action = SomeAction.call(id: 1)
|
23
|
-
|
24
|
-
puts action[:user] # => "User with id: 1"
|
25
|
-
|
26
|
-
puts action[:current_user] # => "User with id: 1"
|
27
|
-
|
28
|
-
puts action # =>
|
29
|
-
# Result: success
|
30
|
-
|
31
|
-
# Railway Flow:
|
32
|
-
# user -> AssignDoby
|
33
|
-
|
34
|
-
# Context:
|
35
|
-
# {:id=>1, :user=>"User with id: 1", :current_user=>"User with id: 1"}
|
36
|
-
|
37
|
-
# Errors:
|
38
|
-
# {}
|
data/docs/doby_deny.md
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
# Doby/Deny
|
2
|
-
|
3
|
-
It's a step type to make configurable manipulations with action context.
|
4
|
-
|
5
|
-
|
6
|
-
## Signature
|
7
|
-
|
8
|
-
```ruby
|
9
|
-
doby(class_constant, **options)
|
10
|
-
deny(class_constant, **options)
|
11
|
-
```
|
12
|
-
|
13
|
-
## Behavior
|
14
|
-
|
15
|
-
### Doby
|
16
|
-
|
17
|
-
- `doby` behaves similar to `step`, depending on `.call` method returning value(truthy or falsy) the execution will be moved to `success or failure` track accordingly.
|
18
|
-
- `doby` doesn't have `on_success, on_failure, if, unless, finish_him` options.
|
19
|
-
- All options passed after class constant will be passed as kwargs for `.call` method.
|
20
|
-
|
21
|
-
### Deny
|
22
|
-
- `deny` behaves similar to `fail`, no matter which value will be returned by `.call` method, it moves to `failure` track.
|
23
|
-
- `deny` doesn't have `on_success, on_failure, if, unless, finish_him` options.
|
24
|
-
- All options passed after class constant will be passed as kwargs for `.call` method.
|
25
|
-
|
26
|
-
|
27
|
-
## How to use?
|
28
|
-
|
29
|
-
Create the ruby class which has `.call` class method.
|
30
|
-
|
31
|
-
`.call` method signature:
|
32
|
-
```ruby
|
33
|
-
# :ctx - it's a ctx from Decouplio::Action
|
34
|
-
# :error_store - it's an error_store from Decouplio::Action
|
35
|
-
# you can call #add_error method on it.
|
36
|
-
# ** - kwargs passed from action.
|
37
|
-
def self.call(ctx:, error_store:, **)
|
38
|
-
end
|
39
|
-
```
|
40
|
-
|
41
|
-
```ruby
|
42
|
-
class AssignDoby
|
43
|
-
def self.call(ctx:, to:, from: nil, value: nil, **)
|
44
|
-
raise 'from/value is empty' unless from || value
|
45
|
-
|
46
|
-
ctx[to] = value || ctx[from]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# OR
|
51
|
-
|
52
|
-
class SemanticDeny
|
53
|
-
def self.call(ctx:, error_store:, semantic:, error_message:)
|
54
|
-
ctx[:semantic] = semantic
|
55
|
-
error_store.add_error(semantic, error_message)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# OR
|
60
|
-
|
61
|
-
# If you don't need ctx and error_store, you can omit them
|
62
|
-
class DummyDoby
|
63
|
-
def self.call(dummy:, **)
|
64
|
-
puts dummy
|
65
|
-
end
|
66
|
-
end
|
67
|
-
```
|
68
|
-
|
69
|
-
`AssignDoby` example.
|
70
|
-
```ruby
|
71
|
-
require 'decouplio'
|
72
|
-
|
73
|
-
class AssignDoby
|
74
|
-
def self.call(ctx:, to:, from: nil, value: nil, **)
|
75
|
-
raise 'from/value is empty' unless from || value
|
76
|
-
|
77
|
-
ctx[to] = value || ctx[from]
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
class SomeAction < Decouplio::Action
|
82
|
-
logic do
|
83
|
-
step :user
|
84
|
-
step AssignDoby, to: :current_user, from: :user
|
85
|
-
end
|
86
|
-
|
87
|
-
def user(id:, **)
|
88
|
-
ctx[:user] = "User with id: #{id}"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
action = SomeAction.call(id: 1)
|
93
|
-
|
94
|
-
action[:user] # => "User with id: 1"
|
95
|
-
|
96
|
-
action[:current_user] # => "User with id: 1"
|
97
|
-
|
98
|
-
action # =>
|
99
|
-
# Result: success
|
100
|
-
|
101
|
-
# Railway Flow:
|
102
|
-
# user -> AssignDoby
|
103
|
-
|
104
|
-
# Context:
|
105
|
-
# {:id=>1, :user=>"User with id: 1", :current_user=>"User with id: 1"}
|
106
|
-
|
107
|
-
# Errors:
|
108
|
-
# {}
|
109
|
-
```
|
110
|
-
`SemanticDeny` example.
|
111
|
-
```ruby
|
112
|
-
require 'decouplio'
|
113
|
-
|
114
|
-
class SemanticDeny
|
115
|
-
def self.call(ctx:, error_store:, semantic:, error_message:)
|
116
|
-
ctx[:semantic] = semantic
|
117
|
-
error_store.add_error(semantic, error_message)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
class SomeAction < Decouplio::Action
|
122
|
-
logic do
|
123
|
-
step :step_one
|
124
|
-
deny SemanticDeny, semantic: :bad_request, error_message: 'Bad request'
|
125
|
-
step :step_two
|
126
|
-
end
|
127
|
-
|
128
|
-
def step_one(step_one_param:, **)
|
129
|
-
ctx[:step_one] = step_one_param
|
130
|
-
end
|
131
|
-
|
132
|
-
def step_two(**)
|
133
|
-
ctx[:step_two] = 'Success'
|
134
|
-
end
|
135
|
-
|
136
|
-
def fail_one(**)
|
137
|
-
ctx[:fail_one] = 'Failure'
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
success_action = SomeAction.call(step_one_param: true)
|
142
|
-
failure_action = SomeAction.call(step_one_param: false)
|
143
|
-
|
144
|
-
success_action # =>
|
145
|
-
# Result: success
|
146
|
-
|
147
|
-
# Railway Flow:
|
148
|
-
# step_one -> step_two
|
149
|
-
|
150
|
-
# Context:
|
151
|
-
# :step_one_param => true
|
152
|
-
# :step_one => true
|
153
|
-
# :step_two => "Success"
|
154
|
-
|
155
|
-
# Errors:
|
156
|
-
# None
|
157
|
-
|
158
|
-
failure_action # =>
|
159
|
-
# Result: failure
|
160
|
-
|
161
|
-
# Railway Flow:
|
162
|
-
# step_one -> SemanticDeny
|
163
|
-
|
164
|
-
# Context:
|
165
|
-
# :step_one_param => false
|
166
|
-
# :step_one => false
|
167
|
-
# :semantic => :bad_request
|
168
|
-
|
169
|
-
# Errors:
|
170
|
-
# :bad_request => ["Bad request"]
|
171
|
-
```
|