trailblazer-operation 0.4.1 → 0.6.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 +16 -12
  6. data/Gemfile +5 -3
  7. data/README.md +13 -2
  8. data/Rakefile +2 -2
  9. data/lib/trailblazer/operation.rb +52 -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/public_call.rb +23 -20
  14. data/lib/trailblazer/operation/railway.rb +2 -3
  15. data/lib/trailblazer/operation/railway/macaroni.rb +2 -2
  16. data/lib/trailblazer/operation/result.rb +14 -1
  17. data/lib/trailblazer/operation/trace.rb +9 -12
  18. data/lib/trailblazer/operation/version.rb +4 -2
  19. data/test/benchmark/skill_resolver_benchmark.rb +8 -9
  20. data/test/call_test.rb +57 -31
  21. data/test/callable_test.rb +147 -147
  22. data/test/class_dependencies_test.rb +6 -7
  23. data/test/docs/doormat_test.rb +13 -12
  24. data/test/docs/macaroni_test.rb +7 -9
  25. data/test/docs/operation_test.rb +69 -4
  26. data/test/docs/wiring_test.rb +85 -153
  27. data/test/dry_container_test.rb +4 -3
  28. data/test/fast_track_test.rb +24 -44
  29. data/test/inheritance_test.rb +13 -12
  30. data/test/introspect_test.rb +6 -6
  31. data/test/operation_test.rb +17 -25
  32. data/test/result_test.rb +4 -4
  33. data/test/ruby-2.0.0/operation_test.rb +9 -9
  34. data/test/ruby-2.0.0/step_test.rb +17 -16
  35. data/test/step_test.rb +55 -50
  36. data/test/test_helper.rb +7 -13
  37. data/test/trace_test.rb +27 -27
  38. data/test/wiring/defaults_test.rb +29 -33
  39. data/trailblazer-operation.gemspec +9 -7
  40. metadata +46 -27
  41. data/lib/trailblazer/operation/heritage.rb +0 -30
  42. data/lib/trailblazer/operation/inject.rb +0 -36
  43. data/lib/trailblazer/operation/inspect.rb +0 -79
  44. data/lib/trailblazer/operation/railway/fast_track.rb +0 -13
  45. data/lib/trailblazer/operation/railway/normalizer.rb +0 -58
  46. data/lib/trailblazer/operation/railway/task_builder.rb +0 -37
  47. data/test/inspect_test.rb +0 -43
  48. data/test/macro_test.rb +0 -60
  49. data/test/task_wrap_test.rb +0 -97
@@ -1,43 +0,0 @@
1
- require "test_helper"
2
-
3
-
4
- class InspectTest < Minitest::Spec
5
- # Test: #to_table
6
- class Create < Trailblazer::Operation
7
- step :decide!
8
- pass :wasnt_ok!
9
- pass :was_ok!
10
- fail :return_true!
11
- fail :return_false!
12
- step :finalize!
13
- end
14
-
15
- #---
16
- #- to_table
17
-
18
- # pp Create.instance_variable_get(:@builder)
19
-
20
- it do
21
- Trailblazer::Operation.introspect(Create).must_equal %{[>decide!,>>wasnt_ok!,>>was_ok!,<<return_true!,<<return_false!,>finalize!]}
22
- end
23
-
24
- it do
25
- Trailblazer::Operation::Inspect.call(Create, style: :rows).must_equal %{
26
- 0 ==============================>decide!
27
- 1 ===========================>>wasnt_ok!
28
- 2 =============================>>was_ok!
29
- 3 <<return_true!========================
30
- 4 <<return_false!=======================
31
- 5 ============================>finalize!}
32
- end
33
-
34
- describe "step with only one output (happens with Nested)" do
35
- class Present < Trailblazer::Operation
36
- pass :ok!, outputs: {:success => Trailblazer::Activity::Output("signal", :success)}
37
- end
38
-
39
- it do
40
- Trailblazer::Operation.introspect(Present).must_equal %{[>>ok!]}
41
- end
42
- end
43
- end
@@ -1,60 +0,0 @@
1
- require "test_helper"
2
- #- test
3
- # macro [ task, {name} ]
4
- # macro [ task, {name}, { alteration: } ] # see task_wrap_test.rb
5
- # macro [ task, {name}, { alteration: }, {task_outputs} ] # for eg. nested
6
-
7
- class MacroTest < Minitest::Spec
8
- MacroB = ->(( options, *args ), **) do
9
- options[:B] = true # we were here!
10
-
11
- [ options[:MacroB_return], [ options, *args ] ]
12
- end
13
-
14
- it "raises exception when macro doesn't provide :id" do
15
- assert_raises do
16
-
17
- Class.new(Trailblazer::Operation) do
18
- step( task: "<some macro>" )
19
- end
20
-
21
- end.message.must_equal %{No :id given for <some macro>}
22
- end
23
-
24
-
25
- class Create < Trailblazer::Operation
26
- step :a
27
- step task: MacroB, id: :MacroB, outputs: { :success => Activity::Output("Allgood", :success), :failure => Activity::Output("Fail!", :failure), :pass_fast => Activity::Output("Winning", :pass_fast) }
28
- step :c
29
-
30
- def a(options, **); options[:a] = true end
31
- def c(options, **); options[:c] = true end
32
- end
33
-
34
- # MacroB returns Allgood and is wired to the :success edge (right track).
35
- it { Create.( {}, MacroB_return: "Allgood" ).inspect(:a, :B, :c).must_equal %{<Result:true [true, true, true] >} }
36
- # MacroB returns Fail! and is wired to the :failure edge (left track).
37
- it { Create.( {}, MacroB_return: "Fail!" ).inspect(:a, :B, :c).must_equal %{<Result:false [true, true, nil] >} }
38
- # MacroB returns Winning and is wired to the :pass_fast edge.
39
- it { Create.( {}, MacroB_return: "Winning" ).inspect(:a, :B, :c).must_equal %{<Result:true [true, true, nil] >} }
40
-
41
- #- user overrides :plus_poles
42
- class Update < Trailblazer::Operation
43
- macro = { task: MacroB, id: :MacroB, outputs: { :success => Activity::Output("Allgood", :success), :failure => Activity::Output("Fail!", :failure), :pass_fast => Activity::Output("Winning", :pass_fast) } }
44
-
45
- step :a
46
- step macro, outputs: { :success => Activity::Output("Fail!", :success), :fail_fast => Activity::Output("Winning", :fail_fast), :failure => Activity::Output("Allgood", :failure) }
47
- # plus_poles: Test.plus_poles_for("Allgood" => :failure, "Fail!" => :success, "Winning" => :fail_fast)
48
- step :c
49
-
50
- def a(options, **); options[:a] = true end
51
- def c(options, **); options[:c] = true end
52
- end
53
-
54
- # MacroB returns Allgood and is wired to the :failure edge.
55
- it { Update.( {}, MacroB_return: "Allgood" ).inspect(:a, :B, :c).must_equal %{<Result:false [true, true, nil] >} }
56
- # MacroB returns Fail! and is wired to the :success edge.
57
- it { Update.( {}, MacroB_return: "Fail!" ).inspect(:a, :B, :c).must_equal %{<Result:true [true, true, true] >} }
58
- # MacroB returns Winning and is wired to the :fail_fast edge.
59
- it { Update.( {}, MacroB_return: "Winning" ).inspect(:a, :B, :c).must_equal %{<Result:false [true, true, nil] >} }
60
- end
@@ -1,97 +0,0 @@
1
- require "test_helper"
2
-
3
- require "trailblazer/operation/inject" # an optional feature.com.
4
-
5
- class TaskWrapTest < Minitest::Spec
6
- MyMacro = ->( (options, *args), *) do
7
- options["MyMacro.contract"] = options[:contract]
8
- [ Trailblazer::Activity::Right, [options, *args] ]
9
- end
10
-
11
- class Create < Trailblazer::Operation
12
- step :model!
13
- # step [ MyMacro, { name: "MyMacro" }, { dependencies: { "contract" => :external_maybe } }]
14
- step(
15
- task: MyMacro,
16
- id: "MyMacro",
17
-
18
- Trailblazer::Activity::DSL::Extension.new(
19
- Trailblazer::Activity::TaskWrap::Merge.new(
20
- Module.new do
21
- extend Trailblazer::Activity::Path::Plan()
22
-
23
- task Trailblazer::Operation::Wrap::Inject::ReverseMergeDefaults.new( contract: "MyDefaultContract" ),
24
- id: "inject.my_default",
25
- before: "task_wrap.call_task"
26
- end
27
- )
28
- ) => true
29
- )
30
-
31
- def model!(options, **)
32
- options["options.contract"] = options[:contract]
33
- true
34
- end
35
- end
36
-
37
- # it { Create.call("adsf", options={}, {}).inspect("MyMacro.contract", "options.contract").must_equal %{} }
38
-
39
- def inspect_hash(hash, *keys)
40
- Hash[ keys.collect { |key| [key, hash[key]] } ].inspect
41
- end
42
-
43
- #-
44
- # default gets set by Injection.
45
- it do
46
- result = Create.call( {} )
47
-
48
- inspect_hash(result, "options.contract", :contract, "MyMacro.contract").
49
- must_equal %{{"options.contract"=>nil, :contract=>"MyDefaultContract", "MyMacro.contract"=>"MyDefaultContract"}}
50
- end
51
-
52
- # injected from outside, Injection skips.
53
- it do
54
- result = Create.call( { :contract=>"MyExternalContract" } )
55
-
56
- inspect_hash(result, "options.contract", :contract, "MyMacro.contract").
57
- must_equal %{{"options.contract"=>"MyExternalContract", :contract=>"MyExternalContract", "MyMacro.contract"=>"MyExternalContract"}}
58
- end
59
-
60
- #- Nested task_wraps should not override the outer.
61
- AnotherMacro = ->( (options, *args), *) do
62
- options["AnotherMacro.another_contract"] = options[:another_contract]
63
- [ Trailblazer::Activity::Right, [options, *args] ]
64
- end
65
-
66
- class Update < Trailblazer::Operation
67
- step(
68
- task: ->( (options, *args), circuit_options ) {
69
- _d, *o = Create.call( [ options, *args ], circuit_options )
70
-
71
- [ Trailblazer::Activity::Right, *o ]
72
- },
73
- id: "Create"
74
- )
75
- step(
76
- task: AnotherMacro,
77
- id: "AnotherMacro",
78
- Trailblazer::Activity::DSL::Extension.new(
79
- Trailblazer::Activity::TaskWrap::Merge.new(
80
- Module.new do
81
- extend Trailblazer::Activity::Path::Plan()
82
-
83
- task Trailblazer::Operation::Wrap::Inject::ReverseMergeDefaults.new( another_contract: "AnotherDefaultContract" ), id: "inject.my_default",
84
- before: "task_wrap.call_task"
85
- end
86
- )
87
- ) => true,
88
- )
89
- end
90
-
91
- it do
92
- result = Update.call( {} )
93
-
94
- inspect_hash(result, "options.contract", :contract, "MyMacro.contract", "AnotherMacro.another_contract").
95
- must_equal %{{"options.contract"=>nil, :contract=>"MyDefaultContract", "MyMacro.contract"=>"MyDefaultContract", "AnotherMacro.another_contract"=>"AnotherDefaultContract"}}
96
- end
97
- end