trailblazer-operation 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.rubocop_todo.yml +223 -0
  4. data/.travis.yml +6 -7
  5. data/CHANGES.md +2 -14
  6. data/Gemfile +4 -2
  7. data/README.md +13 -2
  8. data/Rakefile +2 -2
  9. data/lib/trailblazer/operation.rb +53 -67
  10. data/lib/trailblazer/operation/class_dependencies.rb +1 -1
  11. data/lib/trailblazer/operation/container.rb +14 -0
  12. data/lib/trailblazer/operation/deprecated_macro.rb +2 -2
  13. data/lib/trailblazer/operation/inspect.rb +17 -27
  14. data/lib/trailblazer/operation/public_call.rb +16 -18
  15. data/lib/trailblazer/operation/railway.rb +2 -3
  16. data/lib/trailblazer/operation/railway/macaroni.rb +2 -2
  17. data/lib/trailblazer/operation/result.rb +14 -1
  18. data/lib/trailblazer/operation/trace.rb +5 -8
  19. data/lib/trailblazer/operation/version.rb +4 -2
  20. data/test/benchmark/skill_resolver_benchmark.rb +8 -9
  21. data/test/call_test.rb +56 -30
  22. data/test/callable_test.rb +147 -147
  23. data/test/class_dependencies_test.rb +6 -7
  24. data/test/docs/doormat_test.rb +13 -12
  25. data/test/docs/macaroni_test.rb +7 -9
  26. data/test/docs/operation_test.rb +69 -4
  27. data/test/docs/wiring_test.rb +98 -53
  28. data/test/dry_container_test.rb +4 -3
  29. data/test/fast_track_test.rb +24 -44
  30. data/test/inheritance_test.rb +13 -12
  31. data/test/inspect_test.rb +6 -7
  32. data/test/introspect_test.rb +6 -6
  33. data/test/operation_test.rb +17 -25
  34. data/test/result_test.rb +4 -4
  35. data/test/ruby-2.0.0/operation_test.rb +9 -9
  36. data/test/ruby-2.0.0/step_test.rb +17 -16
  37. data/test/step_test.rb +47 -42
  38. data/test/test_helper.rb +6 -13
  39. data/test/trace_test.rb +26 -26
  40. data/test/wiring/defaults_test.rb +29 -33
  41. data/trailblazer-operation.gemspec +7 -6
  42. metadata +26 -18
  43. data/lib/trailblazer/operation/heritage.rb +0 -30
  44. data/lib/trailblazer/operation/inject.rb +0 -36
  45. data/lib/trailblazer/operation/railway/fast_track.rb +0 -13
  46. data/lib/trailblazer/operation/railway/normalizer.rb +0 -58
  47. data/lib/trailblazer/operation/railway/task_builder.rb +0 -37
  48. data/test/macro_test.rb +0 -60
  49. data/test/task_wrap_test.rb +0 -97
@@ -7,32 +7,33 @@ require "test_helper"
7
7
  # --- step MyMacro
8
8
  class StepTest < Minitest::Spec
9
9
  class Callable
10
- def self.call(options, b:nil, **o)
10
+ def self.call(options, b: nil, **_o)
11
11
  options["b"] = b
12
12
  end
13
13
  end
14
14
 
15
15
  module Implementation
16
16
  module_function
17
- def c(options, c:nil, **o)
17
+
18
+ def c(options, c: nil, **_o)
18
19
  options["c"] = c
19
20
  end
20
21
  end
21
22
 
22
- MyMacro = ->( direction, options, flow_options ) do
23
+ MyMacro = ->(direction, options, flow_options) do
23
24
  options["e"] = options[:e]
24
25
 
25
- [ direction, options, flow_options ]
26
+ [direction, options, flow_options]
26
27
  end
27
28
 
28
29
  class Create < Trailblazer::Operation
29
- step ->(options, a:nil, **o) { options["a"] = a }
30
+ step ->(options, a: nil, **_o) { options["a"] = a }
30
31
  step Callable
31
32
  step Implementation.method(:c)
32
33
  step :d
33
- step [ MyMacro, {} ] # doesn't provide runner_options.
34
+ step [MyMacro, {}] # doesn't provide runner_options.
34
35
 
35
- def d(options, d:nil, **o)
36
+ def d(options, d: nil, **_o)
36
37
  options["d"] = d
37
38
  end
38
39
  end
@@ -47,8 +48,8 @@ class StepTest < Minitest::Spec
47
48
  #- :before, :after, :replace, :delete, :override
48
49
  class A < Trailblazer::Operation
49
50
  step :a!
50
- def a!(options, **o); options["a"] = 1; end
51
- def a!(options, **o); options["a"] = 1; end if RUBY_VERSION == "2.0.0"
51
+ def a!(options, **_o); options["a"] = 1; end
52
+ def a!(options, **_o); options["a"] = 1; end if RUBY_VERSION == "2.0.0"
52
53
  end
53
54
 
54
55
  class B < A
@@ -76,7 +77,7 @@ class StepTest < Minitest::Spec
76
77
 
77
78
  # not existent :name
78
79
  it do
79
- err = assert_raises Trailblazer::Operation::Railway::Sequence::IndexError do
80
+ err = assert_raises Trailblazer::Operation::Railway::Sequence::IndexError do
80
81
  class E < Trailblazer::Operation
81
82
  step :a, before: "I don't exist!"
82
83
  end
@@ -91,8 +92,8 @@ class StepTest < Minitest::Spec
91
92
  class Index < Trailblazer::Operation
92
93
  step :validate!, name: "my validate"
93
94
  step :persist!
94
- step [ MyMacro, name: "I win!" ]
95
- step [ MyMacro, name: "I win!" ], name: "No, I do!"
95
+ step [MyMacro, name: "I win!"]
96
+ step [MyMacro, name: "I win!"], name: "No, I do!"
96
97
  end
97
98
 
98
99
  it { Trailblazer::Operation::Inspect.(Index).must_equal %{[>my validate,>persist!,>I win!,>No, I do!]} }
@@ -114,7 +115,8 @@ end
114
115
  #---
115
116
  #- Macros with the old `input` arg.
116
117
  # step [ ->(input, options) { } ]
117
- class StepWithDeprecatedMacroTest < Minitest::Spec # TODO: remove me in 2.2.
118
+ # TODO: remove me in 2.2.
119
+ class StepWithDeprecatedMacroTest < Minitest::Spec
118
120
  class Create < Trailblazer::Operation
119
121
  MyOutdatedMacro = ->(input, options) {
120
122
  options["x"] = input.class
@@ -126,11 +128,10 @@ class StepWithDeprecatedMacroTest < Minitest::Spec # TODO: remove me in 2.2.
126
128
  end
127
129
  end
128
130
 
129
- step [ MyOutdatedMacro, name: :outdated ]
130
- step [ AnotherOldMacro, name: :oldie ]
131
+ step [MyOutdatedMacro, name: :outdated]
132
+ step [AnotherOldMacro, name: :oldie]
131
133
  end
132
134
 
133
135
  it { Trailblazer::Operation::Inspect.(Create).gsub(/0x.+?step_test.rb/, "").must_equal %{[>outdated,>oldie]} }
134
136
  it { Create.().inspect("x", "y").must_equal %{<Result:true [StepWithDeprecatedMacroTest::Create, StepWithDeprecatedMacroTest::Create] >} }
135
137
  end
136
-
data/test/step_test.rb CHANGED
@@ -7,45 +7,46 @@ require "test_helper"
7
7
  # --- step MyMacro
8
8
  class StepTest < Minitest::Spec
9
9
  class Callable
10
- def self.call(options, b:nil, **)
10
+ def self.call(options, b: nil, **)
11
11
  options["b"] = b
12
12
  end
13
13
  end
14
14
 
15
15
  module Implementation
16
16
  module_function
17
- def c(options, c:nil, **)
17
+
18
+ def c(options, c: nil, **)
18
19
  options["c"] = c
19
20
  end
20
21
  end
21
22
 
22
- MyMacro = ->( (options, flow_options), * ) do
23
+ MyMacro = ->((options, flow_options), *) do
23
24
  options["e"] = options[:e]
24
25
 
25
- [ Trailblazer::Activity::Right, options, flow_options ]
26
+ [Trailblazer::Activity::Right, options, flow_options]
26
27
  end
27
28
 
28
29
  class Create < Trailblazer::Operation
29
- step ->(options, a:nil, **) { options["a"] = a }
30
+ step ->(options, a: nil, **) { options["a"] = a }
30
31
  step Callable
31
32
  step Implementation.method(:c)
32
33
  step :d
33
- step( { task: MyMacro, id: "MyMacro" } ) # doesn't provide `runner_options` and `outputs`.
34
+ step(task: MyMacro, id: "MyMacro") # doesn't provide `runner_options` and `outputs`.
34
35
 
35
- def d(options, d:nil, **)
36
+ def d(options, d: nil, **)
36
37
  options["d"] = d
37
38
  end
38
39
  end
39
40
 
40
41
  it { Create.(a: 1, b: 2, c: 3, d: 4, e: 5).inspect("a", "b", "c", "d", "e").must_equal "<Result:true [1, 2, 3, 4, 5] >" }
41
42
 
42
- it { Trailblazer::Operation::Inspect.(Create).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::29 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro]} }
43
+ it { Trailblazer::Operation::Inspect.(Create).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::30 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro]} }
43
44
 
44
45
  #---
45
46
  #- :before, :after, :replace, :delete, :override
46
47
  class A < Trailblazer::Operation
47
48
  step :a!
48
- def a!(options, **); options["order"] << "a" ; end
49
+ def a!(options, **); options["order"] << "a"; end
49
50
  end
50
51
 
51
52
  class B < A
@@ -53,9 +54,11 @@ class StepTest < Minitest::Spec
53
54
  step :c!, before: :a!
54
55
  step :d!, after: :b!
55
56
 
56
- def b!(options, **); options["order"] << "b" ; end
57
- def c!(options, **); options["order"] << "c" ; end
58
- def d!(options, **); options["order"] << "d" ; end
57
+ def b!(options, **); options["order"] << "b"; end
58
+
59
+ def c!(options, **); options["order"] << "c"; end
60
+
61
+ def d!(options, **); options["order"] << "d"; end
59
62
  end
60
63
 
61
64
  it { Trailblazer::Operation::Inspect.(B).must_equal %{[>b!,>d!,>c!,>a!]} }
@@ -63,20 +66,21 @@ class StepTest < Minitest::Spec
63
66
  class C < B
64
67
  step :e!, replace: :c!
65
68
  step "nil", delete: :d!
66
- def e!(options, **); options["order"] << "e" ; end
69
+ def e!(options, **); options["order"] << "e"; end
67
70
  end
68
71
 
69
72
  it { Trailblazer::Operation::Inspect.(C).must_equal %{[>b!,>e!,>a!]} }
70
- it { C.("order"=>[]).inspect("order").must_equal %{<Result:true [["b", "e", "a"]] >} }
73
+ it { C.("order" => []).inspect("order").must_equal %{<Result:true [["b", "e", "a"]] >} }
71
74
 
72
75
  #---
73
76
  #- override: true
74
77
  class D < Trailblazer::Operation
75
78
  step :a!
76
79
  step :add!
77
- step :add!, id: :another_add!#, override: true
80
+ step :add!, id: :another_add! # , override: true
78
81
 
79
82
  def a!(options, **); options["a"] = []; end
83
+
80
84
  def add!(options, **); options["a"] << :b; end
81
85
  end
82
86
 
@@ -84,16 +88,17 @@ class StepTest < Minitest::Spec
84
88
  it { D.().inspect("a").must_equal %{<Result:true [[:b, :b]] >} }
85
89
 
86
90
  class E < Trailblazer::Operation
87
- step :a!
88
- step :add!
89
- step :add!, override: true
91
+ imp = T.def_task(:b)
90
92
 
91
- def a!(options, **); options["a"] = []; end
92
- def add!(options, **); options["a"] << :b; end
93
+ step :a
94
+ step(task: :b, id: :b)
95
+ step({task: imp, id: :b}, override: true)
96
+
97
+ include T.def_steps(:a)
93
98
  end
94
99
 
95
- it { Trailblazer::Operation::Inspect.(E).must_equal %{[>a!,>add!]} }
96
- it { E.().inspect("a").must_equal %{<Result:true [[:b]] >} }
100
+ it { Trailblazer::Operation::Inspect.(E).must_equal %{[>a,>b]} }
101
+ it { E.(seq: []).inspect(:seq).must_equal %{<Result:true [[:a, :b]] >} }
97
102
 
98
103
  #- with proc
99
104
  class F < Trailblazer::Operation
@@ -109,13 +114,13 @@ class StepTest < Minitest::Spec
109
114
 
110
115
  #- with macro
111
116
  class G < Trailblazer::Operation
112
- MyMacro1 = ->((options, flow_options), *) { options["a"] << :b; [ Trailblazer::Activity::Right, options, flow_options ] }
113
- MyMacro2 = ->((options, flow_options), *) { options["a"] << :b; [ Trailblazer::Activity::Right, options, flow_options ] }
117
+ MyMacro1 = ->((options, flow_options), *) { options["a"] << :b; [Trailblazer::Activity::Right, options, flow_options] }
118
+ MyMacro2 = ->((options, flow_options), *) { options["a"] << :b; [Trailblazer::Activity::Right, options, flow_options] }
114
119
  # MyMacro3 = ->(options, flow_options) { options["a"] << :b; [ Trailblazer::Activity::Right, options, flow_options ] }
115
120
 
116
121
  step :a!
117
- step( { task: MyMacro1, id: "add" })
118
- step( { task: MyMacro2, id: "add" }, replace: "add")
122
+ step(task: MyMacro1, id: "add")
123
+ step({task: MyMacro2, id: "add"}, replace: "add")
119
124
  # step [ MyMacro3, {id: "add"}, {} ], override: true
120
125
 
121
126
  def a!(options, **); options["a"] = []; end
@@ -126,7 +131,7 @@ class StepTest < Minitest::Spec
126
131
 
127
132
  # override: true in inherited class with macro
128
133
  class Go < G
129
- MyMacro = ->((options, flow_options), *) { options["a"] << :m; [ Trailblazer::Activity::Right, options, flow_options ] }
134
+ MyMacro = ->((options, flow_options), *) { options["a"] << :m; [Trailblazer::Activity::Right, options, flow_options] }
130
135
  step task: MyMacro, override: true, id: "add"
131
136
  end
132
137
 
@@ -139,6 +144,7 @@ class StepTest < Minitest::Spec
139
144
  step :add!
140
145
 
141
146
  def a!(options, **); options["a"] = []; end
147
+
142
148
  def add!(options, **); options["a"] << :b; end
143
149
  end
144
150
 
@@ -157,23 +163,21 @@ class StepTest < Minitest::Spec
157
163
  end
158
164
 
159
165
  class Ii < I
160
- step :a, override: true
166
+ step({task: T.def_task(:b), id: :a}, override: true)
161
167
  end
162
168
 
163
169
  # FIXME: we have all fast track ends here.
164
- it { skip;Ii["__activity__"].circuit.instance_variable_get(:@map).size.must_equal 6 }
170
+ it { skip; Ii["__activity__"].circuit.instance_variable_get(:@map).size.must_equal 6 }
165
171
 
166
172
  #---
167
173
  #-
168
174
  # not existent :name
169
175
  it do
170
- assert_raises Trailblazer::Activity::Schema::Sequence::IndexError do
171
-
176
+ assert_raises Trailblazer::Activity::DSL::Linear::Sequence::IndexError do
172
177
  Class.new(Trailblazer::Operation) do
173
178
  step :a, before: "I don't exist!"
174
179
  end
175
-
176
- end.inspect.must_equal "#<Trailblazer::Activity::Schema::Sequence::IndexError: I don't exist!>"
180
+ end.inspect.must_equal %{#<Trailblazer::Activity::DSL::Linear::Sequence::IndexError: "I don't exist!">}
177
181
  end
178
182
 
179
183
  #---
@@ -182,8 +186,8 @@ class StepTest < Minitest::Spec
182
186
  class Index < Trailblazer::Operation
183
187
  step :validate!, id: "my validate"
184
188
  step :persist!
185
- step( { task: MyMacro, id: "I win!" })
186
- step( { task: MyMacro, id: "I win!" }, id: "No, I do!")
189
+ step(task: MyMacro, id: "I win!")
190
+ step({task: "MyMacro", id: "I win!"}, id: "No, I do!")
187
191
  end
188
192
 
189
193
  it { Trailblazer::Operation::Inspect.(Index).must_equal %{[>my validate,>persist!,>I win!,>No, I do!]} }
@@ -193,19 +197,20 @@ class StepTest < Minitest::Spec
193
197
  class New < Create
194
198
  end
195
199
 
196
- it { Trailblazer::Operation::Inspect.(New).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::29 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro]} }
200
+ it { Trailblazer::Operation::Inspect.(New).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::30 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro]} }
197
201
 
198
202
  class Update < Create
199
203
  step :after_save!
200
204
  end
201
205
 
202
- it { Trailblazer::Operation::Inspect.(Update).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::29 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro,>after_save!]} }
206
+ it { Trailblazer::Operation::Inspect.(Update).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::30 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro,>after_save!]} }
203
207
  end
204
208
 
205
209
  #---
206
210
  #- Macros with the old `input` arg.
207
211
  # step [ ->(input, options) { } ]
208
- class StepWithDeprecatedMacroTest < Minitest::Spec # TODO: remove me in 2.2.
212
+ # TODO: remove me in 2.2.
213
+ class StepWithDeprecatedMacroTest < Minitest::Spec
209
214
  class Create < Trailblazer::Operation
210
215
  MyOutdatedMacro = ->(input, options) {
211
216
  options["x"] = input.class
@@ -217,12 +222,12 @@ class StepWithDeprecatedMacroTest < Minitest::Spec # TODO: remove me in 2.2.
217
222
  end
218
223
  end
219
224
 
220
- step [ MyOutdatedMacro, id: :outdated ]
221
- step [ AnotherOldMacro, id: :oldie ]
225
+ step [MyOutdatedMacro, id: :outdated]
226
+ step [AnotherOldMacro, id: :oldie]
222
227
  end
223
228
 
224
- it { Trailblazer::Operation::Inspect.(Create).gsub(/0x.+?step_test.rb/, "").must_equal %{[>outdated,>oldie]} }
225
- it { Create.().inspect("x", "y").must_equal %{<Result:true [StepWithDeprecatedMacroTest::Create, StepWithDeprecatedMacroTest::Create] >} }
229
+ it { skip; Trailblazer::Operation::Inspect.(Create).gsub(/0x.+?step_test.rb/, "").must_equal %{[>outdated,>oldie]} }
230
+ it { skip; Create.().inspect("x", "y").must_equal %{<Result:true [StepWithDeprecatedMacroTest::Create, StepWithDeprecatedMacroTest::Create] >} }
226
231
  end
227
232
 
228
233
  # TODO: test failure and success aliases properly.
data/test/test_helper.rb CHANGED
@@ -2,9 +2,14 @@ require "pp"
2
2
 
3
3
  require "minitest/autorun"
4
4
  require "trailblazer/operation"
5
+ require "trailblazer/activity/testing"
5
6
 
6
- Minitest::Spec::Activity = Trailblazer::Activity
7
+ Minitest::Spec.class_eval do
8
+ Activity = Trailblazer::Activity
9
+ T = Activity::Testing
10
+ end
7
11
 
12
+ # TODO: replace all this with {Activity::Testing.def_steps}
8
13
  module Test
9
14
  # Create a step method in `klass` with the following body.
10
15
  #
@@ -18,22 +23,10 @@ module Test
18
23
  method_def =
19
24
  %{def #{name}(options, #{name}_return:, data:, **)
20
25
  data << :#{name}
21
-
22
26
  #{name}_return
23
27
  end}
24
28
 
25
29
  klass.class_eval(method_def)
26
30
  end
27
31
  end
28
-
29
- # builder for PlusPoles
30
- def self.plus_poles_for(mapping)
31
- ary = mapping.collect { |evt, semantic| [Trailblazer:: Activity::Output(evt, semantic), semantic ] }
32
-
33
- Trailblazer::Activity::Magnetic::DSL::PlusPoles.new.merge(::Hash[ary])
34
- end
35
- end
36
-
37
- Minitest::Spec.class_eval do
38
- Activity = Trailblazer::Activity
39
32
  end
data/test/trace_test.rb CHANGED
@@ -8,19 +8,19 @@ class TraceTest < Minitest::Spec
8
8
 
9
9
  class Create < Trailblazer::Operation
10
10
  step ->(options, a_return:, **) { options[:a] = a_return }, id: "Create.task.a"
11
- step( {task: B, id: "MyNested"}, B.outputs[:success] => Track(:success) )
11
+ step({task: B, id: "MyNested"}, B.to_h[:outputs][0] => Track(:success))
12
12
  step ->(options, **) { options[:c] = true }, id: "Create.task.c"
13
- step ->(options, params:, **) { params.any? }, id: "Create.task.params"
13
+ step ->(_options, params:, **) { params.any? }, id: "Create.task.params"
14
14
  end
15
15
  # raise Create["__task_wraps__"].inspect
16
16
 
17
17
  it "allows using low-level Activity::Trace" do
18
- operation = ->(*args) { puts "@@@@@ #{args.last.inspect}"; Create.__call__(*args) }
18
+ ->(*args) { puts "@@@@@ #{args.last.inspect}"; Create.__call__(*args) }
19
19
 
20
- stack, _ = Trailblazer::Activity::Trace.(
20
+ stack, = Trailblazer::Activity::Trace.(
21
21
  Create,
22
22
  [
23
- { a_return: true, params: {} },
23
+ {a_return: true, params: {}},
24
24
  {}
25
25
  ]
26
26
  )
@@ -28,30 +28,30 @@ class TraceTest < Minitest::Spec
28
28
  puts output = Trailblazer::Activity::Trace::Present.(stack)
29
29
 
30
30
  output.gsub(/0x\w+/, "").gsub(/@.+_test/, "").must_equal %{`-- TraceTest::Create
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}
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
- result = Create.trace({ params: { x: 1 }, a_return: true })
44
+ result = Create.trace(params: {x: 1}, a_return: true)
45
45
  result.wtf.gsub(/0x\w+/, "").gsub(/@.+_test/, "").must_equal %{`-- TraceTest::Create
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}
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
@@ -59,7 +59,6 @@ require "test_helper"
59
59
  # [ [:failure], Trailblazer::Operation::Railway::End::Failure.new(:failure), [] ],
60
60
  # ]
61
61
 
62
-
63
62
  # graph = Trailblazer::Activity::Schema.bla(steps + ends)
64
63
  # circuit = Trailblazer::Activity.new(graph)
65
64
  # # pp schema
@@ -79,67 +78,66 @@ require "test_helper"
79
78
  class WireDefaultsEarlyExitSuccessTest < Minitest::Spec
80
79
  class Create < Trailblazer::Operation
81
80
  step :a
82
- fail :b, Output(:success) => Track(:success) #{}"End.success"
81
+ fail :b, Output(:success) => Track(:success) # {}"End.success"
83
82
  fail :c, Output(:success) => Track(:success)
84
83
 
85
84
  Test.step(self, :a, :b, :c)
86
85
  end
87
86
 
88
87
  # a => true
89
- it { Create.( a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a]] >} }
88
+ it { Create.(a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a]] >} }
90
89
  # b => true
91
- it { Create.( a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b]] >} }
90
+ it { Create.(a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b]] >} }
92
91
  # c => true
93
- it { Create.( a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c]] >} }
92
+ it { Create.(a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c]] >} }
94
93
  # a => b => c => false
95
- it { Create.( a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
94
+ it { Create.(a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
96
95
 
97
96
  # # require "trailblazer/developer"
98
97
  # # it { Trailblazer::Developer::Client.push( operation: Create, name: "ushi" ) }
99
98
 
100
-
101
99
  # #---
102
100
  # # with => Track(:success), steps can still be added before End.success and they will be executed.
103
101
  class Update < Create
104
102
  pass :d
105
103
 
106
- def d(options, data:, **)
104
+ def d(_options, data:, **)
107
105
  data << :d
108
106
  end
109
107
  end
110
108
 
111
109
  # a => true
112
- it { Update.( a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
110
+ it { Update.(a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
113
111
  # b => true
114
- it { Update.( a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :d]] >} }
112
+ it { Update.(a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :d]] >} }
115
113
  # c => true
116
- it { Update.( a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c, :d]] >} }
114
+ it { Update.(a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c, :d]] >} }
117
115
  # a => b => c => false
118
- it { Update.( a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
116
+ it { Update.(a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
119
117
 
120
118
  #---
121
119
  # failure steps reference End.success and not just the polarization. This won't call #d in failure=>success case.
122
120
  class Delete < Trailblazer::Operation
123
121
  step :a
124
- fail :b, Output(:success) => "End.success"
125
- fail :c, Output(:success) => "End.success"
122
+ fail :b, Output(:success) => Id("End.success")
123
+ fail :c, Output(:success) => Id("End.success")
126
124
  pass :d
127
125
 
128
- Test.step(self, :a, :b, :c)
126
+ Test.step(self, :a, :b, :c, :d)
129
127
 
130
- def d(options, data:, **)
128
+ def d(_options, data:, **)
131
129
  data << :d
132
130
  end
133
131
  end
134
132
 
135
133
  # a => true
136
- it { Delete.( a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
134
+ it { Delete.(a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
137
135
  # b => true
138
- it { Delete.( a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b]] >} }
136
+ it { Delete.(a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b]] >} }
139
137
  # c => true
140
- it { Delete.( a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c]] >} }
138
+ it { Delete.(a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c]] >} }
141
139
  # a => b => c => false
142
- it { Delete.( a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
140
+ it { Delete.(a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
143
141
 
144
142
  #---
145
143
  # |----|
@@ -147,13 +145,13 @@ class WireDefaultsEarlyExitSuccessTest < Minitest::Spec
147
145
  # |_____|_|_______ E.f
148
146
  class Connect < Trailblazer::Operation
149
147
  step :a
150
- step :b, Output(:success) => "d"
148
+ step :b, Output(:success) => Id("d")
151
149
  step :c, magnetic_to: [] # otherwise :success will be an open input!
152
150
  pass :d, id: "d"
153
151
 
154
152
  Test.step(self, :a, :b, :c)
155
153
 
156
- def d(options, data:, **)
154
+ def d(_options, data:, **)
157
155
  data << :d
158
156
  end
159
157
  end
@@ -161,11 +159,11 @@ class WireDefaultsEarlyExitSuccessTest < Minitest::Spec
161
159
  # it { puts Trailblazer::Activity::Magnetic::Introspect.seq( Connect.decompose.first ) }
162
160
 
163
161
  # a => true
164
- it { Connect.( a_return: true, b_return: true,data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :d]] >} }
162
+ it { Connect.(a_return: true, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :d]] >} }
165
163
  # a => false
166
- it { Connect.( a_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a]] >} }
164
+ it { Connect.(a_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a]] >} }
167
165
  # b => false
168
- it { Connect.( a_return: true, b_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b]] >} }
166
+ it { Connect.(a_return: true, b_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b]] >} }
169
167
 
170
168
  #---
171
169
  # |---------|
@@ -175,8 +173,8 @@ class WireDefaultsEarlyExitSuccessTest < Minitest::Spec
175
173
  # | \ / V
176
174
  # |__f____g----E.f
177
175
  class Post < Trailblazer::Operation
178
- step :a, Output(:success) => "d", id: "a"
179
- fail :f, Output(:success) => "c"
176
+ step :a, Output(:success) => Id("d"), id: "a"
177
+ fail :f, Output(:success) => Id("c")
180
178
  step :c, magnetic_to: [], id: "c" # otherwise :success will be an open input!
181
179
  fail :g
182
180
  step :d, id: "d"
@@ -184,14 +182,12 @@ class WireDefaultsEarlyExitSuccessTest < Minitest::Spec
184
182
  Test.step(self, :a, :f, :c, :g, :d)
185
183
  end
186
184
 
187
- pp Post["__sequence__"]
188
-
189
185
  # a => true
190
- it { Post.( a_return: true, d_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
186
+ it { Post.(a_return: true, d_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
191
187
  # a => false
192
- it { Post.( a_return: false, f_return: false, g_return: nil, data: []).inspect(:data).must_equal %{<Result:false [[:a, :f, :g]] >} }
188
+ it { Post.(a_return: false, f_return: false, g_return: nil, data: []).inspect(:data).must_equal %{<Result:false [[:a, :f, :g]] >} }
193
189
  # a => false, f => true
194
- it { Post.( a_return: false, f_return: true, c_return: true, d_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :f, :c, :d]] >} }
190
+ it { Post.(a_return: false, f_return: true, c_return: true, d_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :f, :c, :d]] >} }
195
191
  # a => false, f => true, c => false
196
- it { Post.( a_return: false, f_return: true, c_return: false, g_return: true, data: []).inspect(:data).must_equal %{<Result:false [[:a, :f, :c, :g]] >} }
192
+ it { Post.(a_return: false, f_return: true, c_return: false, g_return: true, data: []).inspect(:data).must_equal %{<Result:false [[:a, :f, :c, :g]] >} }
197
193
  end