trailblazer-macro 2.1.7 → 2.1.11
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/.github/workflows/ci.yml +1 -1
- data/CHANGES.md +19 -0
- data/README.md +1 -1
- data/lib/trailblazer/macro/guard.rb +0 -1
- data/lib/trailblazer/macro/model.rb +46 -40
- data/lib/trailblazer/macro/nested.rb +48 -39
- data/lib/trailblazer/macro/policy.rb +19 -16
- data/lib/trailblazer/macro/version.rb +1 -1
- data/lib/trailblazer/macro.rb +6 -6
- data/test/docs/model_test.rb +37 -1
- data/test/docs/nested_test.rb +33 -5
- data/test/operation/nested_test.rb +22 -0
- data/trailblazer-macro.gemspec +2 -2
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34955a47d4c5d006819242d4d9a13ce658a3473afe0d7f6b4570374dbff557c0
|
4
|
+
data.tar.gz: 4f8fb6b8ba5c8bcc3db19ac977507675550c0defa2be95b771c77914644837b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71cc088d718a756171fd402d12dfb3b55d817e87356ea13088871dbc539085b92af36f57b7e7e43c817181aac9b73c580f8e69208b96deec43c59f551df742f9
|
7
|
+
data.tar.gz: c400ba9542fd36400b6ebb0bffc142f3a51212a33b48504b527fdd35b15a5060a95d9c8735a9f146e2f259906568515a7199e9eae7087a3ad3a5b59cbb6a0374
|
data/.github/workflows/ci.yml
CHANGED
@@ -6,7 +6,7 @@ jobs:
|
|
6
6
|
fail-fast: false
|
7
7
|
matrix:
|
8
8
|
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
9
|
-
ruby: [2.5, 2.6, 2.7, '3.0',
|
9
|
+
ruby: [2.5, 2.6, 2.7, '3.0', "3.1", head, jruby]
|
10
10
|
runs-on: ubuntu-latest
|
11
11
|
steps:
|
12
12
|
- uses: actions/checkout@v2
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
# 2.1.11
|
2
|
+
|
3
|
+
* In `Nested()`, we no longer use `Railway::End::Success` and `Railway::End::Failure` as static outputs but
|
4
|
+
simply use `Railway`'s default termini objects.
|
5
|
+
* Use `dsl`'s new `Inject()` API instead of a overriding `:inject` in `Model()` and `Policy()`.
|
6
|
+
|
7
|
+
# 2.1.10
|
8
|
+
|
9
|
+
* Yanked, pushed accidentially.
|
10
|
+
|
11
|
+
# 2.1.9
|
12
|
+
|
13
|
+
* Allow omitting `:params` when calling the operation by defaulting it to `{}` in `Model()`.
|
14
|
+
* Use `dsl-linear` 0.5.0 and above, which allows removing `Inject()` uses.
|
15
|
+
|
16
|
+
# 2.1.8
|
17
|
+
|
18
|
+
Yanked due to inconsistency.
|
19
|
+
|
1
20
|
# 2.1.7
|
2
21
|
|
3
22
|
* Improve `Nested()` warning message.
|
data/README.md
CHANGED
@@ -8,7 +8,6 @@ module Trailblazer::Macro
|
|
8
8
|
def self.build(callable)
|
9
9
|
option = Trailblazer::Option(callable)
|
10
10
|
|
11
|
-
# this gets wrapped in a Operation::Result object.
|
12
11
|
->((ctx, *), **circuit_args) do
|
13
12
|
Trailblazer::Operation::Result.new(!!option.call(ctx, keyword_arguments: ctx.to_hash, **circuit_args), {})
|
14
13
|
end
|
@@ -1,54 +1,60 @@
|
|
1
|
-
module Trailblazer
|
1
|
+
module Trailblazer
|
2
|
+
module Macro
|
2
3
|
|
3
|
-
|
4
|
+
def self.Model(model_class = nil, action = :new, find_by_key = :id, id: 'model.build', not_found_terminus: false)
|
5
|
+
task = Activity::TaskBuilder::Binary(Model.new)
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
injections = {
|
8
|
+
Activity::Railway.Inject() => [:params], # pass-through {:params} if it's in ctx.
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
)
|
10
|
+
# defaulting as per Inject() API.
|
11
|
+
Activity::Railway.Inject() => {
|
12
|
+
:"model.class" => ->(*) { model_class },
|
13
|
+
:"model.action" => ->(*) { action },
|
14
|
+
:"model.find_by_key" => ->(*) { find_by_key },
|
15
|
+
}
|
16
|
+
}
|
13
17
|
|
14
|
-
|
15
|
-
options = options.merge(Linear::Output(:failure) => Linear::End(:not_found)) if not_found_terminus
|
18
|
+
options = {task: task, id: id}.merge(injections)
|
16
19
|
|
17
|
-
|
18
|
-
end
|
20
|
+
options = options.merge(Activity::Railway.Output(:failure) => Activity::Railway.End(:not_found)) if not_found_terminus
|
19
21
|
|
20
|
-
|
21
|
-
def call(options, params: nil, **)
|
22
|
-
builder = Model::Builder.new
|
23
|
-
options[:model] = model = builder.call(options, params)
|
24
|
-
options[:"result.model"] = result = Trailblazer::Operation::Result.new(!model.nil?, {})
|
25
|
-
|
26
|
-
result.success?
|
22
|
+
options
|
27
23
|
end
|
28
24
|
|
29
|
-
class
|
30
|
-
def call(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
action = :pass_through unless %i[new find_by].include?(action)
|
35
|
-
|
36
|
-
send("#{action}!", model_class, params, options[:"model.action"], find_by_key)
|
37
|
-
end
|
38
|
-
|
39
|
-
def new!(model_class, params, *)
|
40
|
-
model_class.new
|
41
|
-
end
|
25
|
+
class Model
|
26
|
+
def call(ctx, params: {}, **)
|
27
|
+
builder = Model::Builder.new
|
28
|
+
ctx[:model] = model = builder.call(ctx, params)
|
29
|
+
ctx[:"result.model"] = result = Operation::Result.new(!model.nil?, {})
|
42
30
|
|
43
|
-
|
44
|
-
def find_by!(model_class, params, action, find_by_key, *)
|
45
|
-
model_class.find_by(find_by_key.to_sym => params[find_by_key])
|
31
|
+
result.success?
|
46
32
|
end
|
47
33
|
|
48
|
-
|
49
|
-
|
50
|
-
|
34
|
+
class Builder
|
35
|
+
def call(ctx, params)
|
36
|
+
action = ctx[:"model.action"]
|
37
|
+
model_class = ctx[:"model.class"]
|
38
|
+
find_by_key = ctx[:"model.find_by_key"]
|
39
|
+
action = :pass_through unless %i[new find_by].include?(action)
|
40
|
+
|
41
|
+
send("#{action}!", model_class, params, ctx[:"model.action"], find_by_key)
|
42
|
+
end
|
43
|
+
|
44
|
+
def new!(model_class, params, *)
|
45
|
+
model_class.new
|
46
|
+
end
|
47
|
+
|
48
|
+
# Doesn't throw an exception and will return false to divert to Left.
|
49
|
+
def find_by!(model_class, params, action, find_by_key, *)
|
50
|
+
model_class.find_by(find_by_key.to_sym => params[find_by_key])
|
51
|
+
end
|
52
|
+
|
53
|
+
# Call any method on the model class and pass find_by_key, for example find(params[:id]).
|
54
|
+
def pass_through!(model_class, params, action, find_by_key, *)
|
55
|
+
model_class.send(action, params[find_by_key])
|
56
|
+
end
|
51
57
|
end
|
52
58
|
end
|
53
|
-
end
|
59
|
+
end # Macro
|
54
60
|
end
|
@@ -9,24 +9,26 @@ module Trailblazer
|
|
9
9
|
"Using the `Nested()` macro with operations and activities is deprecated. " \
|
10
10
|
"Replace `Nested(#{callable})` with `Subprocess(#{callable})`."
|
11
11
|
|
12
|
-
return
|
12
|
+
return Activity::Railway.Subprocess(callable)
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
task = Nested::Dynamic.new(callable, auto_wire: auto_wire)
|
15
|
+
task, outputs, compute_legacy_return_signal = Nested.Dynamic(callable, auto_wire: auto_wire)
|
17
16
|
|
18
17
|
merge = [
|
19
|
-
[
|
20
|
-
[Activity::TaskWrap::Pipeline.method(:insert_after), "task_wrap.call_task", ["Nested.compute_return_signal", task.method(:compute_return_signal)]],
|
18
|
+
[task, id: "Nested.compute_nested_activity", prepend: "task_wrap.call_task"],
|
21
19
|
]
|
22
20
|
|
23
|
-
|
21
|
+
if compute_legacy_return_signal
|
22
|
+
merge << [compute_legacy_return_signal, id: "Nested.compute_return_signal", append: "task_wrap.call_task"]
|
23
|
+
end
|
24
|
+
|
25
|
+
task_wrap_extension = Activity::TaskWrap::Extension::WrapStatic.new(extension: Activity::TaskWrap::Extension(*merge))
|
24
26
|
|
25
27
|
{
|
26
28
|
task: task,
|
27
29
|
id: id,
|
28
30
|
extensions: [task_wrap_extension],
|
29
|
-
outputs:
|
31
|
+
outputs: outputs,
|
30
32
|
}
|
31
33
|
end
|
32
34
|
|
@@ -45,57 +47,64 @@ module Trailblazer
|
|
45
47
|
# by passing their list to {:auto_wire} option.
|
46
48
|
#
|
47
49
|
# step Nested(:compute_nested, auto_wire: [Create, Update])
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
53
|
-
|
54
|
-
def initialize(nested_activity_decider, auto_wire: [])
|
55
|
-
@nested_activity_decider = Trailblazer::Option(nested_activity_decider)
|
56
|
-
@known_activities = Array(auto_wire)
|
57
|
-
@outputs = compute_task_outputs
|
50
|
+
def self.Dynamic(nested_activity_decider, auto_wire:)
|
51
|
+
if auto_wire.empty?
|
52
|
+
is_legacy = true # no auto_wire means we need to compute the legacy return signal.
|
53
|
+
auto_wire = [Class.new(Activity::Railway)]
|
58
54
|
end
|
59
55
|
|
60
|
-
|
56
|
+
outputs = outputs_for(auto_wire)
|
57
|
+
task = Dynamic.new(nested_activity_decider)
|
58
|
+
compute_legacy_return_signal = Dynamic::ComputeLegacyReturnSignal.new(outputs) if is_legacy
|
59
|
+
|
60
|
+
return task, outputs, compute_legacy_return_signal
|
61
|
+
end
|
62
|
+
|
63
|
+
# Go through the list of all possible nested activities and compile the total sum of possible outputs.
|
64
|
+
# FIXME: WHAT IF WE HAVE TWO IDENTICALLY NAMED OUTPUTS?
|
65
|
+
# @private
|
66
|
+
def self.outputs_for(activities)
|
67
|
+
activities.map do |activity|
|
68
|
+
Activity::Railway.Subprocess(activity)[:outputs]
|
69
|
+
end.inject(:merge)
|
70
|
+
end
|
71
|
+
|
72
|
+
class Dynamic
|
73
|
+
def initialize(nested_activity_decider)
|
74
|
+
@nested_activity_decider = Trailblazer::Option(nested_activity_decider)
|
75
|
+
end
|
61
76
|
|
62
77
|
# TaskWrap step.
|
63
|
-
def
|
78
|
+
def call(wrap_ctx, original_args)
|
64
79
|
(ctx, _), original_circuit_options = original_args
|
65
80
|
|
66
81
|
# TODO: evaluate the option to get the actual "object" to call.
|
67
82
|
activity = @nested_activity_decider.(ctx, keyword_arguments: ctx.to_hash, **original_circuit_options)
|
68
83
|
|
69
84
|
# Overwrite :task so task_wrap.call_task will call this activity.
|
70
|
-
# This is a trick so we don't have to repeat logic from #call_task here.
|
85
|
+
# This is a taskWrap trick so we don't have to repeat logic from #call_task here.
|
71
86
|
wrap_ctx[:task] = activity
|
72
87
|
|
73
88
|
return wrap_ctx, original_args
|
74
89
|
end
|
75
90
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
@outputs[:success].signal : @outputs[:failure].signal
|
91
|
+
# TODO: remove me when we make {:auto_wire} mandatory.
|
92
|
+
class ComputeLegacyReturnSignal
|
93
|
+
SUCCESS_SEMANTICS = [:success, :pass_fast] # TODO: make this injectable/or get it from operation.
|
94
|
+
|
95
|
+
def initialize(outputs)
|
96
|
+
@outputs = outputs # not needed for auto_wire!
|
83
97
|
end
|
84
98
|
|
85
|
-
|
86
|
-
|
99
|
+
def call(wrap_ctx, original_args)
|
100
|
+
actual_semantic = wrap_ctx[:return_signal].to_h[:semantic]
|
101
|
+
applied_semantic = SUCCESS_SEMANTICS.include?(actual_semantic) ? :success : :failure
|
87
102
|
|
88
|
-
|
89
|
-
# If :auto_wire is empty, we map outputs to :success and :failure only, for backward compatibility.
|
90
|
-
# This is what {Nested} in 2.0 used to do, where the outcome could only be true/false (or success/failure).
|
91
|
-
return STATIC_OUTPUTS if @known_activities.empty?
|
103
|
+
wrap_ctx[:return_signal] = @outputs.fetch(applied_semantic).signal
|
92
104
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
Hash[activity.to_h[:outputs].collect{ |output| [output.semantic, output] }]
|
97
|
-
end.inject(:merge)
|
98
|
-
end
|
105
|
+
return wrap_ctx, original_args
|
106
|
+
end
|
107
|
+
end # ComputeLegacyReturnSignal
|
99
108
|
end
|
100
109
|
end
|
101
110
|
end
|
@@ -8,35 +8,38 @@ module Trailblazer::Macro
|
|
8
8
|
@path = path
|
9
9
|
end
|
10
10
|
|
11
|
-
# incoming low-level {
|
11
|
+
# incoming low-level {circuit interface}.
|
12
12
|
# outgoing Task::Binary API.
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
#
|
14
|
+
# Retrieve the injectable {condition}, execute it and interpret its {Result} object.
|
15
|
+
def call((ctx, flow_options), **circuit_options)
|
16
|
+
condition = ctx[@path] # this allows dependency injection.
|
17
|
+
result = condition.([ctx, flow_options], **circuit_options)
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
ctx[:"policy.#{@name}"] = result[:policy] # assign the policy as a ctx variable.
|
20
|
+
ctx[:"result.policy.#{@name}"] = result
|
19
21
|
|
20
22
|
# flow control
|
21
|
-
signal = result.success? ? Trailblazer::Activity::Right : Trailblazer::Activity::Left
|
23
|
+
signal = result.success? ? Trailblazer::Activity::Right : Trailblazer::Activity::Left
|
22
24
|
|
23
|
-
return signal, [
|
25
|
+
return signal, [ctx, flow_options]
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
# Adds the `yield` result to the
|
29
|
+
# Adds the `yield` result to the Railway and treats it like a
|
28
30
|
# policy-compatible object at runtime.
|
29
|
-
def self.step(condition,
|
30
|
-
name = options[:name]
|
31
|
+
def self.step(condition, name: nil, &block)
|
31
32
|
path = :"policy.#{name}.eval"
|
32
|
-
|
33
33
|
task = Eval.new(name: name, path: path)
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
injections = {
|
36
|
+
Trailblazer::Activity::Railway.Inject() => {
|
37
|
+
# :"policy.default.eval"
|
38
|
+
path => ->(*) { condition }
|
39
|
+
}
|
40
|
+
}
|
38
41
|
|
39
|
-
{task: task, id: path
|
42
|
+
{task: task, id: path}.merge(injections)
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
data/lib/trailblazer/macro.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "forwardable"
|
2
|
-
require "trailblazer/activity"
|
3
2
|
require "trailblazer/activity/dsl/linear"
|
4
3
|
require "trailblazer/operation" # TODO: remove this dependency
|
5
4
|
|
@@ -17,12 +16,13 @@ module Trailblazer
|
|
17
16
|
|
18
17
|
# All macros sit in the {Trailblazer::Macro} namespace, where we forward calls from
|
19
18
|
# operations and activities to.
|
19
|
+
|
20
20
|
module Activity::DSL::Linear::Helper
|
21
|
-
Policy = Trailblazer::Macro::Policy
|
21
|
+
Constants::Policy = Trailblazer::Macro::Policy
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
# Extending the {Linear::Helper} namespace is the canonical way to import
|
24
|
+
# macros into Railway, FastTrack, Operation, etc.
|
25
|
+
extend Forwardable
|
26
|
+
def_delegators Trailblazer::Macro, :Model, :Nested, :Wrap, :Rescue
|
27
27
|
end # Helper
|
28
28
|
end
|
data/test/docs/model_test.rb
CHANGED
@@ -21,6 +21,17 @@ class DocsModelTest < Minitest::Spec
|
|
21
21
|
end
|
22
22
|
#:op end
|
23
23
|
|
24
|
+
|
25
|
+
it "defaults {:params} to empty hash when not passed" do
|
26
|
+
result = Create.({})
|
27
|
+
assert_equal true, result.success?
|
28
|
+
assert_equal %{#<struct DocsModelTest::Song id=nil, title=nil>}, result[:model].inspect
|
29
|
+
|
30
|
+
result = Update.({})
|
31
|
+
assert_equal false, result.success?
|
32
|
+
assert_equal "nil", result[:model].inspect
|
33
|
+
end
|
34
|
+
|
24
35
|
it do
|
25
36
|
#:create
|
26
37
|
result = Create.(params: {})
|
@@ -126,13 +137,38 @@ class DocsModelTest < Minitest::Spec
|
|
126
137
|
class Hit < Song
|
127
138
|
end
|
128
139
|
|
140
|
+
#:di-model-class
|
129
141
|
result = Create.(params: {}, :"model.class" => Hit)
|
142
|
+
#:di-model-class end
|
130
143
|
|
131
144
|
result[:model].inspect.must_equal %{#<struct DocsModelTest::Hit id=nil, title=nil>}
|
132
145
|
|
133
146
|
# inject all variables
|
134
|
-
|
147
|
+
#:di-all
|
148
|
+
result = Create.(
|
149
|
+
params: {title: "Olympia"}, # some random variable.
|
150
|
+
"model.class": Hit,
|
151
|
+
"model.action": :find_by,
|
152
|
+
"model.find_by_key": :title
|
153
|
+
)
|
154
|
+
#:di-all end
|
135
155
|
|
136
156
|
result[:model].inspect.must_equal %{#<struct DocsModelTest::Hit id=2, title="Olympia">}
|
157
|
+
|
158
|
+
# use empty Model() and inject {model.class} and {model.action}
|
159
|
+
module A
|
160
|
+
#:op-model-empty
|
161
|
+
class Create < Trailblazer::Operation
|
162
|
+
step Model()
|
163
|
+
# ..
|
164
|
+
end
|
165
|
+
#:op-model-empty end
|
166
|
+
end # A
|
167
|
+
|
168
|
+
result = A::Create.(params: {}, :"model.class" => Hit)
|
169
|
+
|
170
|
+
result[:model].inspect.must_equal %{#<struct DocsModelTest::Hit id=nil, title=nil>}
|
171
|
+
|
172
|
+
|
137
173
|
end
|
138
174
|
end
|
data/test/docs/nested_test.rb
CHANGED
@@ -151,7 +151,8 @@ class NestedInput < Minitest::Spec
|
|
151
151
|
end
|
152
152
|
#:nested-with-pass-fast end
|
153
153
|
|
154
|
-
#
|
154
|
+
#= {#save} is still called because the {End.pass_fast} terminus is automatically wired to
|
155
|
+
#= the success "output" of Nested().
|
155
156
|
create.(seq: []).inspect(:seq).must_equal %{<Result:true [[:create, :just_pass_fast, :save]] >}
|
156
157
|
end
|
157
158
|
end
|
@@ -159,15 +160,16 @@ class NestedInput < Minitest::Spec
|
|
159
160
|
it "Nested(:method, auto_wire: *activities) with :pass_fast => End()" do
|
160
161
|
module E
|
161
162
|
class JsonValidate < Trailblazer::Operation
|
162
|
-
step :validate, Output(:
|
163
|
-
|
163
|
+
step :validate, Output(:failure) => End(:invalid_json)
|
164
|
+
step :save
|
165
|
+
include T.def_steps(:validate, :save)
|
164
166
|
end
|
165
167
|
|
166
168
|
#:nested-with-auto-wire
|
167
169
|
class Create < Trailblazer::Operation
|
168
170
|
step :create
|
169
171
|
step Nested(:compute_nested, auto_wire: [Validate, JsonValidate]),
|
170
|
-
Output(:
|
172
|
+
Output(:invalid_json) => End(:jsoned)
|
171
173
|
|
172
174
|
#~meths
|
173
175
|
def compute_nested(ctx, what:, **)
|
@@ -179,10 +181,36 @@ class NestedInput < Minitest::Spec
|
|
179
181
|
end
|
180
182
|
#:nested-with-auto-wire end
|
181
183
|
|
182
|
-
|
184
|
+
|
185
|
+
#@ nested {JsonValidate} ends on {End.success}
|
186
|
+
result = Create.(seq: [], what: JsonValidate, validate: true)
|
187
|
+
|
188
|
+
result.inspect(:seq).must_equal %{<Result:true [[:create, :validate, :save]] >}
|
189
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
|
190
|
+
|
191
|
+
#@ nested {JsonValidate} ends on {End.invalid_json} because validate fails.
|
192
|
+
result = Create.(seq: [], what: JsonValidate, validate: false)
|
183
193
|
|
184
194
|
result.inspect(:seq).must_equal %{<Result:false [[:create, :validate]] >}
|
185
195
|
result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:jsoned>}
|
196
|
+
|
197
|
+
#@ nested {JsonValidate} ends on {End.failure} because save fails.
|
198
|
+
result = Create.(seq: [], what: JsonValidate, save: false)
|
199
|
+
|
200
|
+
result.inspect(:seq).must_equal %{<Result:false [[:create, :validate, :save]] >}
|
201
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>}
|
202
|
+
|
203
|
+
#@ nested {Validate} ends on {End.failure} because validate fails.
|
204
|
+
result = Create.(seq: [], what: Validate, validate: false)
|
205
|
+
|
206
|
+
result.inspect(:seq).must_equal %{<Result:false [[:create, :validate]] >}
|
207
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>}
|
208
|
+
|
209
|
+
#@ nested {Validate} ends on {End.success}.
|
210
|
+
result = Create.(seq: [], what: Validate)
|
211
|
+
|
212
|
+
result.inspect(:seq).must_equal %{<Result:true [[:create, :validate]] >}
|
213
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
|
186
214
|
end
|
187
215
|
end
|
188
216
|
end
|
@@ -49,6 +49,28 @@ class NestedTest < Minitest::Spec
|
|
49
49
|
result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
|
50
50
|
end
|
51
51
|
|
52
|
+
#@ unit test
|
53
|
+
# TODO: make me a non-Operation test.
|
54
|
+
it "allows using multiple Nested() per operation" do
|
55
|
+
create = Class.new(Trailblazer::Operation) do
|
56
|
+
def compute_nested(ctx, what:, **)
|
57
|
+
what
|
58
|
+
end
|
59
|
+
|
60
|
+
step Nested(:compute_nested)
|
61
|
+
step Nested(:compute_nested), id: :compute_nested_again
|
62
|
+
end
|
63
|
+
|
64
|
+
#@ we want both Nested executed
|
65
|
+
result = create.(seq: [], what: SignIn)
|
66
|
+
result.inspect(:seq).must_equal %{<Result:true [[:c, :c]] >}
|
67
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
|
68
|
+
|
69
|
+
result = create.wtf?(seq: [], what: SignUp)
|
70
|
+
result.inspect(:seq).must_equal %{<Result:false [[:b]] >}
|
71
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>}
|
72
|
+
end
|
73
|
+
|
52
74
|
it "raises RuntimeError if dynamically nested activities with custom output are not auto wired" do
|
53
75
|
exception = assert_raises RuntimeError do
|
54
76
|
Class.new(Trailblazer::Operation) do
|
data/trailblazer-macro.gemspec
CHANGED
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "roar"
|
26
26
|
spec.add_development_dependency "trailblazer-developer"
|
27
27
|
|
28
|
-
spec.add_dependency "trailblazer-activity-dsl-linear", ">= 0.
|
29
|
-
spec.add_dependency "trailblazer-operation", ">= 0.
|
28
|
+
spec.add_dependency "trailblazer-activity-dsl-linear", ">= 1.0.0", "< 1.1.0"
|
29
|
+
spec.add_dependency "trailblazer-operation", ">= 0.8.0" # TODO: this dependency will be removed. currently needed for tests?!
|
30
30
|
|
31
31
|
spec.required_ruby_version = ">= 2.2.0"
|
32
32
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-macro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
- Marc Tich
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -101,34 +101,34 @@ dependencies:
|
|
101
101
|
requirements:
|
102
102
|
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: 0.
|
104
|
+
version: 1.0.0
|
105
105
|
- - "<"
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
107
|
+
version: 1.1.0
|
108
108
|
type: :runtime
|
109
109
|
prerelease: false
|
110
110
|
version_requirements: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
112
|
- - ">="
|
113
113
|
- !ruby/object:Gem::Version
|
114
|
-
version: 0.
|
114
|
+
version: 1.0.0
|
115
115
|
- - "<"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 1.1.0
|
118
118
|
- !ruby/object:Gem::Dependency
|
119
119
|
name: trailblazer-operation
|
120
120
|
requirement: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.
|
124
|
+
version: 0.8.0
|
125
125
|
type: :runtime
|
126
126
|
prerelease: false
|
127
127
|
version_requirements: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.
|
131
|
+
version: 0.8.0
|
132
132
|
description: Macros for Trailblazer's operation
|
133
133
|
email:
|
134
134
|
- apotonick@gmail.com
|
@@ -173,7 +173,7 @@ homepage: http://trailblazer.to
|
|
173
173
|
licenses:
|
174
174
|
- LGPL-3.0
|
175
175
|
metadata: {}
|
176
|
-
post_install_message:
|
176
|
+
post_install_message:
|
177
177
|
rdoc_options: []
|
178
178
|
require_paths:
|
179
179
|
- lib
|
@@ -188,8 +188,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
188
|
- !ruby/object:Gem::Version
|
189
189
|
version: '0'
|
190
190
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
192
|
-
signing_key:
|
191
|
+
rubygems_version: 3.2.3
|
192
|
+
signing_key:
|
193
193
|
specification_version: 4
|
194
194
|
summary: 'Macros for Trailblazer''s operation: Policy, Wrap, Rescue and more.'
|
195
195
|
test_files:
|