trailblazer-macro 2.1.13 → 2.1.15

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: 5cdf91d3afe4c31815401fd46ca1b6a8778dd2b1b89db4871c7dcff708cc73ff
4
- data.tar.gz: 48c050c6086a5be67804385a427a95e0df1ab4cf0802de5004b61a96a8e54ced
3
+ metadata.gz: 173e4338e28a9317e1d4982e9cfa9c2662b1639f852c63e17d389d8aac1dbf6f
4
+ data.tar.gz: cfe156150849b2114783ae54799dbc6a9cc1aaf98ee94a076cf2236855c1aebd
5
5
  SHA512:
6
- metadata.gz: 3a27a00484972d2c65a6ffad50bd34e1fff0cfee69382bb5fabd3a06f20e15f818f95d44ce03a13727095fe352901ca0fdfcc544e15ec066bc73e43d14b8b6df
7
- data.tar.gz: c64786889c195182f399c9df157f67926622ae7c032d9ef8c8de47db89b37750544721b1261a7ea5fe5f731208eccb3192aac2fe2c92b77036cbcd3ce68e4070
6
+ metadata.gz: b5d91f20bf7ea34b3328a7cb2419dc3d3df264e998605f887afee09379bc10a41222016f0f63c0512f5caab2236b8528997096baf3b4ec0f17ae2b4b8bb25303
7
+ data.tar.gz: 3a80eb7b70c7c8d9667bad7571c7d8471dc7bfc28ad00fdb40f94ceb5dc4fcae1de7ffae9a4d76848c61526f06cb2d0d85c612e2a5d01f2acb849ed28c1821f0
@@ -1,6 +1,3 @@
1
- ## This file is managed by Terraform.
2
- ## Do not modify this file directly, as it may be overwritten.
3
- ## Please open an issue instead.
4
1
  name: CI
5
2
  on: [push, pull_request]
6
3
  jobs:
@@ -8,7 +5,7 @@ jobs:
8
5
  strategy:
9
6
  fail-fast: false
10
7
  matrix:
11
- ruby: [2.7, '3.0', '3.1']
8
+ ruby: [2.5, 2.6, 2.7, '3.0', '3.1', '3.2', 'jruby']
12
9
  runs-on: ubuntu-latest
13
10
  steps:
14
11
  - uses: actions/checkout@v3
data/CHANGES.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 2.1.15
2
+
3
+ * Use `Macro.id_for` for `Rescue`, meaning IDs will now be consistent à la `Rescue/1` instead of `Rescue(1)`.
4
+ * In `Each`'s tracing code, use `developer-0.1.0` API.
5
+ * Use `trailblazer-operation-0.10.1`.
6
+
7
+ # 2.1.14
8
+
9
+ * Use `trailblazer-activity-dsl-linear-1.2.0` and change internal API as required.
10
+
1
11
  # 2.1.13
2
12
 
3
13
  * Fix an introspect bug in `Each()` where we couldn't look into `"invoke_block_activity"`.
data/Gemfile CHANGED
@@ -4,14 +4,15 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  # gem "trailblazer-developer", github: "trailblazer/trailblazer-developer"
7
+ # gem "trailblazer-developer", path: "../trailblazer-developer"
7
8
  # gem "trailblazer-activity", github: "trailblazer/trailblazer-activity"
8
9
  # gem "trailblazer-activity-dsl-linear", github: "trailblazer/trailblazer-activity-dsl-linear"
9
- # gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
10
- # gem "trailblazer-developer", path: "../trailblazer-developer"
11
- # gem "trailblazer-activity", path: "../trailblazer-activity"
12
10
  # gem "trailblazer-macro-contract", git: "https://github.com/trailblazer/trailblazer-macro-contract"
13
- # gem "trailblazer-context", path: "../trailblazer-context"
14
- # gem "trailblazer-option", path: "../trailblazer-option"
11
+
12
+ # gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
13
+ # gem "trailblazer-developer", path: "../trailblazer-developer"
14
+ # gem "trailblazer-activity", path: "../trailblazer-activity"
15
+ gem "trailblazer-operation", path: "../trailblazer-operation"
15
16
 
16
17
  gem "minitest-line"
17
18
  # gem "trailblazer-core-utils", path: "../trailblazer-core-utils"
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require "rake/testtask"
3
3
 
4
4
  Rake::TestTask.new(:test) do |test|
5
5
  test.libs << 'test'
6
- test.test_files = FileList['test/**/*_test.rb']
6
+ test.test_files = FileList['test/**/*_test.rb'] #- FileList['test/docs/autogenerated/*_test.rb']
7
7
  test.verbose = true
8
8
  end
9
9
 
@@ -66,11 +66,16 @@ module Trailblazer
66
66
  ITERATION_INPUT_PIPE = Activity::DSL::Linear::VariableMapping::DSL.pipe_for_composable_input()
67
67
 
68
68
  # Gets included in Debugger's Normalizer. Results in IDs like {invoke_block_activity.1}.
69
- def self.compute_runtime_id(ctx, captured_node:, activity:, compile_id:, **)
69
+ def self.compute_runtime_id(ctx, trace_node:, activity:, compile_id:, **)
70
70
  # activity is the host activity
71
- return compile_id unless activity[:each] == true
71
+ return compile_id unless activity.to_h[:config][:each] == true
72
72
 
73
- index = captured_node.captured_input.data[:ctx_snapshot].fetch(:index)
73
+ # Developer::Trace::Snapshot::Ctx.ctx_snapshot_for(trace_node.snapshot_before, .data
74
+ # FIXME: BETTER API, we need access to stack now
75
+
76
+
77
+ # index = trace_node.snapshot_before.data[:ctx_snapshot].fetch(:index)
78
+ index = trace_node.snapshot_before.data[:ctx_variable_changeset].find { |name, version, value| name == :index }[2]
74
79
 
75
80
  ctx[:runtime_id] = "#{compile_id}.#{index}"
76
81
  end
@@ -94,16 +99,20 @@ module Trailblazer
94
99
  # This activity is passed into the {Runner} for each iteration of {block_activity}.
95
100
  container_activity = Activity::TaskWrap.container_activity_for(
96
101
  block_activity,
97
- each: true, # mark this activity for {compute_runtime_id}.
98
- nodes: [Activity::NodeAttributes.new("invoke_block_activity", nil, block_activity)], # TODO: use TaskMap::TaskAttributes
99
- outputs: outputs_from_block_activity,
102
+ id: "invoke_block_activity",
103
+ # merged into {:config}:
104
+ each: true, # mark this activity for {compute_runtime_id}.
100
105
  ).merge(
101
- # FIXME: we can't pass {wrap_static: wrap_static_for_block_activity} into {#container_activity_for}
102
- # because when patching, the container_activity is not recompiled, so we need the Hash here
103
- # with defaulting.
104
- wrap_static: Hash.new(wrap_static_for_block_activity)
106
+ outputs: outputs_from_block_activity,
105
107
  )
106
108
 
109
+ # FIXME: we can't pass {wrap_static: wrap_static_for_block_activity} into {#container_activity_for}
110
+ # because when patching, the container_activity is not recompiled, so we need the Hash here
111
+ # with defaulting.
112
+ # FIXME: this "hack" is only here to satify patching.
113
+ config = container_activity[:config].merge(wrap_static: Hash.new(wrap_static_for_block_activity))
114
+ container_activity.merge!(config: config)
115
+
107
116
  # DISCUSS: move to Wrap.
108
117
  termini_from_block_activity =
109
118
  outputs_from_block_activity.
@@ -113,7 +113,7 @@ module Trailblazer
113
113
  def self.host_activity_for(activity:)
114
114
  Activity::TaskWrap.container_activity_for(
115
115
  activity,
116
- nodes: [Trailblazer::Activity::NodeAttributes.new(activity.to_s, nil, activity)],
116
+ id: activity.to_s
117
117
  )
118
118
  end
119
119
 
@@ -127,7 +127,7 @@ module Trailblazer
127
127
  # this will help when semantics overlap.
128
128
  #
129
129
  def self.Static(decider, id:, auto_wire:)
130
- decider_outputs = auto_wire.collect do |activity|
130
+ decider_connectors = auto_wire.collect do |activity|
131
131
  [Activity::Railway.Output(activity, "decision:#{activity}"), Activity::Railway.Track(activity)]
132
132
  end.to_h
133
133
 
@@ -136,7 +136,7 @@ module Trailblazer
136
136
  {
137
137
  task: Static.method(:return_route_signal),
138
138
  id: :route_to_nested_activity, # returns the {nested_activity} signal
139
- }.merge(decider_outputs)
139
+ }.merge(decider_connectors)
140
140
  )
141
141
 
142
142
  auto_wire.each do |activity|
@@ -1,10 +1,8 @@
1
- require "securerandom"
2
-
3
1
  module Trailblazer
4
2
  module Macro
5
3
  NoopHandler = lambda { |*| }
6
4
 
7
- def self.Rescue(*exceptions, handler: NoopHandler, &block)
5
+ def self.Rescue(*exceptions, handler: NoopHandler, id: Rescue.random_id, &block)
8
6
  exceptions = [StandardError] unless exceptions.any?
9
7
 
10
8
  handler = Rescue.deprecate_positional_handler_signature(handler)
@@ -22,9 +20,7 @@ module Trailblazer
22
20
  end
23
21
  end
24
22
 
25
- Wrap(rescue_block, id: "Rescue(#{SecureRandom.hex(4)})", &block)
26
- # FIXME: name
27
- # [ step, name: "Rescue:#{block.source_location.last}" ]
23
+ Wrap(rescue_block, id: id, &block)
28
24
  end
29
25
 
30
26
  # TODO: remove me in 2.2.
@@ -38,6 +34,12 @@ module Trailblazer
38
34
  handler.(exception, ctx, &block)
39
35
  end
40
36
  end
37
+
38
+ # TODO: for legacy reasons, we pass `:id` to {#id_for}. In 2.2, remove the id hint and use
39
+ # generic {Macro.id_for} behavior.
40
+ def self.random_id
41
+ Macro.id_for(nil, macro: :Rescue, id: rand(100))
42
+ end
41
43
  end
42
44
  end
43
45
  end
@@ -1,7 +1,7 @@
1
1
  module Trailblazer
2
2
  module Version
3
3
  module Macro
4
- VERSION = "2.1.13"
4
+ VERSION = "2.1.15"
5
5
  end
6
6
  end
7
7
  end
@@ -51,8 +51,14 @@ module Trailblazer
51
51
  return block_activity, block_activity.to_h[:outputs]
52
52
  end
53
53
 
54
- def self.id_for(user_proc, macro:, hint: nil)
55
- id =
54
+ module IdFor
55
+ module_function
56
+
57
+ def call(user_proc, macro:, hint: nil, id: from_callable(user_proc, hint: hint))
58
+ [macro, id].join("/")
59
+ end
60
+
61
+ def from_callable(user_proc, hint: nil)
56
62
  if user_proc.is_a?(Class)
57
63
  user_proc.to_s
58
64
  elsif user_proc.instance_of?(Method)
@@ -60,8 +66,11 @@ module Trailblazer
60
66
  else
61
67
  hint || rand(4)
62
68
  end
69
+ end
70
+ end
63
71
 
64
- "#{macro}/#{id}"
72
+ def self.id_for(user_proc, **options)
73
+ IdFor.(user_proc, **options)
65
74
  end
66
75
  end # Macro
67
76
 
@@ -54,10 +54,11 @@ class EachTest < Minitest::Spec
54
54
  def composers_for_each(ctx, model:, **)
55
55
  model.composers
56
56
  end
57
-
57
+ #:iterated-value
58
58
  def notify_composers(ctx, index:, item:, **)
59
59
  ctx[:value] = [index, item.full_name]
60
60
  end
61
+ #:iterated-value end
61
62
 
62
63
  #~meths
63
64
  def model(ctx, params:, **)
@@ -590,9 +591,10 @@ class EachStrategyComplianceTest < Minitest::Spec
590
591
  EachPureTest::Mailer.send_options = []
591
592
 
592
593
  #:patch
593
- cover_patched = Trailblazer::Activity::DSL::Linear.Patch(
594
+ cover_patched = Trailblazer::Activity::DSL::Linear::Patch.(
594
595
  Song::Activity::Cover,
595
- ["Each/composers_for_each", "Each.iterate.block"] => -> { step :log_email }
596
+ ["Each/composers_for_each", "Each.iterate.block"],
597
+ -> { step :log_email }
596
598
  )
597
599
  #:patch end
598
600
  cover_patched.include(T.def_steps(:log_email, :notify_composers))
@@ -707,7 +709,7 @@ class EachIDTest < Minitest::Spec
707
709
  assert_equal Trailblazer::Developer::Introspect.find_path(activity, ["Each-1"])[0].id, "Each-1"
708
710
  assert_equal Trailblazer::Developer::Introspect.find_path(activity, ["Each/composers_for_each"])[0].id, "Each/composers_for_each"
709
711
 
710
- assert_match /Each\/\w+/, Trailblazer::Activity::Introspect::TaskMap(activity).values[1].id
712
+ assert_match /Each\/\w+/, Trailblazer::Activity::Introspect::Nodes(activity).values[1].id # FIXME: this test sucks.
711
713
  end
712
714
  end
713
715
 
@@ -738,8 +740,11 @@ class DocsEachUnitTest < Minitest::Spec
738
740
 
739
741
  stack, signal, (ctx, _) = Trailblazer::Developer::Trace.invoke(activity, [ctx, {}])
740
742
 
741
- assert_equal Trailblazer::Developer::Trace::Present.(stack,
742
- node_options: {stack.to_a[0] => {label: "<a-Each-b>"}}), %{<a-Each-b>
743
+ output = Trailblazer::Developer::Trace::Present.(stack) do |trace_nodes:, **|
744
+ {node_options: {trace_nodes[0] => {label: "<a-Each-b>"}}}
745
+ end
746
+
747
+ assert_equal output, %{<a-Each-b>
743
748
  |-- Start.default
744
749
  |-- a
745
750
  |-- Each/1
@@ -23,7 +23,7 @@ class NestedRescueTest < Minitest::Spec
23
23
  fail ->(options, **) { options["outer-err"] = true }, id: "nested/failure"
24
24
  end
25
25
 
26
- it { Trailblazer::Developer.railway(NestedInsanity).must_match /\[>Rescue\(.{8}\),>nested/ } # FIXME: better introspect tests for all id-generating macros.
26
+ it { Trailblazer::Developer.railway(NestedInsanity).must_match /\[>Rescue\/.{1,3},>nested/ } # FIXME: better introspect tests for all id-generating macros.
27
27
  it { NestedInsanity.().inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:true [true, true, true, true, true, true, nil, nil] >} }
28
28
  it { NestedInsanity.( "raise-y" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:false [true, true, nil, nil, nil, nil, true, true] >} }
29
29
  it { NestedInsanity.( "raise-a" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:false [true, true, true, true, nil, nil, nil, true] >} }
@@ -43,31 +43,37 @@ class RescueTest < Minitest::Spec
43
43
  plain Rescue()
44
44
  =end
45
45
  class RescueWithoutHandlerTest < Minitest::Spec
46
- Memo = Class.new
46
+ Song = Class.new
47
+ module Song::Activity; end
47
48
 
48
- class Memo::Create < Trailblazer::Operation
49
- step :find_model
49
+ #:no-args
50
+ class Song::Activity::Create < Trailblazer::Activity::Railway
51
+ step :create_model
50
52
  step Rescue() {
51
- step :update
53
+ step :upload
52
54
  step :rehash
53
55
  }
54
56
  step :notify
55
57
  fail :log_error
56
58
  #~methods
57
- include T.def_steps(:find_model, :update, :notify, :log_error)
59
+ include T.def_steps(:create_model, :upload, :notify, :log_error)
58
60
  include Rehash
59
61
  #~methods end
60
62
  end
63
+ #:no-args end
61
64
 
62
- it { Memo::Create.( { seq: [] } ).inspect(:seq, :exception_class).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
63
- it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error]] >} }
65
+ it { assert_invoke Song::Activity::Create, seq: "[:create_model, :upload, :rehash, :notify]" }
66
+ it { assert_invoke Song::Activity::Create, rehash_raise: RuntimeError, terminus: :failure, seq: "[:create_model, :upload, :rehash, :log_error]", exception_class: RuntimeError }
67
+ it { assert_invoke Song::Activity::Create, rehash_raise: :bla, terminus: :failure, seq: "[:create_model, :upload, :rehash, :log_error]", exception_class: :bla }
68
+ it { assert_invoke Song::Activity::Create, rehash_raise: NoMethodError, terminus: :failure, seq: "[:create_model, :upload, :rehash, :log_error]", exception_class: NoMethodError }
64
69
  end
65
70
 
66
71
  =begin
67
- Rescue( handler: X )
72
+ Rescue( SPECIFIC_EXCEPTION, handler: X )
68
73
  =end
69
74
  class RescueWithClassHandlerTest < Minitest::Spec
70
- Memo = Class.new
75
+ Song = Class.new
76
+ module Song::Activity; end
71
77
 
72
78
  #:rescue-handler
73
79
  class MyHandler
@@ -78,23 +84,29 @@ Rescue( handler: X )
78
84
  #:rescue-handler end
79
85
 
80
86
  #:rescue
81
- class Memo::Create < Trailblazer::Operation
82
- step :find_model
83
- step Rescue( RuntimeError, handler: MyHandler ) {
84
- step :update
87
+ class Song::Activity::Create < Trailblazer::Activity::Railway
88
+ step :create_model
89
+ step Rescue(RuntimeError, handler: MyHandler) {
90
+ step :upload
85
91
  step :rehash
86
92
  }
87
93
  step :notify
88
94
  fail :log_error
89
95
  #~methods
90
- include T.def_steps(:find_model, :update, :notify, :log_error)
96
+ include T.def_steps(:create_model, :upload, :notify, :log_error)
91
97
  include Rehash
92
98
  #~methods end
93
99
  end
94
100
  #:rescue end
95
101
 
96
- it { Memo::Create.( { seq: [], } ).inspect(:seq, :exception_class).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
97
- it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq, :exception_class).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
102
+ it { assert_invoke Song::Activity::Create, seq: "[:create_model, :upload, :rehash, :notify]" }
103
+ it { assert_invoke Song::Activity::Create, rehash_raise: RuntimeError, terminus: :failure, seq: "[:create_model, :upload, :rehash, :log_error]", exception_class: RuntimeError }
104
+ it do
105
+ # Since we don't catch NoMethodError, execution stops.
106
+ assert_raises NoMethodError do
107
+ Song::Activity::Create.invoke([{seq: {}, rehash_raise: NoMethodError}])
108
+ end
109
+ end
98
110
  end
99
111
 
100
112
  class RescueWithModuleHandlerTest < Minitest::Spec
@@ -119,7 +131,7 @@ Rescue( handler: X )
119
131
  end
120
132
 
121
133
  it { Memo::Create.( { seq: [], } ).inspect(:seq, :exception_class).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
122
- it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq, :exception_class).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
134
+ it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq, :exception_class).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
123
135
  end
124
136
 
125
137
  =begin
@@ -149,7 +161,7 @@ Rescue( handler: :instance_method )
149
161
  #:rescue-method end
150
162
 
151
163
  it { Memo::Create.( { seq: [], } ).inspect(:seq, :exception_class).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
152
- it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq, :exception_class).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
164
+ it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq, :exception_class).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
153
165
  end
154
166
 
155
167
  =begin
@@ -176,4 +188,63 @@ Rescue(), fast_track: true {}
176
188
  it { Memo::Create.( { seq: [], } ).inspect(:seq).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify]] >} }
177
189
  it { Memo::Create.( { seq: [], update: false } ).inspect(:seq).must_equal %{<Result:false [[:find_model, :update]] >} }
178
190
  end
191
+
192
+ class RescueIDTest < Minitest::Spec
193
+ class Validate
194
+ def self.call(*)
195
+
196
+ end
197
+ end
198
+
199
+ it "assigns ID via {Macro.id_for}" do
200
+ activity = Class.new(Trailblazer::Activity::Railway) do
201
+ step Rescue() {}
202
+ step Rescue(handler: Validate) {}
203
+ step Rescue(handler: :instance_method) {}
204
+ step Rescue() {}, id: "Rescue-1"
205
+ step Rescue(id: "Rescue-2") {}
206
+ # test identical configuration.
207
+ step Rescue() {}
208
+ step Rescue(handler: Validate) {}
209
+ end
210
+
211
+ # assert_equal Trailblazer::Developer::Introspect.find_path(activity, ["Each/EachIDTest::Validate"])[0].id, "Each/EachIDTest::Validate"
212
+ # assert_equal Trailblazer::Developer::Introspect.find_path(activity, ["Each-1"])[0].id, "Each-1"
213
+ # assert_equal Trailblazer::Developer::Introspect.find_path(activity, ["Each/composers_for_each"])[0].id, "Each/composers_for_each"
214
+
215
+ assert_match /Rescue\/\d+/, Trailblazer::Activity::Introspect::Nodes(activity).values[1].id
216
+ assert_match /Rescue\/\d+/, Trailblazer::Activity::Introspect::Nodes(activity).values[2].id
217
+ assert_match /Rescue\/\d+/, Trailblazer::Activity::Introspect::Nodes(activity).values[3].id
218
+ assert_match "Rescue-1", Trailblazer::Activity::Introspect::Nodes(activity).values[4].id
219
+ assert_match "Rescue-2", Trailblazer::Activity::Introspect::Nodes(activity).values[5].id
220
+ assert_match /Rescue\/\d+/, Trailblazer::Activity::Introspect::Nodes(activity).values[6].id
221
+ assert_match /Rescue\/\d+/, Trailblazer::Activity::Introspect::Nodes(activity).values[7].id
222
+ end
223
+ end
224
+
225
+ class ComplianceTest < Minitest::Spec
226
+ it "tracing" do
227
+ activity = Class.new(Trailblazer::Activity::Railway) do
228
+ step Rescue(id: "Rescue/1") {
229
+ step :validate
230
+ }
231
+
232
+ def validate(ctx, validate: false, seq:, **)
233
+ seq << :validate
234
+ raise unless validate
235
+ validate
236
+ end
237
+ end
238
+
239
+ ctx = {validate: false}
240
+
241
+ output, _ = trace activity, ctx
242
+ assert_equal output, %(TOP
243
+ |-- Start.default
244
+ |-- Rescue/1
245
+ | |-- Start.default
246
+ | `-- validate
247
+ `-- End.failure)
248
+ end
249
+ end
179
250
  end
@@ -169,9 +169,9 @@ When raise: return {Railway.fail!}
169
169
  #@ happy days
170
170
  assert_invoke Memo::Create, seq: "[:model, :update, :rehash, :notify]"
171
171
  #@ rehash raises
172
- assert_invoke Memo::Create, rehash_raise: true, seq: "[:model, :update, :rehash, :log_error]",
172
+ assert_invoke Memo::Create, rehash_raise: RuntimeError, seq: "[:model, :update, :rehash, :log_error]",
173
173
  terminus: :failure,
174
- expected_ctx_variables: {exception: "nope!"}
174
+ expected_ctx_variables: {exception: "RuntimeError"}
175
175
  end
176
176
 
177
177
  =begin
@@ -205,7 +205,7 @@ When raise: return {Railway.fail!}, but wire Wrap() to {fail_fast: true}
205
205
  end
206
206
 
207
207
  it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} }
208
- it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >} }
208
+ it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >} }
209
209
  end
210
210
 
211
211
  =begin
@@ -242,7 +242,7 @@ When raise: return {Railway.fail_fast!} and configure Wrap() to {fast_track: t
242
242
  #:fail-fast end
243
243
 
244
244
  it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} }
245
- it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >} }
245
+ it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >} }
246
246
  end
247
247
 
248
248
  =begin
@@ -289,7 +289,7 @@ When raise: return {Railway.fail!} or {Railway.pass!}
289
289
  end
290
290
 
291
291
  it do
292
- result = Memo::Create.( { seq: [], rehash_raise: true } )
292
+ result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } )
293
293
  result.inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >}
294
294
  result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:transaction_failed>}
295
295
  end
@@ -326,7 +326,7 @@ When raise: return {Railway.pass!} and go "successful"
326
326
  end
327
327
 
328
328
  it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} }
329
- it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} }
329
+ it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} }
330
330
  end
331
331
 
332
332
  =begin
@@ -361,7 +361,7 @@ You can return boolean true in wrap.
361
361
  end
362
362
 
363
363
  it "translates true returned form a wrap to a signal with a `success` semantic" do
364
- result = Memo::Create.( { seq: [], rehash_raise: true } )
364
+ result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } )
365
365
  result.inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >}
366
366
  result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
367
367
  end
@@ -399,7 +399,7 @@ You can return boolean false in wrap.
399
399
  end
400
400
 
401
401
  it "translates false returned form a wrap to a signal with a `failure` semantic" do
402
- result = Memo::Create.( { seq: [], rehash_raise: true } )
402
+ result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } )
403
403
  result.inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash, :log_error]] >}
404
404
  result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>}
405
405
  end
@@ -437,7 +437,7 @@ You can return nil in wrap.
437
437
  end
438
438
 
439
439
  it "translates nil returned form a wrap to a signal with a `failure` semantic" do
440
- result = Memo::Create.( { seq: [], rehash_raise: true } )
440
+ result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } )
441
441
  result.inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash, :log_error]] >}
442
442
  result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>}
443
443
  end
@@ -484,7 +484,7 @@ This one is mostly to show how one could wrap steps in a transaction
484
484
  #:transaction end
485
485
 
486
486
  it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} }
487
- it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash, :log_error]] >} }
487
+ it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash, :log_error]] >} }
488
488
  end
489
489
 
490
490
  =begin
@@ -650,9 +650,10 @@ class WrapUnitTest < Minitest::Spec
650
650
  %{#<Trailblazer::Activity::TaskBuilder::Task user_proc=validate>}
651
651
 
652
652
  #@ Patch interface
653
- patched_activity = Trailblazer::Activity::DSL::Linear.Patch(
653
+ patched_activity = Trailblazer::Activity::DSL::Linear::Patch.call(
654
654
  activity,
655
- ["Wrap/WrapUnitTest::HandleUnsafeProcess"] => -> { step mock_validation, replace: :validation, id: :validation }
655
+ ["Wrap/WrapUnitTest::HandleUnsafeProcess"],
656
+ -> { step mock_validation, replace: :validation, id: :validation }
656
657
  )
657
658
 
658
659
  #@ the original activity with Wrap is unchanged.
@@ -668,9 +669,10 @@ class WrapStrategyComplianceTest < Minitest::Spec
668
669
 
669
670
  it do
670
671
  #:patch
671
- upload_with_upsert = Trailblazer::Activity::DSL::Linear.Patch(
672
+ upload_with_upsert = Trailblazer::Activity::DSL::Linear::Patch.call(
672
673
  Song::Activity::Upload,
673
- ["Wrap/MyTransaction"] => -> { step :upsert, replace: :update }
674
+ ["Wrap/MyTransaction"],
675
+ -> { step :upsert, replace: :update }
674
676
  )
675
677
  #:patch end
676
678
  upload_with_upsert.include(T.def_steps(:upsert))
data/test/test_helper.rb CHANGED
@@ -1,31 +1,11 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require "trailblazer/macro"
3
-
4
- require "delegate" # Ruby 2.2
5
2
  require "minitest/autorun"
6
3
 
4
+ require "trailblazer/macro"
7
5
  require "trailblazer/developer"
6
+ require "trailblazer/activity/testing"
8
7
 
9
- module Mock
10
- class Result
11
- def initialize(bool); @bool = bool end
12
- def success?; @bool end
13
- def errors; ["hihi"] end
14
- end
15
- end
16
-
17
- module Test
18
- module ReturnCall
19
- def self.included(includer)
20
- includer._insert :_insert, ReturnResult, {replace: Trailblazer::Operation::Result::Build}, ReturnResult, ""
21
- end
22
- end
23
- ReturnResult = ->(last, input, options) { input }
24
- end
25
-
26
- require "pp"
27
-
28
- # Minitest::Spec::Operation = Trailblazer::Operation
8
+ T = Trailblazer::Activity::Testing
29
9
 
30
10
  Memo = Struct.new(:id, :body) do
31
11
  def self.find(id)
@@ -34,13 +14,10 @@ Memo = Struct.new(:id, :body) do
34
14
  end
35
15
  end
36
16
 
37
- require "trailblazer/activity/testing"
38
- T = Trailblazer::Activity::Testing
39
-
40
17
  module Rehash
41
18
  def rehash(ctx, seq:, rehash_raise: false, **)
42
19
  seq << :rehash
43
- raise "nope!" if rehash_raise
20
+ raise rehash_raise if rehash_raise
44
21
  true
45
22
  end
46
23
  end
@@ -50,26 +27,13 @@ Minitest::Spec.include Trailblazer::Activity::Testing::Assertions
50
27
  Minitest::Spec.class_eval do
51
28
  def trace(activity, ctx)
52
29
  stack, signal, (ctx, _) = Trailblazer::Developer::Trace.invoke(activity, [ctx, {}])
53
- return Trailblazer::Developer::Trace::Present.(stack, node_options: {stack.to_a[0]=>{label: "TOP"}}).gsub(/:\d+/, ""), signal, ctx
54
- end
55
- end
56
30
 
31
+ output = Trailblazer::Developer::Trace::Present.(stack) do |trace_nodes:, **|
32
+ {node_options: {trace_nodes[0] => {label: "TOP"}}}
33
+ end.gsub(/:\d+/, "")
57
34
 
35
+ return output, signal, ctx
36
+ end
37
+ end
58
38
 
59
- # signal, (ctx, _) = Trailblazer::Activity.(Song::Activity::Create,
60
- # params: {title: "Olympia"}, # some random variable.
61
- # "model.class": Hit,
62
- # "model.action": :find_by,
63
- # "model.find_by_key": :title, seq: []
64
- # )
65
-
66
- # #:update-ok
67
- # signal, (ctx, _) = Trailblazer::Activity.(Song::Activity::Update, params: {id: 1}, seq: [])
68
- # ctx[:model] #=> #<Song id=1, ...>
69
- # puts signal #=> #<Trailblazer::Activity::End semantic=:success>
70
- # #:update-ok end
71
-
72
-
73
- # require "trailblazer/core"
74
- # Trailblazer::Core.convert_operation_test("test/docs/model_test.rb")
75
- # Trailblazer::Core.convert_operation_test("test/docs/each_test.rb")
39
+ # Trailblazer::Core.convert_operation_test("test/docs/composable_variable_mapping_test.rb")
@@ -5,8 +5,8 @@ require 'trailblazer/macro/version'
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "trailblazer-macro"
7
7
  spec.version = Trailblazer::Version::Macro::VERSION
8
- spec.authors = ["Nick Sutterer", "Marc Tich"]
9
- spec.email = ["apotonick@gmail.com", "marc@mudsu.com"]
8
+ spec.authors = ["Nick Sutterer"]
9
+ spec.email = ["apotonick@gmail.com"]
10
10
  spec.description = "Macros for Trailblazer's operation"
11
11
  spec.summary = "Macros for Trailblazer's operation: Policy, Wrap, Rescue and more."
12
12
  spec.homepage = "http://trailblazer.to"
@@ -19,10 +19,10 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "minitest"
21
21
  spec.add_development_dependency "rake"
22
- spec.add_development_dependency "trailblazer-developer"
22
+ spec.add_development_dependency "trailblazer-developer", ">= 0.1.0", "< 0.2.0"
23
+ spec.add_dependency "trailblazer-operation", ">= 0.10.1" # TODO: this dependency will be removed. currently needed for tests and for Guard::Result
23
24
 
24
- spec.add_dependency "trailblazer-activity-dsl-linear", ">= 1.1.0", "< 1.2.0"
25
- spec.add_dependency "trailblazer-operation", ">= 0.9.0" # TODO: this dependency will be removed. currently needed for tests?! and for Guard::Result
25
+ spec.add_dependency "trailblazer-activity-dsl-linear", ">= 1.2.0", "< 1.3.0"
26
26
 
27
- spec.required_ruby_version = ">= 2.2.0"
27
+ spec.required_ruby_version = ">= 2.5.0"
28
28
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-macro
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.13
4
+ version: 2.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
- - Marc Tich
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2022-12-19 00:00:00.000000000 Z
11
+ date: 2023-06-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: minitest
@@ -45,60 +44,62 @@ dependencies:
45
44
  requirements:
46
45
  - - ">="
47
46
  - !ruby/object:Gem::Version
48
- version: '0'
47
+ version: 0.1.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 0.2.0
49
51
  type: :development
50
52
  prerelease: false
51
53
  version_requirements: !ruby/object:Gem::Requirement
52
54
  requirements:
53
55
  - - ">="
54
56
  - !ruby/object:Gem::Version
55
- version: '0'
57
+ version: 0.1.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.2.0
56
61
  - !ruby/object:Gem::Dependency
57
- name: trailblazer-activity-dsl-linear
62
+ name: trailblazer-operation
58
63
  requirement: !ruby/object:Gem::Requirement
59
64
  requirements:
60
65
  - - ">="
61
66
  - !ruby/object:Gem::Version
62
- version: 1.1.0
63
- - - "<"
64
- - !ruby/object:Gem::Version
65
- version: 1.2.0
67
+ version: 0.10.1
66
68
  type: :runtime
67
69
  prerelease: false
68
70
  version_requirements: !ruby/object:Gem::Requirement
69
71
  requirements:
70
72
  - - ">="
71
73
  - !ruby/object:Gem::Version
72
- version: 1.1.0
73
- - - "<"
74
- - !ruby/object:Gem::Version
75
- version: 1.2.0
74
+ version: 0.10.1
76
75
  - !ruby/object:Gem::Dependency
77
- name: trailblazer-operation
76
+ name: trailblazer-activity-dsl-linear
78
77
  requirement: !ruby/object:Gem::Requirement
79
78
  requirements:
80
79
  - - ">="
81
80
  - !ruby/object:Gem::Version
82
- version: 0.9.0
81
+ version: 1.2.0
82
+ - - "<"
83
+ - !ruby/object:Gem::Version
84
+ version: 1.3.0
83
85
  type: :runtime
84
86
  prerelease: false
85
87
  version_requirements: !ruby/object:Gem::Requirement
86
88
  requirements:
87
89
  - - ">="
88
90
  - !ruby/object:Gem::Version
89
- version: 0.9.0
91
+ version: 1.2.0
92
+ - - "<"
93
+ - !ruby/object:Gem::Version
94
+ version: 1.3.0
90
95
  description: Macros for Trailblazer's operation
91
96
  email:
92
97
  - apotonick@gmail.com
93
- - marc@mudsu.com
94
98
  executables: []
95
99
  extensions: []
96
100
  extra_rdoc_files: []
97
101
  files:
98
102
  - ".github/workflows/ci.yml"
99
- - ".github/workflows/ci_jruby.yml"
100
- - ".github/workflows/ci_legacy.yml"
101
- - ".github/workflows/ci_truffleruby.yml"
102
103
  - ".gitignore"
103
104
  - CHANGES.md
104
105
  - Gemfile
@@ -143,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
144
  requirements:
144
145
  - - ">="
145
146
  - !ruby/object:Gem::Version
146
- version: 2.2.0
147
+ version: 2.5.0
147
148
  required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  requirements:
149
150
  - - ">="
@@ -1,19 +0,0 @@
1
- ## This file is managed by Terraform.
2
- ## Do not modify this file directly, as it may be overwritten.
3
- ## Please open an issue instead.
4
- name: CI JRuby
5
- on: [push, pull_request]
6
- jobs:
7
- test:
8
- strategy:
9
- fail-fast: false
10
- matrix:
11
- ruby: [jruby, jruby-head]
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v3
15
- - uses: ruby/setup-ruby@v1
16
- with:
17
- ruby-version: ${{ matrix.ruby }}
18
- bundler-cache: true
19
- - run: bundle exec rake
@@ -1,19 +0,0 @@
1
- ## This file is managed by Terraform.
2
- ## Do not modify this file directly, as it may be overwritten.
3
- ## Please open an issue instead.
4
- name: CI with EOL ruby versions
5
- on: [push, pull_request]
6
- jobs:
7
- test:
8
- strategy:
9
- fail-fast: false
10
- matrix:
11
- ruby: [2.5, 2.6]
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v3
15
- - uses: ruby/setup-ruby@v1
16
- with:
17
- ruby-version: ${{ matrix.ruby }}
18
- bundler-cache: true
19
- - run: bundle exec rake
@@ -1,19 +0,0 @@
1
- ## This file is managed by Terraform.
2
- ## Do not modify this file directly, as it may be overwritten.
3
- ## Please open an issue instead.
4
- name: CI TruffleRuby
5
- on: [push, pull_request]
6
- jobs:
7
- test:
8
- strategy:
9
- fail-fast: false
10
- matrix:
11
- ruby: [truffleruby, truffleruby-head]
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v3
15
- - uses: ruby/setup-ruby@v1
16
- with:
17
- ruby-version: ${{ matrix.ruby }}
18
- bundler-cache: true
19
- - run: bundle exec rake