trailblazer-operation 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9a083756bde5a10353633b2a91b40cb84fe5970a41d626e9ad1602359ed5bc7
4
- data.tar.gz: c3a07f086acbb070d540078f5abaf6046b06a63347eb9ac5b602bbfdc0f320a2
3
+ metadata.gz: 974fc7c8a10331b0e1e3f2b2303a2ae38fbc3accecae4ac691fc07de8b86094e
4
+ data.tar.gz: 899f31b5d0d5d554263444eb6b63dded2c368befb43a4902e43374a77eb7eb1f
5
5
  SHA512:
6
- metadata.gz: 3af0ad462ec4085e622431ddbd752739b5e44ac3eb8c61547933e3e1cc76a6a3cdb2eb34130f0bf4f248639d7bd46c64d7b08b3c2cef6724705507c9550c3599
7
- data.tar.gz: 19b63e1cb5778279b4d4dbc0cbe3deccaf935e60c724a2ccec35e99ea6018b586293edaa874a8f417b1a54a98d9c245d6a210c650fb95f9e9718ae10307aef96
6
+ metadata.gz: 77e1b44bbf35fb63a846dc13d1cfacaa92020a8091af074ae7674b1d9d82f2a777fa1f644758a019588290eaca1e3a3cb1d9898939816f5c275c101369505f8e
7
+ data.tar.gz: acb3c46ce31b0497d0c2f73036f827f3fe7efc33b3c8e5519790df71585fa6d6d6de5ef55e4143e0332a3abe3b249e3beb24cdb56d17b33ee979b5e3d6ff0eea
data/CHANGES.md CHANGED
@@ -14,6 +14,10 @@ lots of work on the DSL specific parts.
14
14
 
15
15
  params:, rest: ..
16
16
 
17
+ ## 0.3.1
18
+
19
+ * Moved `VariableMapping` to the `activity` gem.
20
+
17
21
  ## 0.3.0
18
22
 
19
23
  * Use `activity` 0.6.0.
data/Gemfile CHANGED
@@ -12,4 +12,4 @@ gem "benchmark-ips"
12
12
 
13
13
  # gem "trailblazer-developer", path: "../developer"
14
14
  # gem "trailblazer-developer", git: "https://github.com/trailblazer/trailblazer-developer"
15
- gem "trailblazer-activity", path: "../trailblazer-activity"
15
+ # gem "trailblazer-activity", path: "../trailblazer-activity"
@@ -9,7 +9,6 @@ require "trailblazer/activity"
9
9
  require "trailblazer/activity/dsl/magnetic"
10
10
 
11
11
 
12
- require "trailblazer/operation/variable_mapping"
13
12
  require "trailblazer/operation/callable"
14
13
 
15
14
  require "trailblazer/operation/heritage"
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Operation
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  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.6.0", "< 0.7.0"
20
+ spec.add_dependency "trailblazer-activity", ">= 0.6.1", "< 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.3.0
4
+ version: 0.3.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: 2018-05-03 00:00:00.000000000 Z
11
+ date: 2018-05-14 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.6.0
19
+ version: 0.6.1
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.6.0
29
+ version: 0.6.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.7.0
@@ -120,7 +120,6 @@ files:
120
120
  - lib/trailblazer/operation/railway/task_builder.rb
121
121
  - lib/trailblazer/operation/result.rb
122
122
  - lib/trailblazer/operation/trace.rb
123
- - lib/trailblazer/operation/variable_mapping.rb
124
123
  - lib/trailblazer/operation/version.rb
125
124
  - test/benchmark/skill_resolver_benchmark.rb
126
125
  - test/call_test.rb
@@ -149,7 +148,6 @@ files:
149
148
  - test/task_wrap_test.rb
150
149
  - test/test_helper.rb
151
150
  - test/trace_test.rb
152
- - test/variable_mapping_test.rb
153
151
  - test/wire_test.rb
154
152
  - test/wiring/defaults_test.rb
155
153
  - test/wiring/subprocess_test.rb
@@ -206,7 +204,6 @@ test_files:
206
204
  - test/task_wrap_test.rb
207
205
  - test/test_helper.rb
208
206
  - test/trace_test.rb
209
- - test/variable_mapping_test.rb
210
207
  - test/wire_test.rb
211
208
  - test/wiring/defaults_test.rb
212
209
  - test/wiring/subprocess_test.rb
@@ -1,91 +0,0 @@
1
- class Trailblazer::Activity < Module
2
- module TaskWrap
3
- # TaskWrap step to compute the incoming {Context} for the wrapped task.
4
- # This allows renaming, filtering, hiding, of the options passed into the wrapped task.
5
- #
6
- # Both Input and Output are typically to be added before and after task_wrap.call_task.
7
- #
8
- # @note Assumption: we always have :input _and_ :output, where :input produces a Context and :output decomposes it.
9
- class Input
10
- def initialize(filter)
11
- @filter = Trailblazer::Option(filter)
12
- end
13
-
14
- # `original_args` are the actual args passed to the wrapped task: [ [options, ..], circuit_options ]
15
- #
16
- def call( (wrap_ctx, original_args), **circuit_options )
17
- # let user compute new ctx for the wrapped task.
18
- input_ctx = apply_filter(*original_args) # FIXME: THIS SHOULD ALWAYS BE A _NEW_ Context.
19
- # TODO: make this unnecessary.
20
- # wrap user's hash in Context if it's not one, already (in case user used options.merge).
21
- # DISCUSS: should we restrict user to .merge and options.Context?
22
- input_ctx = Trailblazer.Context(input_ctx) if !input_ctx.instance_of?(Trailblazer::Context) || input_ctx==original_args[0][0]
23
-
24
- wrap_ctx = wrap_ctx.merge( vm_original_args: original_args )
25
-
26
- # decompose the original_args since we want to modify them.
27
- (original_ctx, original_flow_options), original_circuit_options = original_args
28
-
29
- # instead of the original Context, pass on the filtered `input_ctx` in the wrap.
30
- return Trailblazer::Activity::Right, [ wrap_ctx, [[input_ctx, original_flow_options], original_circuit_options] ]
31
- end
32
-
33
- private
34
-
35
- def apply_filter((original_ctx, original_flow_options), original_circuit_options)
36
- @filter.( original_ctx, **original_circuit_options )
37
- end
38
- end
39
-
40
- # TaskWrap step to compute the outgoing {Context} from the wrapped task.
41
- # This allows renaming, filtering, hiding, of the options returned from the wrapped task.
42
- class Output
43
- def initialize(filter, strategy=CopyMutableToOriginal)
44
- @filter = Trailblazer::Option(filter)
45
- @strategy = strategy
46
- end
47
-
48
- # Runs the user filter and replaces the ctx in `wrap_ctx[:return_args]` with the filtered one.
49
- def call( (wrap_ctx, original_args), **circuit_options )
50
- (original_ctx, original_flow_options), original_circuit_options = original_args
51
-
52
- returned_ctx, _ = wrap_ctx[:return_args] # this is the Context returned from `call`ing the task.
53
-
54
- # returned_ctx is the Context object from the nested operation. In <=2.1, this might be a completely different one
55
- # than "ours" we created in Input. We now need to compile a list of all added values. This is time-intensive and should
56
- # be optimized by removing as many Context creations as possible (e.g. the one adding self[] stuff in Operation.__call__).
57
- _, mutable_data = returned_ctx.decompose # DISCUSS: this is a weak assumption. What if the task returns a deeply nested Context?
58
-
59
- # let user compute the output.
60
- output = apply_filter(mutable_data, original_flow_options, original_circuit_options)
61
-
62
- original_ctx = wrap_ctx[:vm_original_args][0][0]
63
-
64
- new_ctx = @strategy.( original_ctx, output ) # here, we compute the "new" options {Context}.
65
-
66
- wrap_ctx = wrap_ctx.merge( return_args: [new_ctx, original_flow_options] )
67
-
68
- # and then pass on the "new" context.
69
- return Trailblazer::Activity::Right, [ wrap_ctx, original_args ]
70
- end
71
-
72
- private
73
-
74
- # @note API not stable
75
- def apply_filter(mutable_data, original_flow_options, original_circuit_options)
76
- @filter.(mutable_data, **original_circuit_options)
77
- end
78
-
79
- # "merge" Strategy
80
- module CopyMutableToOriginal
81
- # @param original Context
82
- # @param options Context The object returned from a (nested) {Activity}.
83
- def self.call(original, mutable)
84
- mutable.each { |k,v| original[k] = v }
85
-
86
- original
87
- end
88
- end
89
- end
90
- end # Wrap
91
- end
@@ -1,70 +0,0 @@
1
- require "test_helper"
2
-
3
- # Test input- and output filter for specific tasks.
4
- # These are task wrap steps added before and after the task.
5
- class VariableMappingTest < Minitest::Spec
6
- # first task
7
- Model = ->((options, flow), **o) do
8
- options["a"] = options["a"] * 2 # rename to model.a
9
- options["model.nonsense"] = true # filter me out
10
-
11
- [Activity::Right, [options, flow]]
12
- end
13
-
14
- # second task
15
- Uuid = ->((options, flow), **o) do
16
- options["a"] = options["a"] + options["model.a"] # rename to uuid.a
17
- options["uuid.nonsense"] = false # filter me out
18
-
19
- [Activity::Right, [options, flow]]
20
- end
21
-
22
- let (:activity) do
23
- Module.new do
24
- extend Activity::Path()
25
-
26
- task task: Model
27
- task task: Uuid
28
- end
29
- end
30
-
31
- describe "input/output" do
32
-
33
- it do
34
- model_input = ->(options) { { "a" => options["a"]+1 } }
35
- model_output = ->(options) { { "model.a" => options["a"] } }
36
- uuid_input = ->(options) { { "a" => options["a"]*3, "model.a" => options["model.a"] } }
37
- uuid_output = ->(options) { { "uuid.a" => options["a"] } }
38
-
39
- runtime = {}
40
-
41
- # add filters around Model.
42
- runtime[ Model ] = Module.new do
43
- extend Activity::Path::Plan()
44
-
45
- task Activity::TaskWrap::Input.new( model_input ), id: "task_wrap.input", before: "task_wrap.call_task"
46
- task Activity::TaskWrap::Output.new( model_output ), id: "task_wrap.output", before: "End.success", group: :end
47
- end
48
-
49
- # add filters around Uuid.
50
- runtime[ Uuid ] = Module.new do
51
- extend Activity::Path::Plan()
52
-
53
- task Activity::TaskWrap::Input.new( uuid_input ), id: "task_wrap.input", before: "task_wrap.call_task"
54
- task Activity::TaskWrap::Output.new( uuid_output ), id: "task_wrap.output", before: "End.success", group: :end
55
- end
56
-
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 })
68
- end
69
- end
70
- end