trailblazer-operation 0.6.0 → 0.6.1
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/CHANGES.md +4 -0
- data/Gemfile +1 -1
- data/lib/trailblazer/operation.rb +0 -1
- data/lib/trailblazer/operation/class_dependencies.rb +24 -15
- data/lib/trailblazer/operation/trace.rb +1 -1
- data/lib/trailblazer/operation/version.rb +1 -1
- data/test/class_dependencies_test.rb +25 -6
- data/test/docs/class_dependencies_test.rb +54 -0
- data/test/trace_test.rb +20 -20
- data/trailblazer-operation.gemspec +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 569ffef484d0783c9f16d35ce6848f8506687140e3fede28f15ab506d832ad5c
|
4
|
+
data.tar.gz: e646b0c9b05dbaba40c136d8345c896727b30cfeba1ee62b5f180e87ff6c05b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d1f804fb97272a858374a5204b033e4ef3ee0a8fe29e29a36e6c3c9f0314b1059b4731b32e9aaf35a9e921b3158cfed53302e6b58fa3070bd3b89b239e49365
|
7
|
+
data.tar.gz: 03353eadeaa413e25ba9deb4847ddedf07827f8b71d16f943a5bf980c499eed231fa8158e60e4492bf449bdbc341c711c109c4fbbb77ade2c858e816a7aff0c9
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
@@ -10,7 +10,7 @@ gem "dry-auto_inject"
|
|
10
10
|
gem "benchmark-ips"
|
11
11
|
gem "minitest-line"
|
12
12
|
|
13
|
-
# gem "trailblazer-developer", path: "../
|
13
|
+
# gem "trailblazer-developer", path: "../developer"
|
14
14
|
# gem "trailblazer-developer", git: "https://github.com/trailblazer/trailblazer-developer"
|
15
15
|
# gem "trailblazer-activity", path: "../trailblazer-activity"
|
16
16
|
# gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
|
@@ -1,25 +1,34 @@
|
|
1
1
|
# Dependencies can be defined on the operation. class level
|
2
2
|
class Trailblazer::Operation
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
3
|
+
# The use of this module is currently not encouraged and it is only here for backward-compatibility.
|
4
|
+
# Instead, please pass dependencies via containers, locals, or macros into the respective steps.
|
5
|
+
module ClassDependencies
|
6
|
+
def [](field)
|
7
|
+
@state.to_h[:fields][field]
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
def []=(field, value)
|
11
|
+
options = @state.to_h[:fields].merge(field => value)
|
12
|
+
@state.update_options(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def options_for_public_call(options, *)
|
16
|
+
ctx = super
|
17
|
+
context_for_fields(class_fields, ctx)
|
18
|
+
end
|
19
|
+
|
20
|
+
private def class_fields
|
21
|
+
@state.to_h[:fields]
|
22
|
+
end
|
23
|
+
|
24
|
+
private def context_for_fields(fields, ctx)
|
25
|
+
ctx_with_fields = Trailblazer::Context.implementation.build(fields, ctx, [ctx, {}], {}) # TODO: redundant to otions_for_public_call. how to inject aliasing etc?
|
13
26
|
end
|
14
|
-
end
|
15
27
|
|
16
|
-
# The use of this module is not encouraged and it is only here for backward-compatibility.
|
17
|
-
# Instead, please pass dependencies via containers, locals, or macros into the respective steps.
|
18
|
-
module ClassDependencies
|
19
28
|
def call_with_circuit_interface((ctx, flow_options), **circuit_options)
|
20
|
-
|
29
|
+
ctx_with_fields = context_for_fields(class_fields, ctx)
|
21
30
|
|
22
|
-
super
|
31
|
+
super([ctx_with_fields, flow_options], circuit_options) # FIXME: should we unwrap here?
|
23
32
|
end
|
24
33
|
end
|
25
34
|
end
|
@@ -24,7 +24,7 @@ module Trailblazer
|
|
24
24
|
|
25
25
|
# Presentation of the traced stack via the returned result object.
|
26
26
|
# This object is wrapped around the original result in {Trace.call}.
|
27
|
-
class Result < SimpleDelegator
|
27
|
+
class Result < ::SimpleDelegator
|
28
28
|
def initialize(result, stack)
|
29
29
|
super(result)
|
30
30
|
@stack = stack
|
@@ -3,13 +3,32 @@ require "test_helper"
|
|
3
3
|
class ClassDependenciesTest < Minitest::Spec
|
4
4
|
#- Operation[] and Operation[]=
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
class Index < Trailblazer::Operation
|
7
|
+
extend ClassDependencies
|
8
8
|
|
9
|
-
|
9
|
+
self["model.class"] = Module
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
step ->(options, **) { options["a"] = options["model.class"] }
|
12
|
+
end
|
13
13
|
|
14
|
-
it {
|
14
|
+
it { Index.({}).inspect("a", "model.class").must_equal %{<Result:true [Module, Module] >} }
|
15
|
+
|
16
|
+
it "creates separate ctx for circuit interface" do
|
17
|
+
signal, (ctx, _) = Index.([{}, {}], {})
|
18
|
+
|
19
|
+
ctx["model.class"].inspect.must_equal %{Module} # FIXME: should this be here?
|
20
|
+
ctx[:a].inspect.must_equal %{Module}
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "inheritance" do
|
24
|
+
it "reader/setter read from separate config" do
|
25
|
+
subclass = Class.new(Index)
|
26
|
+
|
27
|
+
subclass["model.class"].must_equal Module
|
28
|
+
subclass["model.class"] = Class
|
29
|
+
subclass["model.class"].must_equal Class
|
30
|
+
Index["model.class"].must_equal Module
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
15
34
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class DocsClassFieldsTest < Minitest::Spec
|
4
|
+
module A
|
5
|
+
class AlwaysTrue
|
6
|
+
def self.call(params)
|
7
|
+
true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
class Insert < Trailblazer::Operation
|
13
|
+
extend ClassDependencies
|
14
|
+
|
15
|
+
self[:name] = :insert
|
16
|
+
end
|
17
|
+
|
18
|
+
#:create
|
19
|
+
class Create < Trailblazer::Operation
|
20
|
+
extend ClassDependencies
|
21
|
+
|
22
|
+
# Configure some dependency on class level
|
23
|
+
self[:validator] = AlwaysTrue
|
24
|
+
|
25
|
+
step :validate
|
26
|
+
step Subprocess(Insert)
|
27
|
+
|
28
|
+
#:validate
|
29
|
+
def validate(ctx, validator:, params:, **)
|
30
|
+
validator.(params)
|
31
|
+
end
|
32
|
+
#:validate end
|
33
|
+
end
|
34
|
+
#:create end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "what" do
|
38
|
+
Create = A::Create
|
39
|
+
|
40
|
+
ctx = {params: {name: "Yogi"}}
|
41
|
+
|
42
|
+
#:invoke
|
43
|
+
signal, (ctx, _) = Create.([ctx, {}])
|
44
|
+
|
45
|
+
puts ctx[:validator] #=> AlwaysTrue
|
46
|
+
#:invoke end
|
47
|
+
|
48
|
+
puts ctx[:name] #=> insert
|
49
|
+
|
50
|
+
signal.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
|
51
|
+
ctx[:validator].inspect.must_equal %{DocsClassFieldsTest::A::AlwaysTrue}
|
52
|
+
ctx[:name].inspect.must_equal %{:insert}
|
53
|
+
end
|
54
|
+
end
|
data/test/trace_test.rb
CHANGED
@@ -28,30 +28,30 @@ class TraceTest < Minitest::Spec
|
|
28
28
|
puts output = Trailblazer::Developer::Trace::Present.(stack)
|
29
29
|
|
30
30
|
output.gsub(/0x\w+/, "").gsub(/@.+_test/, "").must_equal %{`-- TraceTest::Create
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
31
|
+
|-- Start.default
|
32
|
+
|-- Create.task.a
|
33
|
+
|-- MyNested
|
34
|
+
| |-- Start.default
|
35
|
+
| |-- B.task.b
|
36
|
+
| |-- B.task.e
|
37
|
+
| `-- End.success
|
38
|
+
|-- Create.task.c
|
39
|
+
|-- Create.task.params
|
40
|
+
`-- End.failure}
|
41
41
|
end
|
42
42
|
|
43
43
|
it "Operation::trace" do
|
44
44
|
result = Create.trace(params: {x: 1}, a_return: true)
|
45
45
|
result.wtf.gsub(/0x\w+/, "").gsub(/@.+_test/, "").must_equal %{`-- TraceTest::Create
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
|-- Start.default
|
47
|
+
|-- Create.task.a
|
48
|
+
|-- MyNested
|
49
|
+
| |-- Start.default
|
50
|
+
| |-- B.task.b
|
51
|
+
| |-- B.task.e
|
52
|
+
| `-- End.success
|
53
|
+
|-- Create.task.c
|
54
|
+
|-- Create.task.params
|
55
|
+
`-- End.success}
|
56
56
|
end
|
57
57
|
end
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "trailblazer-activity-dsl-linear", ">= 0.2.
|
20
|
+
spec.add_dependency "trailblazer-activity-dsl-linear", ">= 0.2.6", "< 1.0.0"
|
21
21
|
spec.add_dependency "trailblazer-activity", ">= 0.10.0", "< 1.0.0"
|
22
22
|
spec.add_dependency "trailblazer-developer", ">= 0.0.8"
|
23
23
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-operation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trailblazer-activity-dsl-linear
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.
|
19
|
+
version: 0.2.6
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 1.0.0
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.2.
|
29
|
+
version: 0.2.6
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.0.0
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- test/call_test.rb
|
151
151
|
- test/callable_test.rb
|
152
152
|
- test/class_dependencies_test.rb
|
153
|
+
- test/docs/class_dependencies_test.rb
|
153
154
|
- test/docs/doormat_test.rb
|
154
155
|
- test/docs/macaroni_test.rb
|
155
156
|
- test/docs/operation_test.rb
|
@@ -193,8 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
194
|
- !ruby/object:Gem::Version
|
194
195
|
version: '0'
|
195
196
|
requirements: []
|
196
|
-
|
197
|
-
rubygems_version: 2.7.6
|
197
|
+
rubygems_version: 3.0.8
|
198
198
|
signing_key:
|
199
199
|
specification_version: 4
|
200
200
|
summary: Trailblazer's operation object with railway flow and integrated error handling.
|
@@ -203,6 +203,7 @@ test_files:
|
|
203
203
|
- test/call_test.rb
|
204
204
|
- test/callable_test.rb
|
205
205
|
- test/class_dependencies_test.rb
|
206
|
+
- test/docs/class_dependencies_test.rb
|
206
207
|
- test/docs/doormat_test.rb
|
207
208
|
- test/docs/macaroni_test.rb
|
208
209
|
- test/docs/operation_test.rb
|