trailblazer-operation 0.7.3 → 0.8.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2bed59ccc4a6af470ef0413dfd4c5132c138a2ed68e1e7ed390ea7637c8db4e
4
- data.tar.gz: '074982e69ce025d63cc256964b8c334ad6405f792357201778beea2694668f93'
3
+ metadata.gz: 5bbb0fa15c5191698a061f5bb8b93a5eace67064ea2fbcbf0e470fac0cd753ae
4
+ data.tar.gz: 8e2936aa292319ae85ff536b52a7804d458490789cf899993bcad735f127e737
5
5
  SHA512:
6
- metadata.gz: 9b74fd06391e9035c5a82ff85b281e4b87445f18b0c238d5f939dfdb80e4541cd484743523a474371dfa2dd803068c6bb415732a40bea25dfa67fd777134dc3c
7
- data.tar.gz: 79eb31f4211e4a6521c3c06f879df49bf32b57f5b020b0f3a4273efb8c12fc047812f9a75f0987034c78fc6952945d5e4e24d08ac820b6c31222657490d4ea68
6
+ metadata.gz: aa828e7e9ca916cd4d312925407e7a723831a13d08f4f8bc4eddae6b0f0867bd8f7c23929e5f385fde91a7dad9ed706b96cbb54010adbec607f7c315eb928725
7
+ data.tar.gz: ec3ecc37e71550152747ce598e4a1e44ac17beac712dbde45463a08e357673c3835539c6122e5047a6381b9440be32829f1a9f986d894715204bf5a39332d5a7
@@ -6,7 +6,7 @@ jobs:
6
6
  fail-fast: false
7
7
  matrix:
8
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]
9
+ ruby: [2.5, 2.6, 2.7, '3.0', '3.1', head, jruby]
10
10
  runs-on: ubuntu-latest
11
11
  steps:
12
12
  - uses: actions/checkout@v2
data/CHANGES.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 0.8.0
2
+
3
+ * Use `trailblazer-activity-dsl-linear` 1.0.0.
4
+
5
+ ## 0.7.5
6
+
7
+ * Upgrade `trailblazer-activity` & `trailblazer-activity-dsl-linear` patch versions.
8
+
9
+ ## 0.7.4
10
+
11
+ * Fix `Operation.call` being called twice before delegating to `call_with_circuit_interface`. This is done via a special `call_task` in the operation's taskWrap.
12
+
1
13
  ## 0.7.3
2
14
 
3
15
  * Revert trailblazer-developer to a runtime dependency.
data/Gemfile CHANGED
@@ -16,3 +16,8 @@ gem "minitest-line"
16
16
  # gem "trailblazer-context", path: "../trailblazer-context"
17
17
  # gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
18
18
  # gem "trailblazer-activity", github: "trailblazer/trailblazer-activity"
19
+
20
+ # gem "trailblazer-macro", path: "../trailblazer-macro"
21
+ # gem "trailblazer-activity", path: "../trailblazer-activity"
22
+ # gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
23
+ # gem "trailblazer-declarative"
@@ -2,14 +2,17 @@
2
2
  class Trailblazer::Operation
3
3
  # The use of this module is currently not encouraged and it is only here for backward-compatibility.
4
4
  # Instead, please pass dependencies via containers, locals, or macros into the respective steps.
5
+ #
5
6
  module ClassDependencies
6
7
  def [](field)
7
- @state.to_h[:fields][field]
8
+ class_fields[field]
8
9
  end
9
10
 
11
+ # Store a field on @state, which is provided by {Strategy}.
10
12
  def []=(field, value)
11
- options = @state.to_h[:fields].merge(field => value)
12
- @state.update_options(options)
13
+ @state.update!(:fields) do |fields|
14
+ fields.merge(field => value)
15
+ end
13
16
  end
14
17
 
15
18
  def options_for_public_call(options, flow_options)
@@ -18,7 +21,7 @@ class Trailblazer::Operation
18
21
  end
19
22
 
20
23
  private def class_fields
21
- @state.to_h[:fields]
24
+ @state.get(:fields)
22
25
  end
23
26
 
24
27
  private def context_for_fields(fields, (ctx, flow_options), **)
@@ -14,7 +14,7 @@ module Trailblazer
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(options = {}, flow_options = {}, **circuit_options)
17
- return call_with_circuit_interface(options, **circuit_options) if options.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.
17
+ return call_with_circuit_interface(options, **circuit_options) if options.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 thing as we're fading out Operation::public_call anyway.
18
18
 
19
19
  call_with_public_interface(options, flow_options, **circuit_options)
20
20
  end
@@ -40,7 +40,8 @@ module Trailblazer
40
40
  signal, (ctx, flow_options) = invoke_class.invoke(
41
41
  self,
42
42
  [ctx, flow_options],
43
- exec_context: new
43
+ exec_context: new,
44
+ wrap_static: initial_wrap_static,
44
45
  )
45
46
 
46
47
  # Result is successful if the activity ended with an End event derived from Railway::End::Success.
@@ -79,5 +80,24 @@ module Trailblazer
79
80
  raise "[Trailblazer] `Operation.call_with_flow_options is deprecated in Ruby 3.0. Use `Operation.(options, flow_options)`" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.0.0")
80
81
  call_with_public_interface(options, flow_options, {invoke_class: Activity::TaskWrap})
81
82
  end
83
+
84
+ def initial_wrap_static(*)
85
+ Activity::TaskWrap::Pipeline.new([Activity::TaskWrap::Pipeline.Row("task_wrap.call_task", method(:call_task))])
86
+ end
87
+
88
+ def call_task(wrap_ctx, original_args) # DISCUSS: copied from {TaskWrap.call_task}.
89
+ op = wrap_ctx[:task]
90
+
91
+ original_arguments, original_circuit_options = original_args
92
+
93
+ # Call the actual task we're wrapping here.
94
+ # puts "~~~~wrap.call: #{task}"
95
+ return_signal, return_args = op.call_with_circuit_interface(original_arguments, **original_circuit_options)
96
+
97
+ # DISCUSS: do we want original_args here to be passed on, or the "effective" return_args which are different to original_args now?
98
+ wrap_ctx = wrap_ctx.merge(return_signal: return_signal, return_args: return_args)
99
+
100
+ return wrap_ctx, original_args
101
+ end
82
102
  end
83
103
  end
@@ -38,10 +38,12 @@ module Trailblazer
38
38
  @stack = stack
39
39
  end
40
40
 
41
+ # TODO: deprecate!
41
42
  def wtf
42
43
  Developer::Trace::Present.(@stack)
43
44
  end
44
45
 
46
+ # TODO: deprecate!
45
47
  def wtf?
46
48
  puts wtf
47
49
  end
@@ -1,7 +1,7 @@
1
1
  module Trailblazer
2
2
  module Version
3
3
  module Operation
4
- VERSION = "0.7.3"
4
+ VERSION = "0.8.0.beta1"
5
5
  end
6
6
  end
7
7
  end
@@ -1,12 +1,11 @@
1
+ require "trailblazer/activity/dsl/linear"
1
2
  require 'forwardable'
2
3
  require 'trailblazer/operation/version'
3
- require "trailblazer/option"
4
- require "trailblazer/context"
5
-
6
- require "trailblazer/activity/dsl/linear"
7
4
 
8
5
  module Trailblazer
9
- # DISCUSS: I don't know where else to put this. It's not part of the {Activity} concept
6
+ # As opposed to {Activity::Railway} and {Activity::FastTrack} an operation
7
+ # maintains different terminus subclasses.
8
+ # DISCUSS: remove this, at some point in time!
10
9
  class Activity
11
10
  class Railway
12
11
  module End
@@ -31,6 +30,7 @@ module Trailblazer
31
30
  end
32
31
  end
33
32
 
33
+ # DISCUSS: where do we need this?
34
34
  def self.Operation(options)
35
35
  Class.new(Activity::FastTrack( Activity::Operation.OptionsForState.merge(options) )) do
36
36
  extend Operation::PublicCall
@@ -38,16 +38,14 @@ module Trailblazer
38
38
  end
39
39
 
40
40
  # The Trailblazer-style operation.
41
- # Note that you don't have to use our "opinionated" version with result object, skills, etc.
42
- class Operation < Activity::FastTrack(Activity::Operation.OptionsForState)
43
- # extend Skill::Accessors # ::[] and ::[]= # TODO: fade out this usage.
44
-
41
+ # Note that you don't have to use our "opinionated" version with result object, etc.
42
+ class Operation < Activity::FastTrack(**Activity::Operation.OptionsForState)
45
43
  class << self
46
44
  alias_method :strategy_call, :call
47
45
  end
48
46
 
49
47
  require "trailblazer/operation/public_call" # TODO: Remove in 3.0.
50
- extend PublicCall # ::call(params, { current_user: .. })
48
+ extend PublicCall # ::call(params: .., current_user: ..)
51
49
 
52
50
  require "trailblazer/operation/trace"
53
51
  extend Trace # ::trace
@@ -8,16 +8,43 @@ class ClassDependenciesTest < Minitest::Spec
8
8
 
9
9
  self["model.class"] = Module
10
10
 
11
- step ->(options, **) { options["a"] = options["model.class"] }
11
+ step ->(ctx, **) { ctx["a"] = ctx["model.class"] }
12
12
  end
13
13
 
14
14
  it { Index.({}).inspect("a", "model.class").must_equal %{<Result:true [Module, Module] >} }
15
15
 
16
16
  it "creates separate ctx for circuit interface" do
17
+ # raise "this can't work since the OP is run without TaskWrap.invoke"
17
18
  signal, (ctx, _) = Index.([{}, {}], {})
18
19
 
19
- ctx["model.class"].inspect.must_equal %{Module} # FIXME: should this be here?
20
20
  ctx[:a].inspect.must_equal %{Module}
21
+ ctx["model.class"].inspect.must_equal %{Module} # FIXME: should this be here?
22
+ end
23
+
24
+ # nested OPs
25
+ it "injects class dependencies for nested OP" do
26
+ class Home < Trailblazer::Operation
27
+ step Subprocess(Index)
28
+ end
29
+
30
+ # "model.class" gets injected automatically just before {Index}.
31
+ Home.({params: {}}).inspect.must_equal %{<Result:true #<Trailblazer::Context::Container wrapped_options={\"model.class\"=>Module} mutable_options=#<Trailblazer::Context::Container wrapped_options={:params=>{}} mutable_options={\"a\"=>Module}>> >}
32
+
33
+ # "model.class" gets injected by user and overrides class dependencies.
34
+ Home.({params: {}, "model.class" => Symbol}).inspect.must_equal %{<Result:true #<Trailblazer::Context::Container wrapped_options={\"model.class\"=>Module} mutable_options=#<Trailblazer::Context::Container wrapped_options={:params=>{}, \"model.class\"=>Symbol} mutable_options={\"a\"=>Symbol}>> >}
35
+
36
+
37
+ class Dashboard < Trailblazer::Operation
38
+ extend ClassDependencies
39
+ self["model.class"] = Float # this overrides {Index}'es dependency
40
+
41
+ pass ->(ctx, **) { ctx[:Dashboard] = ctx["model.class"] }
42
+ step Subprocess(Index)
43
+ end
44
+
45
+ # TODO: "model.class" gets injected automatically in {Dashboard} and overrides the {Index} input.
46
+ Dashboard.({params: {}}).inspect.must_equal %{<Result:true #<Trailblazer::Context::Container wrapped_options={\"model.class\"=>Module} mutable_options=#<Trailblazer::Context::Container wrapped_options={\"model.class\"=>Float} mutable_options=#<Trailblazer::Context::Container wrapped_options={\"model.class\"=>Float} mutable_options=#<Trailblazer::Context::Container wrapped_options={:params=>{}} mutable_options={:Dashboard=>Float, \"a\"=>Float}>>>> >}
47
+
21
48
  end
22
49
 
23
50
  describe "inheritance" do
@@ -1,6 +1,28 @@
1
1
  require "test_helper"
2
2
 
3
3
  class DeclarativeApiTest < Minitest::Spec
4
+ it "doesn't invoke {call} twice when using public interface" do
5
+ class MyOp < Trailblazer::Operation
6
+ @@GLOBAL = []
7
+ def self.global; @@GLOBAL; end
8
+
9
+
10
+ def self.call(*args)
11
+ @@GLOBAL << :call
12
+ super
13
+ end
14
+
15
+ pass :model
16
+
17
+ def model(ctx, **)
18
+ @@GLOBAL << :model
19
+ end
20
+ end
21
+
22
+ MyOp.({})
23
+ MyOp.global.inspect.must_equal %{[:call, :model]}
24
+ end
25
+
4
26
  #---
5
27
  #- step, pass, fail
6
28
 
data/test/step_test.rb CHANGED
@@ -177,13 +177,13 @@ class StepTest < Minitest::Spec
177
177
  #-
178
178
  # not existent :name
179
179
  it do
180
- op = assert_raises Trailblazer::Activity::DSL::Linear::Sequence::IndexError do
180
+ op = assert_raises Trailblazer::Activity::Adds::IndexError do
181
181
  class InvalidStep < Trailblazer::Operation
182
182
  step :a, before: "I don't exist!"
183
183
  end
184
184
  end
185
185
 
186
- error_message = %{#<Trailblazer::Activity::DSL::Linear::Sequence::IndexError: StepTest::InvalidStep:
186
+ error_message = %{#<Trailblazer::Activity::Adds::IndexError: StepTest::InvalidStep:
187
187
  \e[31m\"I don't exist!\" is not a valid step ID. Did you mean any of these ?\e[0m
188
188
  \e[32m\"Start.default\"
189
189
  \"End.success\"
@@ -17,8 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "trailblazer-activity-dsl-linear", ">= 0.4.0", "< 1.0.0"
21
- spec.add_dependency "trailblazer-developer", ">= 0.0.21", "< 1.0.0"
20
+ spec.add_dependency "trailblazer-activity-dsl-linear", ">= 1.0.0.beta1", "< 1.1.0"
21
+ spec.add_dependency "trailblazer-developer", ">= 0.0.26"
22
22
 
23
23
  spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "minitest"
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.7.3
4
+ version: 0.8.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-12 00:00:00.000000000 Z
11
+ date: 2022-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer-activity-dsl-linear
@@ -16,40 +16,34 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.0
19
+ version: 1.0.0.beta1
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 1.0.0
22
+ version: 1.1.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.4.0
29
+ version: 1.0.0.beta1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 1.0.0
32
+ version: 1.1.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: trailblazer-developer
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 0.0.21
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: 1.0.0
39
+ version: 0.0.26
43
40
  type: :runtime
44
41
  prerelease: false
45
42
  version_requirements: !ruby/object:Gem::Requirement
46
43
  requirements:
47
44
  - - ">="
48
45
  - !ruby/object:Gem::Version
49
- version: 0.0.21
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: 1.0.0
46
+ version: 0.0.26
53
47
  - !ruby/object:Gem::Dependency
54
48
  name: bundler
55
49
  requirement: !ruby/object:Gem::Requirement
@@ -161,7 +155,7 @@ homepage: http://trailblazer.to
161
155
  licenses:
162
156
  - MIT
163
157
  metadata: {}
164
- post_install_message:
158
+ post_install_message:
165
159
  rdoc_options: []
166
160
  require_paths:
167
161
  - lib
@@ -172,12 +166,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
166
  version: 2.1.0
173
167
  required_rubygems_version: !ruby/object:Gem::Requirement
174
168
  requirements:
175
- - - ">="
169
+ - - ">"
176
170
  - !ruby/object:Gem::Version
177
- version: '0'
171
+ version: 1.3.1
178
172
  requirements: []
179
- rubygems_version: 3.0.8
180
- signing_key:
173
+ rubygems_version: 3.2.3
174
+ signing_key:
181
175
  specification_version: 4
182
176
  summary: Trailblazer's operation object with railway flow and integrated error handling.
183
177
  test_files: