trailblazer-operation 0.7.0 → 0.7.5

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: 5a184243cc5650f8905e96a29d4abd248f463dcf8e2c5ec28d3a68de6391ae4e
4
- data.tar.gz: 8c8eeb9c36d0065096e1c9be60872254c0776ecd6dd617d439aa55c3896f020e
3
+ metadata.gz: e06d73c350844dbfc8a0e2f1e7a6fab4d2943d52bb3efb8b35c51b5f9a042926
4
+ data.tar.gz: 658a1b5b6d94a14d2f3b6a92c2da8bae5c0b4c157393a5da218fbe3bbdac8caf
5
5
  SHA512:
6
- metadata.gz: c1abb34f87e18425f77c6189ded96dd0f02c39f9e2ce178b1d2bfff3d2b2e8c2c4dd4d37e88a770ffc8b8457613dbc4e334b8e2e7924395c07bd4a59c6bd3376
7
- data.tar.gz: 68fb2740d396b174c7eaa62e0145049755ff593fbf7bdba66825b79caa7908b35b954b8508528b6a6f93883fee3f372e2043a860f968bf5699cb2bceea1c3f17
6
+ metadata.gz: e9b30666287aa4e737a393266e9be36f2eb8fed6543329fb99c23afc17aa7b5ffd54c765e0adf008f62d673b4d4ff3a9a34e7b81e808c825b8f6faf9e3a0c0fd
7
+ data.tar.gz: 5a022c81097174f73a9894b6b9a52333eaf5e83e300a1d3054a9abdb1205a7825a0b2da0ec643206f75cc33b35c21140682b2733cd2dccd559a47e0efc0a101a
@@ -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,23 @@
1
+ ## 0.7.5
2
+
3
+ * Upgrade `trailblazer-activity` & `trailblazer-activity-dsl-linear` patch versions.
4
+
5
+ ## 0.7.4
6
+
7
+ * 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.
8
+
9
+ ## 0.7.3
10
+
11
+ * Revert trailblazer-developer to a runtime dependency.
12
+
13
+ ## 0.7.2
14
+
15
+ * Bugfix: when calling `Operation.call(params: {}, "current_user" => user)` the stringified variables got lost in Ruby < 3.
16
+
17
+ ## 0.7.1
18
+
19
+ * In `Operation.call_with_public_interface`, pass `self` and not `@activity` to the `invoke`r. This fixes tracing as it now catches the actual Operation class, not an activity instance.
20
+
1
21
  ## 0.7.0
2
22
 
3
23
  * Compatible with Ruby 2.4-3.0.
@@ -47,7 +47,7 @@ module Trailblazer
47
47
  end
48
48
 
49
49
  require "trailblazer/operation/public_call" # TODO: Remove in 3.0.
50
- extend PublicCall # ::call(params, { current_user: .. })
50
+ extend PublicCall # ::call(params: .., current_user: ..)
51
51
 
52
52
  require "trailblazer/operation/trace"
53
53
  extend Trace # ::trace
@@ -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
@@ -29,17 +29,19 @@ module Trailblazer
29
29
  def call_with_public_interface(options, flow_options, invoke_class: Activity::TaskWrap, **circuit_options)
30
30
  flow_options = flow_options_for_public_call(flow_options)
31
31
 
32
- options = circuit_options.any? ? circuit_options : options # This is needed in Ruby 3 for {Create.(params: {})} calls.
33
-
32
+ # In Ruby < 3, calling Op.(params: {}, "current_user" => user) results in both {circuit_options} and {options} containing variables.
33
+ # In Ruby 3.0, **circuit_options is always empty.
34
+ options = circuit_options.any? ? circuit_options.merge(options) : options
34
35
 
35
36
  ctx = options_for_public_call(options, flow_options)
36
37
 
37
38
  # call the activity.
38
39
  # This will result in invoking {::call_with_circuit_interface}.
39
40
  signal, (ctx, flow_options) = invoke_class.invoke(
40
- @activity,
41
+ self,
41
42
  [ctx, flow_options],
42
- exec_context: new
43
+ exec_context: new,
44
+ wrap_static: initial_wrap_static,
43
45
  )
44
46
 
45
47
  # Result is successful if the activity ended with an End event derived from Railway::End::Success.
@@ -78,5 +80,24 @@ module Trailblazer
78
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")
79
81
  call_with_public_interface(options, flow_options, {invoke_class: Activity::TaskWrap})
80
82
  end
83
+
84
+ def initial_wrap_static(*)
85
+ Activity::TaskWrap::Pipeline.new([["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
81
102
  end
82
103
  end
@@ -1,7 +1,7 @@
1
1
  module Trailblazer
2
2
  module Version
3
3
  module Operation
4
- VERSION = "0.7.0"
4
+ VERSION = "0.7.5"
5
5
  end
6
6
  end
7
7
  end
@@ -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
 
@@ -95,6 +117,17 @@ class DeclarativeApiTest < Minitest::Spec
95
117
  Unset. ("params" => {decide: true}).inspect("a", "b", "c", "d", "e").must_equal %{<Result:true [false, true, nil, 1, 2] >}
96
118
  end
97
119
 
120
+ # Mixing keywords and string keys in {Operation.call}.
121
+ # Test that {.(params: {}, "current_user" => user)} is processed properly
122
+ class Collect < Trailblazer::Operation
123
+ # step ->(ctx, **) { ctx[:keys] }
124
+ end
125
+
126
+ it "contains all keys from {call}" do
127
+ result = Collect.(params: {}, "current_user" => Module)
128
+ _(result.inspect).must_equal %{<Result:true #<Trailblazer::Context::Container wrapped_options={:params=>{}, \"current_user\"=>Module} mutable_options={}> >}
129
+ end
130
+
98
131
  #---
99
132
  #- ctx container
100
133
  it do
data/test/step_test.rb CHANGED
@@ -178,12 +178,20 @@ class StepTest < Minitest::Spec
178
178
  # not existent :name
179
179
  it do
180
180
  op = assert_raises Trailblazer::Activity::DSL::Linear::Sequence::IndexError do
181
- Class.new(Trailblazer::Operation) do
181
+ class InvalidStep < Trailblazer::Operation
182
182
  step :a, before: "I don't exist!"
183
183
  end
184
184
  end
185
- assert_equal Trailblazer::Activity::DSL::Linear::Sequence::IndexError, op.class
186
- # assert_match /<Trailblazer::Activity::DSL::Linear::Sequence::IndexError: .+ is not a valid step ID. Did you mean any of these ?/, op.inspect
185
+
186
+ error_message = %{#<Trailblazer::Activity::DSL::Linear::Sequence::IndexError: StepTest::InvalidStep:
187
+ \e[31m\"I don't exist!\" is not a valid step ID. Did you mean any of these ?\e[0m
188
+ \e[32m\"Start.default\"
189
+ \"End.success\"
190
+ \"End.pass_fast\"
191
+ \"End.fail_fast\"
192
+ \"End.failure\"\e[0m>}
193
+
194
+ assert_match error_message, op.inspect
187
195
  end
188
196
 
189
197
  #---
data/test/trace_test.rb CHANGED
@@ -56,7 +56,7 @@ class TraceTest < Minitest::Spec
56
56
  result = Create.wtf?(params: {x: 1}, a_return: true)
57
57
  end
58
58
 
59
- output.gsub(/0x\w+/, "").gsub(/@.+_test/, "").must_equal %{`-- #<Trailblazer::Activity:>
59
+ output.gsub(/0x\w+/, "").gsub(/@.+_test/, "").must_equal %{`-- TraceTest::Create
60
60
  |-- \e[32mStart.default\e[0m
61
61
  |-- \e[32mCreate.task.a\e[0m
62
62
  |-- MyNested
@@ -17,13 +17,14 @@ 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"
20
+ spec.add_dependency "trailblazer-activity-dsl-linear", ">= 0.4.1", "< 1.0.0"
21
+ spec.add_dependency "trailblazer-activity", ">= 0.12.2", "< 1.0.0"
22
+ spec.add_dependency "trailblazer-developer", ">= 0.0.21", "< 1.0.0"
21
23
 
22
24
  spec.add_development_dependency "bundler"
23
25
  spec.add_development_dependency "minitest"
24
26
  spec.add_development_dependency "rake"
25
27
  spec.add_development_dependency "rubocop"
26
- spec.add_development_dependency "trailblazer-developer"
27
28
 
28
29
  spec.required_ruby_version = ">= 2.1.0"
29
30
  end
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.0
4
+ version: 0.7.5
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-03 00:00:00.000000000 Z
11
+ date: 2021-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer-activity-dsl-linear
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.0
19
+ version: 0.4.1
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 1.0.0
@@ -26,26 +26,52 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.4.0
29
+ version: 0.4.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.0.0
33
33
  - !ruby/object:Gem::Dependency
34
- name: bundler
34
+ name: trailblazer-activity
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
40
- type: :development
39
+ version: 0.12.2
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 1.0.0
43
+ type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
47
  - - ">="
45
48
  - !ruby/object:Gem::Version
46
- version: '0'
49
+ version: 0.12.2
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 1.0.0
47
53
  - !ruby/object:Gem::Dependency
48
- name: minitest
54
+ name: trailblazer-developer
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.0.21
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 0.0.21
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: 1.0.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: bundler
49
75
  requirement: !ruby/object:Gem::Requirement
50
76
  requirements:
51
77
  - - ">="
@@ -59,7 +85,7 @@ dependencies:
59
85
  - !ruby/object:Gem::Version
60
86
  version: '0'
61
87
  - !ruby/object:Gem::Dependency
62
- name: rake
88
+ name: minitest
63
89
  requirement: !ruby/object:Gem::Requirement
64
90
  requirements:
65
91
  - - ">="
@@ -73,7 +99,7 @@ dependencies:
73
99
  - !ruby/object:Gem::Version
74
100
  version: '0'
75
101
  - !ruby/object:Gem::Dependency
76
- name: rubocop
102
+ name: rake
77
103
  requirement: !ruby/object:Gem::Requirement
78
104
  requirements:
79
105
  - - ">="
@@ -87,7 +113,7 @@ dependencies:
87
113
  - !ruby/object:Gem::Version
88
114
  version: '0'
89
115
  - !ruby/object:Gem::Dependency
90
- name: trailblazer-developer
116
+ name: rubocop
91
117
  requirement: !ruby/object:Gem::Requirement
92
118
  requirements:
93
119
  - - ">="
@@ -107,10 +133,10 @@ executables: []
107
133
  extensions: []
108
134
  extra_rdoc_files: []
109
135
  files:
136
+ - ".github/workflows/ci.yml"
110
137
  - ".gitignore"
111
138
  - ".rubocop.yml"
112
139
  - ".rubocop_todo.yml"
113
- - ".travis.yml"
114
140
  - CHANGES.md
115
141
  - Gemfile
116
142
  - README.md
@@ -155,7 +181,7 @@ homepage: http://trailblazer.to
155
181
  licenses:
156
182
  - MIT
157
183
  metadata: {}
158
- post_install_message:
184
+ post_install_message:
159
185
  rdoc_options: []
160
186
  require_paths:
161
187
  - lib
@@ -170,8 +196,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
196
  - !ruby/object:Gem::Version
171
197
  version: '0'
172
198
  requirements: []
173
- rubygems_version: 3.2.3
174
- signing_key:
199
+ rubygems_version: 3.0.8
200
+ signing_key:
175
201
  specification_version: 4
176
202
  summary: Trailblazer's operation object with railway flow and integrated error handling.
177
203
  test_files:
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - ruby-head
4
- - 3.0
5
- - 2.7
6
- - 2.6
7
- - 2.5
8
- - 2.4
9
- jobs:
10
- allow_failures:
11
- - rvm: ruby-head