trailblazer-macro 2.1.7 → 2.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +9 -0
- data/README.md +1 -1
- data/lib/trailblazer/macro/guard.rb +0 -1
- data/lib/trailblazer/macro/model.rb +16 -15
- data/lib/trailblazer/macro/policy.rb +17 -16
- data/lib/trailblazer/macro/version.rb +1 -1
- data/test/docs/model_test.rb +37 -1
- data/trailblazer-macro.gemspec +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 639ab06bc834f5258e404d9c87e1e53db434884225e6f6c222afcb9df9597154
|
4
|
+
data.tar.gz: b5f08c21b83529cd8a12fed2e6ef3e638a9db546b2d57d651f3a9f9adec8ff3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebf4969c76b10be6b3e842376ebbb6bb5fd73bd7a3c8fe1f6c61ab1efb9e8d945b3bb13404fcf6cdbead3590deb5cf9aeaf0150a32209d14107e2019981732ed
|
7
|
+
data.tar.gz: 5d485adedac0da50b68f3528ddaf80329f9d33a06cd6768e7a7c1d430c4f7ff05bf5daafbf14eb174fd821bbb5d1108150bbb278fbc7eacb960c26fd8f058cca
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 2.1.9
|
2
|
+
|
3
|
+
* Allow omitting `:params` when calling the operation by defaulting it to `{}` in `Model()`.
|
4
|
+
* Use `dsl-linear` 0.5.0 and above, which allows removing `Inject()` uses.
|
5
|
+
|
6
|
+
# 2.1.8
|
7
|
+
|
8
|
+
Yanked due to inconsistency.
|
9
|
+
|
1
10
|
# 2.1.7
|
2
11
|
|
3
12
|
* 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
|
@@ -2,38 +2,39 @@ module Trailblazer::Macro
|
|
2
2
|
|
3
3
|
Linear = Trailblazer::Activity::DSL::Linear
|
4
4
|
|
5
|
-
def self.Model(model_class, action =
|
5
|
+
def self.Model(model_class = nil, action = :new, find_by_key = :id, id: 'model.build', not_found_terminus: false)
|
6
6
|
task = Trailblazer::Activity::TaskBuilder::Binary(Model.new)
|
7
7
|
|
8
|
-
|
9
|
-
:"model.class" => model_class,
|
10
|
-
:"model.action" => action,
|
11
|
-
:"model.find_by_key" => find_by_key
|
12
|
-
|
8
|
+
injections = { # defaulting as per `:inject` API.
|
9
|
+
:"model.class" => ->(*) { model_class },
|
10
|
+
:"model.action" => ->(*) { action },
|
11
|
+
:"model.find_by_key" => ->(*) { find_by_key },
|
12
|
+
}
|
13
|
+
|
14
|
+
options = {task: task, id: id, inject: [:params, injections]} # pass-through {:params} if it's in ctx.
|
13
15
|
|
14
|
-
options = { task: task, id: id, extensions: [injection] }
|
15
16
|
options = options.merge(Linear::Output(:failure) => Linear::End(:not_found)) if not_found_terminus
|
16
17
|
|
17
18
|
options
|
18
19
|
end
|
19
20
|
|
20
21
|
class Model
|
21
|
-
def call(
|
22
|
+
def call(ctx, params: {}, **)
|
22
23
|
builder = Model::Builder.new
|
23
|
-
|
24
|
-
|
24
|
+
ctx[:model] = model = builder.call(ctx, params)
|
25
|
+
ctx[:"result.model"] = result = Trailblazer::Operation::Result.new(!model.nil?, {})
|
25
26
|
|
26
27
|
result.success?
|
27
28
|
end
|
28
29
|
|
29
30
|
class Builder
|
30
|
-
def call(
|
31
|
-
action =
|
32
|
-
model_class =
|
33
|
-
find_by_key =
|
31
|
+
def call(ctx, params)
|
32
|
+
action = ctx[:"model.action"]
|
33
|
+
model_class = ctx[:"model.class"]
|
34
|
+
find_by_key = ctx[:"model.find_by_key"]
|
34
35
|
action = :pass_through unless %i[new find_by].include?(action)
|
35
36
|
|
36
|
-
send("#{action}!", model_class, params,
|
37
|
+
send("#{action}!", model_class, params, ctx[:"model.action"], find_by_key)
|
37
38
|
end
|
38
39
|
|
39
40
|
def new!(model_class, params, *)
|
@@ -8,35 +8,36 @@ 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
|
+
# :"policy.default.eval"
|
37
|
+
path => ->(*) { condition }
|
38
|
+
}
|
38
39
|
|
39
|
-
{task: task, id: path,
|
40
|
+
{task: task, id: path, inject: [injections]}
|
40
41
|
end
|
41
42
|
end
|
42
43
|
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/trailblazer-macro.gemspec
CHANGED
@@ -25,7 +25,7 @@ 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.
|
28
|
+
spec.add_dependency "trailblazer-activity-dsl-linear", ">= 0.5.0", "< 0.6.0"
|
29
29
|
spec.add_dependency "trailblazer-operation", ">= 0.7.0" # TODO: this dependency will be removed.
|
30
30
|
|
31
31
|
spec.required_ruby_version = ">= 2.2.0"
|
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.9
|
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: 2021-
|
12
|
+
date: 2021-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -101,20 +101,20 @@ dependencies:
|
|
101
101
|
requirements:
|
102
102
|
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: 0.
|
104
|
+
version: 0.5.0
|
105
105
|
- - "<"
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version: 0.
|
107
|
+
version: 0.6.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: 0.5.0
|
115
115
|
- - "<"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
117
|
+
version: 0.6.0
|
118
118
|
- !ruby/object:Gem::Dependency
|
119
119
|
name: trailblazer-operation
|
120
120
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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:
|