trailblazer-activity 0.11.2 → 0.12.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: c1af98988b1c0739296afe5fdcc67174fda97f1bcccfcc3e75adb8a06e3043e3
4
- data.tar.gz: 9f35640842440b53054d77e8f479010c715218db81f3be35d821bb0567442b95
3
+ metadata.gz: 26bd7483c314f6fda4c424cb35a9923b139194882639e0324c1f3877b267ed3d
4
+ data.tar.gz: 414ec2f07eb06318f7fb7fab7aadbef9bbf34cdbb76fad866936ede20ad55937
5
5
  SHA512:
6
- metadata.gz: b186be55e37823824fb426d108aa5a4b8df2f2972b7a43e46e021bf33330ec75c89f07b5a6d5d6f3377a57b5d93c59f8cf6f966caf257ca2b1c81d7dfba095c1
7
- data.tar.gz: 24b6b30334a3f610b95ebe781d9b1993db45e529bc5040174f16728ef05c35df135236296cc2daf67090fdee8dcaa84356341a3c86b4cdc14478e38bc22ae2cb
6
+ metadata.gz: a75f9f5d4ac9367540c058b749bf411a52f38e077e90df8d256c1bbfbf9aa697cc0b1b3c8be5b5d2f1fe35ef287976afa2f4ed3eb5b8abba5adf8c152810242b
7
+ data.tar.gz: 2bbad5b09c667363ce8f0f59105b48ffbba688ff78bb8b664b57fc89414742c2513f155b2a13a967da3614463808d4837243aa616684805d460b84f44b51efc2
@@ -0,0 +1,17 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
9
+ ruby: [2.5, 2.6, 2.7, '3.0', head, jruby, jruby-head]
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby }}
16
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
17
+ - run: bundle exec rake
data/CHANGES.md CHANGED
@@ -1,3 +1,24 @@
1
+ # 0.12.1
2
+
3
+ * Allow injecting `:wrap_static` into `TaskWrap.invoke`.
4
+
5
+ # 0.12.0
6
+
7
+ * Support for Ruby 3.0.
8
+
9
+ # 0.11.5
10
+
11
+ * Bug fix: `:output` filter from `TaskWrap::VariableMapping` wasn't returning the correct `flow_options`. If the wrapped task changed
12
+ its `flow_options`, the original one was still returned from the taskWrap run, not the updated one.
13
+
14
+ # 0.11.4
15
+
16
+ * Introduce the `config_wrap:` option in `Intermediate.call(intermediate, implementation, config_merge: {})` to allow injecting data into the activity's `:config` field.
17
+
18
+ # 0.11.3
19
+
20
+ * Allow `Testing.def_task` & `Testing.def_tasks` to return custom signals
21
+
1
22
  # 0.11.2
2
23
 
3
24
  * Updrading `trailblazer-context` version :drum:
data/Gemfile CHANGED
@@ -1,10 +1,5 @@
1
1
  source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in workflow.gemspec
4
2
  gemspec
5
3
 
6
- gem "benchmark-ips"
7
- gem "minitest-line"
8
-
9
- # gem "trailblazer-context", path: "../trailblazer-context"
10
4
  # gem "trailblazer-developer", path: "../trailblazer-developer"
5
+ # gem "trailblazer-context", github: "trailblazer/trailblazer-context", branch: "ruby-3"
@@ -68,6 +68,20 @@ module Trailblazer
68
68
  def self.Graph(*args)
69
69
  Graph.new(*args)
70
70
  end
71
+
72
+ def self.render_task(proc)
73
+ if proc.is_a?(Method)
74
+
75
+ receiver = proc.receiver
76
+ receiver = receiver.is_a?(Class) ? (receiver.name || "#<Class:0x>") : (receiver.name || "#<Module:0x>") #"#<Class:0x>"
77
+
78
+ return "#<Method: #{receiver}.#{proc.name}>"
79
+ elsif proc.is_a?(Symbol)
80
+ return proc.to_s
81
+ end
82
+
83
+ proc.inspect
84
+ end
71
85
  end # Introspect
72
86
  end
73
87
  end
@@ -12,14 +12,16 @@ class Trailblazer::Activity
12
12
  # Compiles a {Schema} instance from an {intermediate} structure and
13
13
  # the {implementation} object references.
14
14
  #
15
- # Intermediate structure, Implementation, calls extensions, passes {}config # TODO
16
- def self.call(intermediate, implementation)
17
- config_default = {wrap_static: Hash.new(TaskWrap.initial_wrap_static)}.freeze # DISCUSS: this really doesn't have to be here, but works for now and we want it in 99%.
15
+ # Intermediate structure, Implementation, calls extensions, passes {config} # TODO
16
+ def self.call(intermediate, implementation, config_merge: {})
17
+ config_default = {wrap_static: Hash.new(TaskWrap.initial_wrap_static)} # DISCUSS: this really doesn't have to be here, but works for now and we want it in 99%.
18
+ config = config_default.merge(config_merge)
19
+ config.freeze
18
20
 
19
21
  circuit = circuit(intermediate, implementation)
20
22
  nodes = node_attributes(intermediate, implementation)
21
23
  outputs = outputs(intermediate.stop_task_ids, nodes)
22
- config = config(implementation, config: config_default)
24
+ config = config(implementation, config: config)
23
25
  Schema.new(circuit, outputs, nodes, config)
24
26
  end
25
27
 
@@ -5,7 +5,7 @@ module Trailblazer
5
5
  # Output signal binary: true=>Right, false=>Left.
6
6
  # Passes through all subclasses of Direction.~~~~~~~~~~~~~~~~~
7
7
  def self.Binary(user_proc)
8
- Task.new(Trailblazer::Option::KW( user_proc ), user_proc)
8
+ Task.new(Trailblazer::Option(user_proc), user_proc)
9
9
  end
10
10
 
11
11
  # Translates the return value of the user step into a valid signal.
@@ -28,16 +28,16 @@ module Trailblazer
28
28
 
29
29
  def call( (ctx, flow_options), **circuit_options )
30
30
  # Execute the user step with TRB's kw args.
31
- result = @task.( ctx, **circuit_options ) # circuit_options contains :exec_context.
31
+ result = @task.(ctx, keyword_arguments: ctx.to_hash, **circuit_options) # circuit_options contains :exec_context.
32
32
 
33
33
  # Return an appropriate signal which direction to go next.
34
- signal = Activity::TaskBuilder.binary_signal_for( result, Activity::Right, Activity::Left )
34
+ signal = Activity::TaskBuilder.binary_signal_for(result, Activity::Right, Activity::Left)
35
35
 
36
- return signal, [ ctx, flow_options ]
36
+ return signal, [ctx, flow_options]
37
37
  end
38
38
 
39
- def inspect
40
- %{#<Trailblazer::Activity::TaskBuilder::Task user_proc=#{@user_proc}>}
39
+ def inspect # TODO: make me private!
40
+ %{#<Trailblazer::Activity::TaskBuilder::Task user_proc=#{Trailblazer::Activity::Introspect.render_task(@user_proc)}>}
41
41
  end
42
42
  alias_method :to_s, :inspect
43
43
  end
@@ -13,11 +13,14 @@ module Trailblazer
13
13
  module_function
14
14
 
15
15
  # Compute runtime arguments necessary to execute a taskWrap per task of the activity.
16
- def invoke(activity, args, wrap_runtime: {}, **circuit_options)
16
+ # This method is the top-level entry, called only once for the entire activity graph.
17
+ def invoke(activity, args, wrap_runtime: {}, wrap_static: initial_wrap_static, **circuit_options)
17
18
  circuit_options = circuit_options.merge(
18
19
  runner: TaskWrap::Runner,
19
20
  wrap_runtime: wrap_runtime,
20
- activity: {wrap_static: {activity => initial_wrap_static}, nodes: {}}, # for Runner. Ideally we'd have a list of all static_wraps here (even nested).
21
+ # This {:activity} structure is currently (?) only needed in {TaskWrap.wrap_static_for}, where we
22
+ # access {activity[:wrap_static]} to compile the effective taskWrap.
23
+ activity: {wrap_static: {activity => wrap_static}, nodes: {}}, # for Runner. Ideally we'd have a list of all static_wraps here (even nested).
21
24
  )
22
25
 
23
26
  # signal, (ctx, flow), circuit_options =
@@ -43,6 +46,9 @@ module Trailblazer
43
46
  @merge = merge
44
47
  end
45
48
 
49
+ # Compile-time:
50
+ # Gets called via the {Normalizer} and represents an {:extensions} item.
51
+ # Adds/alters the activity's {wrap_static}.
46
52
  def call(config:, task:, **)
47
53
  before_pipe = State::Config.get(config, :wrap_static, task.circuit_task)
48
54
 
@@ -6,9 +6,11 @@ class Trailblazer::Activity
6
6
  def self.call_task(wrap_ctx, original_args)
7
7
  task = wrap_ctx[:task]
8
8
 
9
+ original_arguments, original_circuit_options = original_args
10
+
9
11
  # Call the actual task we're wrapping here.
10
12
  # puts "~~~~wrap.call: #{task}"
11
- return_signal, return_args = task.(*original_args)
13
+ return_signal, return_args = task.(original_arguments, **original_circuit_options)
12
14
 
13
15
  # DISCUSS: do we want original_args here to be passed on, or the "effective" return_args which are different to original_args now?
14
16
  wrap_ctx = wrap_ctx.merge( return_signal: return_signal, return_args: return_args )
@@ -17,7 +17,7 @@ class Trailblazer::Activity
17
17
 
18
18
  # We save all original args passed into this Runner.call, because we want to return them later after this wrap
19
19
  # is finished.
20
- original_args = [ args, circuit_options ]
20
+ original_args = [args, circuit_options]
21
21
 
22
22
  # call the wrap {Activity} around the task.
23
23
  wrap_ctx, _ = task_wrap_pipeline.(wrap_ctx, original_args) # we omit circuit_options here on purpose, so the wrapping activity uses the default, plain Runner.
@@ -38,7 +38,7 @@ class Trailblazer::Activity
38
38
  end
39
39
 
40
40
  # {input.call()} is invoked in the circuit.
41
- # `original_args` are the actual args passed to the wrapped task: [ [options, ..], circuit_options ]
41
+ # `original_args` are the actual args passed to the wrapped task: [ [ctx, ..], circuit_options ]
42
42
  #
43
43
  def call(wrap_ctx, original_args)
44
44
  # let user compute new ctx for the wrapped task.
@@ -57,7 +57,7 @@ class Trailblazer::Activity
57
57
 
58
58
  # Invoke the @filter callable with the original circuit interface.
59
59
  def apply_filter((ctx, original_flow_options), original_circuit_options)
60
- @filter.([ctx, original_flow_options], original_circuit_options) # returns {new_ctx}.
60
+ @filter.([ctx, original_flow_options], **original_circuit_options) # returns {new_ctx}.
61
61
  end
62
62
  end
63
63
 
@@ -73,12 +73,14 @@ class Trailblazer::Activity
73
73
  def call(wrap_ctx, original_args)
74
74
  (original_ctx, original_flow_options), original_circuit_options = original_args
75
75
 
76
- returned_ctx, _ = wrap_ctx[:return_args] # this is the Context returned from {call}ing the wrapped user task.
77
- original_ctx = wrap_ctx[@id] # grab the original ctx from before which was set in the {:input} filter.
76
+ return_args = wrap_ctx[:return_args]
77
+
78
+ returned_ctx, returned_flow_options = wrap_ctx[:return_args] # this is the Context returned from {call}ing the wrapped user task.
79
+ original_ctx = wrap_ctx[@id] # grab the original ctx from before which was set in the {:input} filter.
78
80
  # let user compute the output.
79
- output_ctx = @filter.(returned_ctx, [original_ctx, original_flow_options], original_circuit_options)
81
+ output_ctx = @filter.(returned_ctx, [original_ctx, returned_flow_options], **original_circuit_options)
80
82
 
81
- wrap_ctx = wrap_ctx.merge( return_args: [output_ctx, original_flow_options] )
83
+ wrap_ctx = wrap_ctx.merge( return_args: [output_ctx, returned_flow_options] )
82
84
 
83
85
  # and then pass on the "new" context.
84
86
  return wrap_ctx, original_args
@@ -27,7 +27,9 @@ module Trailblazer
27
27
  Module.new do
28
28
  define_singleton_method(name) do | (ctx, flow_options), ** |
29
29
  ctx[:seq] << name
30
- return Activity::Right, [ctx, flow_options]
30
+ signal = ctx.key?(name) ? ctx[name] : Activity::Right
31
+
32
+ return signal, [ctx, flow_options]
31
33
  end
32
34
  end.method(name)
33
35
  end
@@ -38,9 +40,9 @@ module Trailblazer
38
40
  names.each do |name|
39
41
  define_method(name) do | (ctx, flow_options), ** |
40
42
  ctx[:seq] << name
41
- result = ctx.key?(name) ? ctx[name] : true
43
+ signal = ctx.key?(name) ? ctx[name] : Activity::Right
42
44
 
43
- return (result ? Activity::Right : Activity::Left), [ctx, flow_options]
45
+ return signal, [ctx, flow_options]
44
46
  end
45
47
  end
46
48
  end
@@ -60,10 +62,6 @@ module Trailblazer
60
62
  Success = Activity::End(:success)
61
63
  end
62
64
 
63
- def Cct(activity)
64
- Trailblazer::Developer::Render::Circuit.(activity)
65
- end
66
-
67
65
  # TODO: Remove this once all it's references are removed
68
66
  def implementing
69
67
  Implementing
@@ -141,9 +139,19 @@ module Trailblazer
141
139
 
142
140
  def assert_circuit(schema, circuit)
143
141
  cct = Cct(schema)
142
+
144
143
  cct = cct.gsub("#<Trailblazer::Activity::TaskBuilder::Task user_proc=", "<*")
145
144
  assert_equal %{#{circuit}}, cct
146
145
  end
146
+
147
+ def Cct(activity)
148
+ Trailblazer::Developer::Render::Circuit.(activity, inspect_task: Trailblazer::Activity::Testing.method(:render_task))
149
+ end
150
+ end
151
+
152
+ # Use this in {#Cct}.
153
+ def self.render_task(proc)
154
+ Activity::Introspect.render_task(proc)
147
155
  end
148
156
  end
149
157
  end
@@ -1,7 +1,7 @@
1
1
  module Trailblazer
2
2
  module Version
3
3
  module Activity
4
- VERSION = '0.11.2'.freeze
4
+ VERSION = '0.12.1'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -17,10 +17,11 @@ Gem::Specification.new do |spec|
17
17
  end
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "trailblazer-context", ">= 0.3.1", "< 0.4.0"
20
+ spec.add_dependency "trailblazer-context", ">= 0.4.0", "< 0.5.0"
21
21
 
22
22
  spec.add_development_dependency "bundler"
23
23
  spec.add_development_dependency "minitest", "~> 5.0"
24
+ spec.add_development_dependency "minitest-line"
24
25
  spec.add_development_dependency "rake"
25
26
  spec.add_development_dependency "trailblazer-developer", ">= 0.0.7"
26
27
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-activity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.12.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: 2020-08-20 00:00:00.000000000 Z
11
+ date: 2021-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer-context
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.1
19
+ version: 0.4.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 0.4.0
22
+ version: 0.5.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.3.1
29
+ version: 0.4.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 0.4.0
32
+ version: 0.5.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '5.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: minitest-line
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: rake
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -93,8 +107,8 @@ executables: []
93
107
  extensions: []
94
108
  extra_rdoc_files: []
95
109
  files:
110
+ - ".github/workflows/ci.yml"
96
111
  - ".gitignore"
97
- - ".travis.yml"
98
112
  - CHANGES.md
99
113
  - Gemfile
100
114
  - LICENSE
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- language: ruby
2
- before_install: gem install bundler
3
- cache: bundler
4
- rvm:
5
- - ruby-head
6
- - 2.7
7
- - 2.6
8
- - 2.5
9
- - 2.4
10
- jobs:
11
- allow_failures:
12
- - rvm: ruby-head