trailblazer-operation 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/Gemfile +1 -1
- data/lib/trailblazer/operation.rb +0 -2
- data/lib/trailblazer/operation/version.rb +1 -1
- data/test/docs/wiring_test.rb +0 -113
- data/test/step_test.rb +13 -13
- data/test/test_helper.rb +1 -0
- data/trailblazer-operation.gemspec +1 -0
- metadata +16 -5
- data/lib/trailblazer/operation/inspect.rb +0 -69
- data/test/inspect_test.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72f9bed867af38feb73cc3cd6eae06ac1621870649d315d93c17ef2fb2f01c9d
|
4
|
+
data.tar.gz: e4c512de05dd2dda4c670d0322455d9e0e2b8b3e646e237c553e4e49d8db70cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 808122f1bb28e26261afa083fd9718811d2c578a9e230cc59f091f623b447d17daece7f8caad233b8069bce50e99e45f04670f4037cef01d5e8ee697a795cd44
|
7
|
+
data.tar.gz: 7161f4c1341072a67c9d02fca6b1fb8d8c11befe66f722ab65a455bfbf0a226dc19dce8c1d6adb9beb6a490b753d7722b077e9a7d63b6ae10a3cc6ff01e617a1
|
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
|
-
|
13
|
+
gem "trailblazer-developer", path: "../trailblazer-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"
|
data/test/docs/wiring_test.rb
CHANGED
@@ -287,119 +287,6 @@ describe all options :pass_fast, :fast_track and emiting signals directly, like
|
|
287
287
|
end
|
288
288
|
end
|
289
289
|
|
290
|
-
=begin
|
291
|
-
:before, :after, :replace, :delete, :group, :id
|
292
|
-
=end
|
293
|
-
class WiringsDocSeqOptionsTest < Minitest::Spec
|
294
|
-
module Id
|
295
|
-
Memo = Class.new(WiringDocsTest::Memo)
|
296
|
-
|
297
|
-
#:id
|
298
|
-
class Memo::Create < Trailblazer::Operation
|
299
|
-
step :create_model, id: "create_memo"
|
300
|
-
step :validate, id: "validate_params"
|
301
|
-
step :save
|
302
|
-
#~id-methods
|
303
|
-
def create_model(options, **)
|
304
|
-
end
|
305
|
-
|
306
|
-
def validate(options, **)
|
307
|
-
end
|
308
|
-
|
309
|
-
def save(options, **)
|
310
|
-
end
|
311
|
-
#~id-methods end
|
312
|
-
end
|
313
|
-
#:id end
|
314
|
-
|
315
|
-
#:delete
|
316
|
-
class Memo::Create::Admin < Memo::Create
|
317
|
-
step nil, delete: "validate_params", id: ""
|
318
|
-
end
|
319
|
-
#:delete end
|
320
|
-
|
321
|
-
#:before
|
322
|
-
class Memo::Create::Authorized < Memo::Create
|
323
|
-
step :policy, before: "create_memo"
|
324
|
-
#~before-methods
|
325
|
-
def policy(options, **)
|
326
|
-
end
|
327
|
-
#~before-methods end
|
328
|
-
end
|
329
|
-
#:before end
|
330
|
-
|
331
|
-
#:after
|
332
|
-
class Memo::Create::Logging < Memo::Create
|
333
|
-
step :logger, after: "validate_params"
|
334
|
-
#~after-methods
|
335
|
-
def logger(options, **)
|
336
|
-
end
|
337
|
-
#~after-methods end
|
338
|
-
end
|
339
|
-
#:after end
|
340
|
-
|
341
|
-
#:replace
|
342
|
-
class Memo::Update < Memo::Create
|
343
|
-
step :find_model, replace: "create_memo", id: "update_memo"
|
344
|
-
#~replace-methods
|
345
|
-
def find_model(options, **)
|
346
|
-
end
|
347
|
-
#~replace-methods end
|
348
|
-
end
|
349
|
-
#:replace end
|
350
|
-
end
|
351
|
-
|
352
|
-
it ":id shows up in introspect" do
|
353
|
-
Memo = Id::Memo
|
354
|
-
#:id-inspect
|
355
|
-
Trailblazer::Operation.introspect(Memo::Create)
|
356
|
-
#=> [>create_memo,>validate_params,>save]
|
357
|
-
#:id-inspect end
|
358
|
-
|
359
|
-
Trailblazer::Operation.introspect(Memo::Create).must_equal %{[>create_memo,>validate_params,>save]}
|
360
|
-
end
|
361
|
-
|
362
|
-
it ":delete removes step" do
|
363
|
-
Memo = Id::Memo
|
364
|
-
#:delete-inspect
|
365
|
-
Trailblazer::Operation.introspect(Memo::Create::Admin)
|
366
|
-
#=> [>create_model,>save]
|
367
|
-
#:delete-inspect end
|
368
|
-
|
369
|
-
Trailblazer::Operation.introspect(Memo::Create::Admin).must_equal %{[>create_memo,>save]}
|
370
|
-
end
|
371
|
-
|
372
|
-
it ":before inserts" do
|
373
|
-
Memo = Id::Memo
|
374
|
-
#:before-inspect
|
375
|
-
Trailblazer::Operation.introspect(Memo::Create::Authorized)
|
376
|
-
#=> [>create_model,>save]
|
377
|
-
#:before-inspect end
|
378
|
-
|
379
|
-
Trailblazer::Operation.introspect(Memo::Create::Authorized).must_equal %{[>policy,>create_memo,>validate_params,>save]}
|
380
|
-
end
|
381
|
-
|
382
|
-
it ":after inserts" do
|
383
|
-
Memo = Id::Memo
|
384
|
-
#:after-inspect
|
385
|
-
Trailblazer::Operation.introspect(Memo::Create::Logging)
|
386
|
-
#=> [>create_memo,>validate_params,>logger,>save]
|
387
|
-
#:after-inspect end
|
388
|
-
|
389
|
-
Trailblazer::Operation.introspect(Memo::Create::Logging).must_equal %{[>create_memo,>validate_params,>logger,>save]}
|
390
|
-
end
|
391
|
-
|
392
|
-
it ":replace inserts" do
|
393
|
-
Memo = Id::Memo
|
394
|
-
#:replace-inspect
|
395
|
-
Trailblazer::Operation.introspect(Memo::Update)
|
396
|
-
#=> [>update_memo,>validate_params,>save]
|
397
|
-
#:replace-inspect end
|
398
|
-
|
399
|
-
Trailblazer::Operation.introspect(Memo::Update).must_equal %{[>update_memo,>validate_params,>save]}
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
290
|
# @see https://github.com/trailblazer/trailblazer/issues/190#issuecomment-326992255
|
404
291
|
class WiringsDocRecoverTest < Minitest::Spec
|
405
292
|
Memo = WiringDocsTest::Memo
|
data/test/step_test.rb
CHANGED
@@ -40,7 +40,7 @@ class StepTest < Minitest::Spec
|
|
40
40
|
|
41
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] >" }
|
42
42
|
|
43
|
-
it { Trailblazer::
|
43
|
+
it { Trailblazer::Developer.railway(Create).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::30 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro]} }
|
44
44
|
|
45
45
|
#---
|
46
46
|
#- :before, :after, :replace, :delete, :override
|
@@ -61,7 +61,7 @@ class StepTest < Minitest::Spec
|
|
61
61
|
def d!(options, **); options["order"] << "d"; end
|
62
62
|
end
|
63
63
|
|
64
|
-
it { Trailblazer::
|
64
|
+
it { Trailblazer::Developer.railway(B).must_equal %{[>b!,>d!,>c!,>a!]} }
|
65
65
|
|
66
66
|
class C < B
|
67
67
|
step :e!, replace: :c!
|
@@ -69,7 +69,7 @@ class StepTest < Minitest::Spec
|
|
69
69
|
def e!(options, **); options["order"] << "e"; end
|
70
70
|
end
|
71
71
|
|
72
|
-
it { Trailblazer::
|
72
|
+
it { Trailblazer::Developer.railway(C).must_equal %{[>b!,>e!,>a!]} }
|
73
73
|
it { C.("order" => []).inspect("order").must_equal %{<Result:true [["b", "e", "a"]] >} }
|
74
74
|
|
75
75
|
#---
|
@@ -84,7 +84,7 @@ class StepTest < Minitest::Spec
|
|
84
84
|
def add!(options, **); options["a"] << :b; end
|
85
85
|
end
|
86
86
|
|
87
|
-
it { Trailblazer::
|
87
|
+
it { Trailblazer::Developer.railway(D).must_equal %{[>a!,>add!,>another_add!]} }
|
88
88
|
it { D.().inspect("a").must_equal %{<Result:true [[:b, :b]] >} }
|
89
89
|
|
90
90
|
class E < Trailblazer::Operation
|
@@ -97,7 +97,7 @@ class StepTest < Minitest::Spec
|
|
97
97
|
include T.def_steps(:a)
|
98
98
|
end
|
99
99
|
|
100
|
-
it { Trailblazer::
|
100
|
+
it { Trailblazer::Developer.railway(E).must_equal %{[>a,>b]} }
|
101
101
|
it { E.(seq: []).inspect(:seq).must_equal %{<Result:true [[:a, :b]] >} }
|
102
102
|
|
103
103
|
#- with proc
|
@@ -109,7 +109,7 @@ class StepTest < Minitest::Spec
|
|
109
109
|
def a!(options, **); options["a"] = []; end
|
110
110
|
end
|
111
111
|
|
112
|
-
it { Trailblazer::
|
112
|
+
it { Trailblazer::Developer.railway(F).must_equal %{[>a!,>add!!!]} }
|
113
113
|
it { F.().inspect("a").must_equal %{<Result:true [[:b]] >} }
|
114
114
|
|
115
115
|
#- with macro
|
@@ -126,7 +126,7 @@ class StepTest < Minitest::Spec
|
|
126
126
|
def a!(options, **); options["a"] = []; end
|
127
127
|
end
|
128
128
|
|
129
|
-
it { Trailblazer::
|
129
|
+
it { Trailblazer::Developer.railway(G).must_equal %{[>a!,>add]} }
|
130
130
|
it { G.().inspect("a").must_equal %{<Result:true [[:b]] >} }
|
131
131
|
|
132
132
|
# override: true in inherited class with macro
|
@@ -135,7 +135,7 @@ class StepTest < Minitest::Spec
|
|
135
135
|
step task: MyMacro, override: true, id: "add"
|
136
136
|
end
|
137
137
|
|
138
|
-
it { Trailblazer::
|
138
|
+
it { Trailblazer::Developer.railway(Go).must_equal %{[>a!,>add]} }
|
139
139
|
it { Go.().inspect("a").must_equal %{<Result:true [[:m]] >} }
|
140
140
|
|
141
141
|
#- with inheritance
|
@@ -154,7 +154,7 @@ class StepTest < Minitest::Spec
|
|
154
154
|
def _add!(options, **); options["a"] << :hh; end
|
155
155
|
end
|
156
156
|
|
157
|
-
it { Trailblazer::
|
157
|
+
it { Trailblazer::Developer.railway(Hh).must_equal %{[>a!,>_add!]} }
|
158
158
|
it { Hh.().inspect("a").must_equal %{<Result:true [[:hh]] >} }
|
159
159
|
|
160
160
|
#- inheritance unit test
|
@@ -190,20 +190,20 @@ class StepTest < Minitest::Spec
|
|
190
190
|
step({task: "MyMacro", id: "I win!"}, id: "No, I do!")
|
191
191
|
end
|
192
192
|
|
193
|
-
it { Trailblazer::
|
193
|
+
it { Trailblazer::Developer.railway(Index).must_equal %{[>my validate,>persist!,>I win!,>No, I do!]} }
|
194
194
|
|
195
195
|
#---
|
196
196
|
#- inheritance
|
197
197
|
class New < Create
|
198
198
|
end
|
199
199
|
|
200
|
-
it { Trailblazer::
|
200
|
+
it { Trailblazer::Developer.railway(New).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::30 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro]} }
|
201
201
|
|
202
202
|
class Update < Create
|
203
203
|
step :after_save!
|
204
204
|
end
|
205
205
|
|
206
|
-
it { Trailblazer::
|
206
|
+
it { Trailblazer::Developer.railway(Update).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::30 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro,>after_save!]} }
|
207
207
|
end
|
208
208
|
|
209
209
|
#---
|
@@ -226,7 +226,7 @@ class StepWithDeprecatedMacroTest < Minitest::Spec
|
|
226
226
|
step [AnotherOldMacro, id: :oldie]
|
227
227
|
end
|
228
228
|
|
229
|
-
it { skip; Trailblazer::
|
229
|
+
it { skip; Trailblazer::Developer.railway(Create).gsub(/0x.+?step_test.rb/, "").must_equal %{[>outdated,>oldie]} }
|
230
230
|
it { skip; Create.().inspect("x", "y").must_equal %{<Result:true [StepWithDeprecatedMacroTest::Create, StepWithDeprecatedMacroTest::Create] >} }
|
231
231
|
end
|
232
232
|
|
data/test/test_helper.rb
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "minitest"
|
25
25
|
spec.add_development_dependency "rake"
|
26
26
|
spec.add_development_dependency "rubocop"
|
27
|
+
spec.add_development_dependency "trailblazer-developer", ">= 0.0.3"
|
27
28
|
|
28
29
|
spec.required_ruby_version = ">= 2.1.0"
|
29
30
|
end
|
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.5.
|
4
|
+
version: 0.5.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: 2019-06-
|
11
|
+
date: 2019-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trailblazer-activity-dsl-linear
|
@@ -106,6 +106,20 @@ dependencies:
|
|
106
106
|
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: trailblazer-developer
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 0.0.3
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 0.0.3
|
109
123
|
description: Trailblazer's operation object.
|
110
124
|
email:
|
111
125
|
- apotonick@gmail.com
|
@@ -126,7 +140,6 @@ files:
|
|
126
140
|
- lib/trailblazer/operation/class_dependencies.rb
|
127
141
|
- lib/trailblazer/operation/container.rb
|
128
142
|
- lib/trailblazer/operation/deprecated_macro.rb
|
129
|
-
- lib/trailblazer/operation/inspect.rb
|
130
143
|
- lib/trailblazer/operation/public_call.rb
|
131
144
|
- lib/trailblazer/operation/railway.rb
|
132
145
|
- lib/trailblazer/operation/railway/macaroni.rb
|
@@ -148,7 +161,6 @@ files:
|
|
148
161
|
- test/gemfiles/Gemfile.ruby-2.0.lock
|
149
162
|
- test/gemfiles/Gemfile.ruby-2.3
|
150
163
|
- test/inheritance_test.rb
|
151
|
-
- test/inspect_test.rb
|
152
164
|
- test/introspect_test.rb
|
153
165
|
- test/operation_test.rb
|
154
166
|
- test/result_test.rb
|
@@ -202,7 +214,6 @@ test_files:
|
|
202
214
|
- test/gemfiles/Gemfile.ruby-2.0.lock
|
203
215
|
- test/gemfiles/Gemfile.ruby-2.3
|
204
216
|
- test/inheritance_test.rb
|
205
|
-
- test/inspect_test.rb
|
206
217
|
- test/introspect_test.rb
|
207
218
|
- test/operation_test.rb
|
208
219
|
- test/result_test.rb
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module Trailblazer
|
2
|
-
# Operation-specific circuit rendering. This is optimized for a linear railway circuit.
|
3
|
-
#
|
4
|
-
# @private
|
5
|
-
#
|
6
|
-
# NOTE: this is absolutely to be considered as prototyping and acts more like a test helper ATM as
|
7
|
-
# Inspect is not a mission-critical part.
|
8
|
-
class Operation
|
9
|
-
def self.introspect(*args)
|
10
|
-
Operation::Inspect.(*args)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module Operation::Inspect
|
15
|
-
module_function
|
16
|
-
|
17
|
-
def call(operation, options = {style: :line})
|
18
|
-
graph = Activity::Introspect::Graph(operation)
|
19
|
-
|
20
|
-
rows = graph.collect do |node, i|
|
21
|
-
next if node[:data][:stop_event] # DISCUSS: show this?
|
22
|
-
|
23
|
-
created_by = node[:data][:dsl_track] || :pass
|
24
|
-
|
25
|
-
[i, [created_by, node.id]]
|
26
|
-
end.compact
|
27
|
-
|
28
|
-
rows = rows[1..-1] # remove start
|
29
|
-
|
30
|
-
return inspect_line(rows) if options[:style] == :line
|
31
|
-
|
32
|
-
return inspect_rows(rows)
|
33
|
-
end
|
34
|
-
|
35
|
-
def inspect_func(step)
|
36
|
-
@inspect[step]
|
37
|
-
end
|
38
|
-
|
39
|
-
Operator = {fail: "<<", pass: ">>", step: ">"}
|
40
|
-
|
41
|
-
def inspect_line(names)
|
42
|
-
string = names.collect { |i, (end_of_edge, name)| "#{Operator[end_of_edge]}#{name}" }.join(",")
|
43
|
-
"[#{string}]"
|
44
|
-
end
|
45
|
-
|
46
|
-
def inspect_rows(names)
|
47
|
-
string = names.collect do |i, (end_of_edge, name)|
|
48
|
-
operator = Operator[end_of_edge]
|
49
|
-
|
50
|
-
op = "#{operator}#{name}"
|
51
|
-
padding = 38
|
52
|
-
|
53
|
-
proc = if operator == "<<"
|
54
|
-
sprintf("%- #{padding}s", op)
|
55
|
-
elsif [">", ">>", "&"].include?(operator.to_s)
|
56
|
-
sprintf("% #{padding}s", op)
|
57
|
-
else
|
58
|
-
pad = " " * ((padding - op.length) / 2)
|
59
|
-
"#{pad}#{op}#{pad}"
|
60
|
-
end
|
61
|
-
|
62
|
-
proc = proc.gsub(" ", "=")
|
63
|
-
|
64
|
-
sprintf("%2d %s", i, proc)
|
65
|
-
end.join("\n")
|
66
|
-
"\n#{string}"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/test/inspect_test.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class InspectTest < Minitest::Spec
|
4
|
-
# Test: #to_table
|
5
|
-
class Create < Trailblazer::Operation
|
6
|
-
step :decide!
|
7
|
-
pass :wasnt_ok!
|
8
|
-
pass :was_ok!
|
9
|
-
fail :return_true!
|
10
|
-
fail :return_false!
|
11
|
-
step :finalize!
|
12
|
-
end
|
13
|
-
|
14
|
-
#---
|
15
|
-
#- to_table
|
16
|
-
|
17
|
-
# pp Create.instance_variable_get(:@builder)
|
18
|
-
|
19
|
-
it do
|
20
|
-
Trailblazer::Operation.introspect(Create).must_equal %{[>decide!,>>wasnt_ok!,>>was_ok!,<<return_true!,<<return_false!,>finalize!]}
|
21
|
-
end
|
22
|
-
|
23
|
-
it do
|
24
|
-
Trailblazer::Operation::Inspect.call(Create, style: :rows).must_equal %{
|
25
|
-
1 ==============================>decide!
|
26
|
-
2 ===========================>>wasnt_ok!
|
27
|
-
3 =============================>>was_ok!
|
28
|
-
4 <<return_true!========================
|
29
|
-
5 <<return_false!=======================
|
30
|
-
6 ============================>finalize!}
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "step with only one output (happens with Nested)" do
|
34
|
-
class Present < Trailblazer::Operation
|
35
|
-
pass :ok!, outputs: {:success => Trailblazer::Activity::Output("signal", :success)}
|
36
|
-
end
|
37
|
-
|
38
|
-
it do
|
39
|
-
Trailblazer::Operation.introspect(Present).must_equal %{[>>ok!]}
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|