trailblazer-operation 0.2.5 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d9e1d5b133331e52c4daa858d788d4a040be8d732b9038e6a8294e1ae868ba7
4
- data.tar.gz: 07b4cfe11ffb833ad8b1681207eabaad2b4937fe0422eb920799fb3c238f2e39
3
+ metadata.gz: a9a083756bde5a10353633b2a91b40cb84fe5970a41d626e9ad1602359ed5bc7
4
+ data.tar.gz: c3a07f086acbb070d540078f5abaf6046b06a63347eb9ac5b602bbfdc0f320a2
5
5
  SHA512:
6
- metadata.gz: d6e77202fc2c6497d6bc5d9819e6334f8ff5165f6d65eda01ef6efb5e4146e34fc9e7f1205266a652c826ddae525d1f8cc811203cd6be129338611096fe821a9
7
- data.tar.gz: fbb8bdb761168cf7d361bb04014026aae6ecee8aa481294aca3e05732f769cb78a747176d59099d9468802e37a292a4c6a964d401154b810d98ee57717dda1b2
6
+ metadata.gz: 3af0ad462ec4085e622431ddbd752739b5e44ac3eb8c61547933e3e1cc76a6a3cdb2eb34130f0bf4f248639d7bd46c64d7b08b3c2cef6724705507c9550c3599
7
+ data.tar.gz: 19b63e1cb5778279b4d4dbc0cbe3deccaf935e60c724a2ccec35e99ea6018b586293edaa874a8f417b1a54a98d9c245d6a210c650fb95f9e9718ae10307aef96
data/CHANGES.md CHANGED
@@ -14,6 +14,17 @@ lots of work on the DSL specific parts.
14
14
 
15
15
  params:, rest: ..
16
16
 
17
+ ## 0.3.0
18
+
19
+ * Use `activity` 0.6.0.
20
+ * Remove `Operation::__call__` in favor of one `call` that dispatches to either
21
+ * `call_with_public_interface` this implements the complicated public `Operation.()` semantic and will be faded out with the rise of workflow engines.
22
+ * `call_with_circuit_interface` is the circuit-compatible version that will be invoked on nested operations.
23
+
24
+ This might seem a bit "magical" but simplifies the interface a lot. In better languages, you could use method overloading for that, in Ruby, we have to
25
+ do that ourselves. This decision was made with the deprecation of `Operation.()` in mind. In the future, operations will mostly be invoked from
26
+ workflow engines and not directly, where the engine takes care of applying the correct interface.
27
+
17
28
  ## 0.2.5
18
29
 
19
30
  * Minor fixes for activity 0.5.2.
data/Gemfile CHANGED
@@ -10,14 +10,6 @@ gem "dry-auto_inject"
10
10
  gem "minitest-line"
11
11
  gem "benchmark-ips"
12
12
 
13
- # gem "trailblazer-circuit", git: "https://github.com/trailblazer/trailblazer-circuit"
14
- # gem "trailblazer-activity", path: "../trailblazer-activity"
15
13
  # gem "trailblazer-developer", path: "../developer"
16
14
  # gem "trailblazer-developer", git: "https://github.com/trailblazer/trailblazer-developer"
17
- # gem "representable", path: "../representable"
18
-
19
- # gem "raise", path: "../raise"
20
-
21
- # gem "declarative", path: "../declarative"
22
-
23
- # gem "trailblazer-activity", path: "../trailblazer-circuit"
15
+ gem "trailblazer-activity", path: "../trailblazer-activity"
@@ -14,7 +14,7 @@ require "trailblazer/operation/callable"
14
14
 
15
15
  require "trailblazer/operation/heritage"
16
16
  require "trailblazer/operation/public_call" # TODO: Remove in 3.0.
17
- require "trailblazer/operation/skill"
17
+ require "trailblazer/operation/class_dependencies"
18
18
  require "trailblazer/operation/deprecated_macro" # TODO: remove in 2.2.
19
19
  require "trailblazer/operation/result"
20
20
  require "trailblazer/operation/railway"
@@ -57,17 +57,6 @@ module Trailblazer
57
57
  extend Activity::Interface
58
58
 
59
59
  module Process
60
- # Call the actual {Process} with the options prepared in PublicCall.
61
- #
62
- # @private
63
- def __call__(args, argumenter: [], **circuit_options)
64
- @activity.( args, circuit_options.merge(
65
- exec_context: new,
66
- argumenter: argumenter + [ Activity::TaskWrap.method(:arguments_for_call) ], # FIXME: should we move this outside?
67
- )
68
- )
69
- end
70
-
71
60
  def to_h
72
61
  @activity.to_h.merge( activity: @activity )
73
62
  end
@@ -80,7 +69,7 @@ module Trailblazer
80
69
  class << self
81
70
  extend Forwardable # TODO: test those helpers
82
71
  def_delegators :@activity, :Path, :Output, :End, :Track
83
- def_delegators :@activity, :outputs, :debug
72
+ def_delegators :@activity, :outputs
84
73
 
85
74
  def step(task, options={}, &block); add_task!(:step, task, options, &block) end
86
75
  def pass(task, options={}, &block); add_task!(:pass, task, options, &block) end
@@ -16,7 +16,7 @@ class Trailblazer::Operation
16
16
  # The use of this module is not encouraged and it is only here for backward-compatibility.
17
17
  # Instead, please pass dependencies via containers, locals, or macros into the respective steps.
18
18
  module ClassDependencies
19
- def __call__( (ctx, flow_options), **circuit_options )
19
+ def call_with_circuit_interface( (ctx, flow_options), **circuit_options )
20
20
  @skills.each { |name, value| ctx[name] ||= value } # this resembles the behavior in 2.0. we didn't say we liked it.
21
21
 
22
22
  super
@@ -1,5 +1,5 @@
1
- class Trailblazer::Operation
2
- module PublicCall
1
+ module Trailblazer
2
+ module Operation::PublicCall
3
3
  # This is the outer-most public `call` method that gets invoked when calling `Create.()`.
4
4
  # The signature of this is `params, options, *containers`. This was a mistake, as the
5
5
  # first argument could've been part of `options` hash in the first place.
@@ -14,13 +14,29 @@ class Trailblazer::Operation
14
14
  # @note Do not override this method as it will be removed in future versions. Also, you will break tracing.
15
15
  # @return Operation::Railway::Result binary result object
16
16
  def call(*args)
17
- ctx = PublicCall.options_for_public_call(*args)
17
+ return call_with_circuit_interface(*args) if args.any? && args[0].is_a?(Array) # This is kind of a hack that could be well hidden if Ruby had method overloading. Goal is to simplify the call/__call__ thing as we're fading out Operation::call anyway.
18
+ call_with_public_interface(*args)
19
+ end
20
+
21
+ def call_with_public_interface(*args)
22
+ ctx = Operation::PublicCall.options_for_public_call(*args)
18
23
 
19
24
  # call the activity.
20
- last_signal, (options, flow_options) = __call__( [ctx, {}] ) # Railway::call # DISCUSS: this could be ::call_with_context.
25
+ # This will result in invoking {::call_with_circuit_interface}.
26
+ last_signal, (options, flow_options) = Activity::TaskWrap.invoke(self, [ctx, {}], {})
21
27
 
22
28
  # Result is successful if the activity ended with an End event derived from Railway::End::Success.
23
- Railway::Result(last_signal, options, flow_options)
29
+ Operation::Railway::Result(last_signal, options, flow_options)
30
+ end
31
+
32
+ # This interface is used for all nested OPs (and the outer-most, too).
33
+ def call_with_circuit_interface(args, circuit_options)
34
+ @activity.(
35
+ args,
36
+ circuit_options.merge(
37
+ exec_context: new
38
+ )
39
+ )
24
40
  end
25
41
 
26
42
  # Compile a Context object to be passed into the Activity::call.
@@ -6,18 +6,11 @@ module Trailblazer
6
6
  ctx = PublicCall.options_for_public_call(*args) # redundant with PublicCall::call.
7
7
 
8
8
  # Prepare the tracing-specific arguments. This is only run once for the entire circuit!
9
- operation, (options, flow_options), circuit_options = Trailblazer::Activity::Trace.arguments_for_call( operation, [ctx, {}], {} )
9
+ operation, *args = Trailblazer::Activity::Trace.arguments_for_call( operation, [ctx, {}], {} )
10
10
 
11
- circuit_options = circuit_options.merge({ argumenter: [ Trailblazer::Activity::Introspect.method(:arguments_for_call) ] }) # this is called for every Activity.
11
+ last_signal, (ctx, flow_options) = Activity::TaskWrap.invoke(operation, *args )
12
12
 
13
-
14
- last_signal, (options, flow_options) =
15
- operation.__call__( # FIXME: this is the only problem.
16
- [options, flow_options],
17
- circuit_options
18
- )
19
-
20
- result = Railway::Result(last_signal, options) # redundant with PublicCall::call.
13
+ result = Railway::Result(last_signal, ctx) # redundant with PublicCall::call.
21
14
 
22
15
  Result.new(result, flow_options[:stack].to_a)
23
16
  end
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Operation
3
- VERSION = "0.2.5"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -96,7 +96,7 @@ class CallableHelper < Minitest::Spec
96
96
  Module.new do
97
97
  extend Activity::Path()
98
98
 
99
- task task: Operation::Callable( _blog, task: Blog::Next ), _blog.outputs[:success] => Track(:success)
99
+ task task: Operation::Callable( _blog, start_task: Blog::Next ), _blog.outputs[:success] => Track(:success)
100
100
  task task: User::Relax
101
101
  end
102
102
  end
@@ -78,7 +78,7 @@ class FailFastBangTest < Minitest::Spec
78
78
  end
79
79
 
80
80
  # without proper configuration, emitting a FastTrack signal is illegal.
81
- it { assert_raises(Trailblazer::Circuit::IllegalOutputSignalError) { Create.().inspect("x", "y", "a").must_equal %{<Result:false [true, nil, nil] >} } }
81
+ it { assert_raises(Trailblazer::Circuit::IllegalSignalError) { Create.().inspect("x", "y", "a").must_equal %{<Result:false [true, nil, nil] >} } }
82
82
 
83
83
  class Update < Trailblazer::Operation
84
84
  step ->(options, *) { options["x"] = true; Railway.fail_fast! }, fast_track: true
@@ -126,7 +126,7 @@ class NestedFastTrackTest < Minitest::Spec
126
126
  describe "Nested, fast_track: true and all its outputs given" do
127
127
  let(:update) do
128
128
  Class.new(Trailblazer::Operation) do
129
- step task: Trailblazer::Operation::Callable( Edit, call: :__call__ ), id: "Callable/",
129
+ step task: Trailblazer::Operation::Callable( Edit, call: :call_with_circuit_interface ), id: "Callable/",
130
130
  outputs: Edit.outputs ,
131
131
  fast_track: true
132
132
  step :b
@@ -151,7 +151,7 @@ class NestedFastTrackTest < Minitest::Spec
151
151
  Class.new(Trailblazer::Operation) do
152
152
  include Steps
153
153
 
154
- step task: Trailblazer::Operation::Callable( Edit, call: :__call__ ), id: "Callable/",
154
+ step task: Trailblazer::Operation::Callable( Edit, call: :call_with_circuit_interface ), id: "Callable/",
155
155
  outputs: Edit.outputs # all outputs given means it "works"
156
156
  step :b
157
157
  fail :f
@@ -173,7 +173,7 @@ class NestedFastTrackTest < Minitest::Spec
173
173
  Class.new(Trailblazer::Operation) do
174
174
  include Steps
175
175
 
176
- step({task: Trailblazer::Operation::Callable( Edit, call: :__call__ ), id: "Callable/",
176
+ step({task: Trailblazer::Operation::Callable( Edit, call: :call_with_circuit_interface ), id: "Callable/",
177
177
  outputs: Edit.outputs },
178
178
  {Output(:pass_fast) => Track(:success), Output(:fail_fast) => Track(:failure)} )# manually rewire the fast-track outputs to "conventional" railway ends.
179
179
 
@@ -15,7 +15,7 @@ class TaskWrapTest < Minitest::Spec
15
15
  task: MyMacro,
16
16
  id: "MyMacro",
17
17
 
18
- extension: [
18
+ Trailblazer::Activity::DSL::Extension.new(
19
19
  Trailblazer::Activity::TaskWrap::Merge.new(
20
20
  Module.new do
21
21
  extend Trailblazer::Activity::Path::Plan()
@@ -25,7 +25,7 @@ class TaskWrapTest < Minitest::Spec
25
25
  before: "task_wrap.call_task"
26
26
  end
27
27
  )
28
- ]
28
+ ) => true
29
29
  )
30
30
 
31
31
  def model!(options, **)
@@ -34,7 +34,7 @@ class TaskWrapTest < Minitest::Spec
34
34
  end
35
35
  end
36
36
 
37
- # it { Create.__call__("adsf", options={}, {}).inspect("MyMacro.contract", "options.contract").must_equal %{} }
37
+ # it { Create.call("adsf", options={}, {}).inspect("MyMacro.contract", "options.contract").must_equal %{} }
38
38
 
39
39
  def inspect_hash(hash, *keys)
40
40
  Hash[ keys.collect { |key| [key, hash[key]] } ].inspect
@@ -43,17 +43,17 @@ class TaskWrapTest < Minitest::Spec
43
43
  #-
44
44
  # default gets set by Injection.
45
45
  it do
46
- direction, (options, _) = Create.__call__( [{}, {}] )
46
+ result = Create.call( {} )
47
47
 
48
- inspect_hash(options, "options.contract", :contract, "MyMacro.contract").
48
+ inspect_hash(result, "options.contract", :contract, "MyMacro.contract").
49
49
  must_equal %{{"options.contract"=>nil, :contract=>"MyDefaultContract", "MyMacro.contract"=>"MyDefaultContract"}}
50
50
  end
51
51
 
52
52
  # injected from outside, Injection skips.
53
53
  it do
54
- direction, (options, _) = Create.__call__( [ { :contract=>"MyExternalContract" }, {} ] )
54
+ result = Create.call( { :contract=>"MyExternalContract" } )
55
55
 
56
- inspect_hash(options, "options.contract", :contract, "MyMacro.contract").
56
+ inspect_hash(result, "options.contract", :contract, "MyMacro.contract").
57
57
  must_equal %{{"options.contract"=>"MyExternalContract", :contract=>"MyExternalContract", "MyMacro.contract"=>"MyExternalContract"}}
58
58
  end
59
59
 
@@ -65,8 +65,8 @@ class TaskWrapTest < Minitest::Spec
65
65
 
66
66
  class Update < Trailblazer::Operation
67
67
  step(
68
- task: ->( (options, *args), * ) {
69
- _d, *o = Create.__call__( [ options, *args ] )
68
+ task: ->( (options, *args), circuit_options ) {
69
+ _d, *o = Create.call( [ options, *args ], circuit_options )
70
70
 
71
71
  [ Trailblazer::Activity::Right, *o ]
72
72
  },
@@ -75,7 +75,7 @@ class TaskWrapTest < Minitest::Spec
75
75
  step(
76
76
  task: AnotherMacro,
77
77
  id: "AnotherMacro",
78
- extension: [
78
+ Trailblazer::Activity::DSL::Extension.new(
79
79
  Trailblazer::Activity::TaskWrap::Merge.new(
80
80
  Module.new do
81
81
  extend Trailblazer::Activity::Path::Plan()
@@ -84,14 +84,14 @@ class TaskWrapTest < Minitest::Spec
84
84
  before: "task_wrap.call_task"
85
85
  end
86
86
  )
87
- ]
87
+ ) => true,
88
88
  )
89
89
  end
90
90
 
91
91
  it do
92
- direction, (options, _) = Update.__call__( [ {}, {} ] )
92
+ result = Update.call( {} )
93
93
 
94
- inspect_hash(options, "options.contract", :contract, "MyMacro.contract", "AnotherMacro.another_contract").
94
+ inspect_hash(result, "options.contract", :contract, "MyMacro.contract", "AnotherMacro.another_contract").
95
95
  must_equal %{{"options.contract"=>nil, :contract=>"MyDefaultContract", "MyMacro.contract"=>"MyDefaultContract", "AnotherMacro.another_contract"=>"AnotherDefaultContract"}}
96
96
  end
97
97
  end
@@ -4,10 +4,6 @@ class TraceTest < Minitest::Spec
4
4
  class B < Trailblazer::Operation
5
5
  step ->(options, **) { options[:b] = true }, id: "B.task.b"
6
6
  step ->(options, **) { options[:e] = true }, id: "B.task.e"
7
-
8
- def self.call( (options, flow_options), **circuit_options )
9
- __call__( [Trailblazer::Context(options), flow_options], circuit_options )
10
- end
11
7
  end
12
8
 
13
9
  class Create < Trailblazer::Operation
@@ -15,10 +11,6 @@ class TraceTest < Minitest::Spec
15
11
  step( {task: B, id: "MyNested"}, B.outputs[:success] => Track(:success) )
16
12
  step ->(options, **) { options[:c] = true }, id: "Create.task.c"
17
13
  step ->(options, params:, **) { params.any? }, id: "Create.task.params"
18
-
19
- def self.call( (options, flow_options), **circuit_options )
20
- __call__( [Trailblazer::Context(options), flow_options], circuit_options ) # FIXME.
21
- end
22
14
  end
23
15
  # raise Create["__task_wraps__"].inspect
24
16
 
@@ -35,29 +27,31 @@ class TraceTest < Minitest::Spec
35
27
 
36
28
  puts output = Trailblazer::Activity::Trace::Present.tree(stack)
37
29
 
38
- output.gsub(/0x\w+/, "").gsub(/@.+_test/, "").must_equal %{|-- #<Trailblazer::Activity::Start semantic=:default>
39
- |-- Create.task.a
40
- |-- MyNested
41
- | |-- #<Trailblazer::Activity::Start semantic=:default>
42
- | |-- B.task.b
43
- | |-- B.task.e
44
- | `-- #<Trailblazer::Operation::Railway::End::Success semantic=:success>
45
- |-- Create.task.c
46
- |-- Create.task.params
47
- `-- #<Trailblazer::Operation::Railway::End::Failure semantic=:failure>}
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}
48
41
  end
49
42
 
50
43
  it "Operation::trace" do
51
44
  result = Create.trace({ params: { x: 1 }, a_return: true })
52
- result.wtf.gsub(/0x\w+/, "").gsub(/@.+_test/, "").must_equal %{|-- #<Trailblazer::Activity::Start semantic=:default>
53
- |-- Create.task.a
54
- |-- MyNested
55
- | |-- #<Trailblazer::Activity::Start semantic=:default>
56
- | |-- B.task.b
57
- | |-- B.task.e
58
- | `-- #<Trailblazer::Operation::Railway::End::Success semantic=:success>
59
- |-- Create.task.c
60
- |-- Create.task.params
61
- `-- #<Trailblazer::Operation::Railway::End::Success semantic=:success>}
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}
62
56
  end
63
57
  end
@@ -54,20 +54,17 @@ class VariableMappingTest < Minitest::Spec
54
54
  task Activity::TaskWrap::Output.new( uuid_output ), id: "task_wrap.output", before: "End.success", group: :end
55
55
  end
56
56
 
57
- signal, (options, flow_options) = activity.(
58
- [
59
- options = { "a" => 1 },
60
- {},
61
- ],
62
-
63
- wrap_runtime: runtime, # dynamic additions from the outside (e.g. tracing), also per task.
64
- runner: Activity::TaskWrap::Runner,
65
- argumenters: [ Activity::TaskWrap::NonStatic.method(:arguments_for_call) ],
66
- wrap_static: Hash.new( Activity::TaskWrap.initial_activity ),
67
- )
68
-
69
- signal.must_equal activity.outputs[:success].signal
70
- options.must_equal({"a"=>1, "model.a"=>4, "uuid.a" => 7 })
57
+ signal, (options, flow_options) = Activity::TaskWrap.invoke(activity,
58
+ [
59
+ options = { "a" => 1 },
60
+ {},
61
+ ],
62
+
63
+ wrap_runtime: runtime, # dynamic additions from the outside (e.g. tracing), also per task.
64
+ )
65
+
66
+ signal.must_equal activity.outputs[:success].signal
67
+ options.must_equal({"a"=>1, "model.a"=>4, "uuid.a" => 7 })
71
68
  end
72
69
  end
73
70
  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", ">= 0.5.2", "< 0.7.0"
20
+ spec.add_dependency "trailblazer-activity", ">= 0.6.0", "< 0.7.0"
21
21
  spec.add_dependency "trailblazer-context", ">= 0.1.1", "< 0.3.0"
22
22
 
23
23
  spec.add_development_dependency "bundler"
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.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-23 00:00:00.000000000 Z
11
+ date: 2018-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer-activity
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.2
19
+ version: 0.6.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.7.0
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.5.2
29
+ version: 0.6.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.7.0
@@ -107,6 +107,7 @@ files:
107
107
  - Rakefile
108
108
  - lib/trailblazer/operation.rb
109
109
  - lib/trailblazer/operation/callable.rb
110
+ - lib/trailblazer/operation/class_dependencies.rb
110
111
  - lib/trailblazer/operation/deprecated_macro.rb
111
112
  - lib/trailblazer/operation/heritage.rb
112
113
  - lib/trailblazer/operation/inject.rb
@@ -118,7 +119,6 @@ files:
118
119
  - lib/trailblazer/operation/railway/normalizer.rb
119
120
  - lib/trailblazer/operation/railway/task_builder.rb
120
121
  - lib/trailblazer/operation/result.rb
121
- - lib/trailblazer/operation/skill.rb
122
122
  - lib/trailblazer/operation/trace.rb
123
123
  - lib/trailblazer/operation/variable_mapping.rb
124
124
  - lib/trailblazer/operation/version.rb