decouplio 1.0.0alpha3 → 1.0.0alpha7
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/decouplio.gemspec +4 -4
- data/lib/decouplio/action.rb +13 -3
- data/lib/decouplio/composer.rb +24 -3
- data/lib/decouplio/const/doby_aide_options.rb +1 -0
- data/lib/decouplio/const/error_messages.rb +9 -0
- data/lib/decouplio/const/step_options.rb +16 -0
- data/lib/decouplio/default_error_handler.rb +21 -6
- data/lib/decouplio/errors/execution_error.rb +20 -0
- data/lib/decouplio/errors/step_is_not_defined_for_pass_error.rb +27 -0
- data/lib/decouplio/logic_dsl.rb +52 -3
- data/lib/decouplio/options_validator.rb +46 -10
- data/lib/decouplio/steps/base_resq.rb +13 -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/version.rb +1 -1
- metadata +14 -39
- data/docs/_config.yml +0 -1
- data/docs/aide.rb +0 -59
- data/docs/benchmarks.md +0 -1
- data/docs/context.md +0 -74
- data/docs/context.rb +0 -62
- data/docs/doby.rb +0 -38
- data/docs/doby_aide.md +0 -208
- 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 -29
- data/docs/octo.md +0 -326
- 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
@@ -6,10 +6,11 @@ require_relative 'shared/fail_resolver'
|
|
6
6
|
module Decouplio
|
7
7
|
module Steps
|
8
8
|
class ServiceFail < Decouplio::Steps::BaseStep
|
9
|
-
def initialize(name:, service:, on_success_type:, on_failure_type:)
|
9
|
+
def initialize(name:, service:, args:, on_success_type:, on_failure_type:)
|
10
10
|
super()
|
11
11
|
@name = name
|
12
12
|
@service = service
|
13
|
+
@args = args
|
13
14
|
@on_success_type = on_success_type
|
14
15
|
@on_failure_type = on_failure_type
|
15
16
|
end
|
@@ -18,7 +19,8 @@ module Decouplio
|
|
18
19
|
instance.append_railway_flow(@name)
|
19
20
|
result = @service.call(
|
20
21
|
ctx: instance.ctx,
|
21
|
-
error_store: instance.error_store
|
22
|
+
error_store: instance.error_store,
|
23
|
+
**@args
|
22
24
|
)
|
23
25
|
|
24
26
|
resolve(result: result, instance: instance)
|
@@ -5,10 +5,11 @@ require_relative 'base_step'
|
|
5
5
|
module Decouplio
|
6
6
|
module Steps
|
7
7
|
class ServicePass < Decouplio::Steps::BaseStep
|
8
|
-
def initialize(name:, service:, on_success_type:, on_failure_type:)
|
8
|
+
def initialize(name:, service:, args:, on_success_type:, on_failure_type:)
|
9
9
|
super()
|
10
10
|
@name = name
|
11
11
|
@service = service
|
12
|
+
@args = args
|
12
13
|
@on_success_type = on_success_type
|
13
14
|
@on_failure_type = on_failure_type
|
14
15
|
end
|
@@ -17,7 +18,8 @@ module Decouplio
|
|
17
18
|
instance.append_railway_flow(@name)
|
18
19
|
@service.call(
|
19
20
|
ctx: instance.ctx,
|
20
|
-
error_store: instance.error_store
|
21
|
+
error_store: instance.error_store,
|
22
|
+
**@args
|
21
23
|
)
|
22
24
|
|
23
25
|
resolve(instance: instance)
|
@@ -6,10 +6,11 @@ require_relative 'shared/step_resolver'
|
|
6
6
|
module Decouplio
|
7
7
|
module Steps
|
8
8
|
class ServiceStep < Decouplio::Steps::BaseStep
|
9
|
-
def initialize(name:, service:, on_success_type:, on_failure_type:)
|
9
|
+
def initialize(name:, service:, args:, on_success_type:, on_failure_type:)
|
10
10
|
super()
|
11
11
|
@name = name
|
12
12
|
@service = service
|
13
|
+
@args = args
|
13
14
|
@on_success_type = on_success_type
|
14
15
|
@on_failure_type = on_failure_type
|
15
16
|
end
|
@@ -18,7 +19,8 @@ module Decouplio
|
|
18
19
|
instance.append_railway_flow(@name)
|
19
20
|
result = @service.call(
|
20
21
|
ctx: instance.ctx,
|
21
|
-
error_store: instance.error_store
|
22
|
+
error_store: instance.error_store,
|
23
|
+
**@args
|
22
24
|
)
|
23
25
|
|
24
26
|
resolve(result: result, instance: instance)
|
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.0alpha7
|
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-26 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,42 +126,15 @@ files:
|
|
126
126
|
- bin/setup
|
127
127
|
- decouplio.gemspec
|
128
128
|
- docker-compose.yml
|
129
|
-
- docs/_config.yml
|
130
|
-
- docs/aide.rb
|
131
|
-
- docs/benchmarks.md
|
132
|
-
- docs/context.md
|
133
|
-
- docs/context.rb
|
134
|
-
- docs/doby.rb
|
135
|
-
- docs/doby_aide.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
|
162
133
|
- lib/decouplio/const/doby_aide_options.rb
|
134
|
+
- lib/decouplio/const/error_messages.rb
|
163
135
|
- lib/decouplio/const/reserved_methods.rb
|
164
136
|
- lib/decouplio/const/results.rb
|
137
|
+
- lib/decouplio/const/step_options.rb
|
165
138
|
- lib/decouplio/const/types.rb
|
166
139
|
- lib/decouplio/const/validations/action_option_class.rb
|
167
140
|
- lib/decouplio/const/validations/aide.rb
|
@@ -184,6 +157,7 @@ files:
|
|
184
157
|
- lib/decouplio/errors/doby_controversial_keys_error.rb
|
185
158
|
- lib/decouplio/errors/doby_finish_him_error.rb
|
186
159
|
- lib/decouplio/errors/error_store_error.rb
|
160
|
+
- lib/decouplio/errors/execution_error.rb
|
187
161
|
- lib/decouplio/errors/extra_key_for_fail_error.rb
|
188
162
|
- lib/decouplio/errors/extra_key_for_octo_error.rb
|
189
163
|
- lib/decouplio/errors/extra_key_for_pass_error.rb
|
@@ -214,6 +188,7 @@ files:
|
|
214
188
|
- lib/decouplio/errors/step_is_not_defined_for_aide_error.rb
|
215
189
|
- lib/decouplio/errors/step_is_not_defined_for_doby_error.rb
|
216
190
|
- lib/decouplio/errors/step_is_not_defined_for_fail_error.rb
|
191
|
+
- lib/decouplio/errors/step_is_not_defined_for_pass_error.rb
|
217
192
|
- lib/decouplio/errors/step_is_not_defined_for_step_error.rb
|
218
193
|
- lib/decouplio/errors/step_is_not_defined_for_wrap_error.rb
|
219
194
|
- lib/decouplio/errors/step_name_error.rb
|
@@ -252,13 +227,13 @@ files:
|
|
252
227
|
- lib/decouplio/steps/wrap.rb
|
253
228
|
- lib/decouplio/validators/condition.rb
|
254
229
|
- lib/decouplio/version.rb
|
255
|
-
homepage: https://github.
|
230
|
+
homepage: https://differencialx.github.io/decouplio.github.io/
|
256
231
|
licenses:
|
257
232
|
- MIT
|
258
233
|
metadata:
|
259
|
-
homepage_uri: https://github.
|
260
|
-
source_code_uri: https://github.com/differencialx/decouplio
|
261
|
-
changelog_uri: https://github.com/differencialx/decouplio/CHANGELOG.md
|
234
|
+
homepage_uri: https://differencialx.github.io/decouplio.github.io/
|
235
|
+
source_code_uri: https://github.com/differencialx/decouplio/blob/master/docs
|
236
|
+
changelog_uri: https://github.com/differencialx/decouplio/blob/master/docs/CHANGELOG.md
|
262
237
|
post_install_message:
|
263
238
|
rdoc_options: []
|
264
239
|
require_paths:
|
data/docs/_config.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
theme: jekyll-theme-cayman
|
data/docs/aide.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require_relative '../lib/decouplio'
|
2
|
-
|
3
|
-
class SemanticAide
|
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
|
-
aide SemanticAide, 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 -> SemanticAide
|
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/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/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_aide.md
DELETED
@@ -1,208 +0,0 @@
|
|
1
|
-
# Doby/Aide
|
2
|
-
|
3
|
-
Steps which make configurable manipulations with action context.
|
4
|
-
|
5
|
-
|
6
|
-
## Signature
|
7
|
-
|
8
|
-
```ruby
|
9
|
-
doby(class_constant, **options)
|
10
|
-
aide(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
|
-
### Aide
|
22
|
-
- `aide` behaves similar to `fail`, no matter which value will be returned by `.call` method, it moves to `failure` track.
|
23
|
-
- `aide` 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 SemanticAide
|
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
|
-
doby 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
|
-
`SemanticAide` example.
|
111
|
-
```ruby
|
112
|
-
require 'decouplio'
|
113
|
-
|
114
|
-
class SemanticAide
|
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
|
-
aide SemanticAide, 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 -> SemanticAide
|
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
|
-
```
|
172
|
-
|
173
|
-
|
174
|
-
## Options
|
175
|
-
|
176
|
-
### Doby
|
177
|
-
Has the same options and behavior as [step](https://github.com/differencialx/decouplio/blob/master/docs/step.md), just specify them along with doby class options like here:
|
178
|
-
```ruby
|
179
|
-
# ...
|
180
|
-
|
181
|
-
logic do
|
182
|
-
doby AssignDoby,
|
183
|
-
to: :current_user,
|
184
|
-
from: :user,
|
185
|
-
on_success: :finish_him,
|
186
|
-
if: :condition
|
187
|
-
end
|
188
|
-
|
189
|
-
# ...
|
190
|
-
```
|
191
|
-
|
192
|
-
### Aide
|
193
|
-
Has the same options and behavior as [fail](https://github.com/differencialx/decouplio/blob/master/docs/fail.md), just specify them along with aide class options like here:
|
194
|
-
|
195
|
-
```ruby
|
196
|
-
# ...
|
197
|
-
|
198
|
-
logic do
|
199
|
-
step :step_one
|
200
|
-
aide SemanticAide,
|
201
|
-
semantic: :bad_request,
|
202
|
-
error_message: 'Bad request',
|
203
|
-
on_failure: :PASS,
|
204
|
-
unless: :condition
|
205
|
-
end
|
206
|
-
|
207
|
-
# ...
|
208
|
-
```
|