trailblazer-macro 2.1.6 → 2.1.7
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 +4 -4
- data/CHANGES.md +5 -0
- data/lib/trailblazer/macro/nested.rb +5 -1
- data/lib/trailblazer/macro/rescue.rb +2 -5
- data/lib/trailblazer/macro/version.rb +1 -1
- data/test/docs/model_test.rb +15 -1
- data/test/docs/rescue_test.rb +27 -2
- data/test/operation/nested_test.rb +11 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b94581daf3c1a0afeea2d8a3d9f470393b15fbfe57fe01dc29c5d1f247beb7c
|
4
|
+
data.tar.gz: dff368470d21d9fb0f9522bf610ef1e62b51eebf59f9c41f371298d12d11b8e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a2547701dec5fd643a229313dfeab1d047b1b469208ba54c950cf6f496ef07aa950e6674fb96221fea898dcaff8329f2f3d2ff1f9bec7fa0b758599a96e6329
|
7
|
+
data.tar.gz: a0fb745ffb5a9a313764a08972f5271f66e2f07c097759bd5cccb0521b1f80cf72eadaf3c71ae1dc5abdc8bd311abf0aabf6aed4dbea728328a9c590249d9e24
|
data/CHANGES.md
CHANGED
@@ -4,7 +4,11 @@ module Trailblazer
|
|
4
4
|
# {Nested} macro.
|
5
5
|
def self.Nested(callable, id: "Nested(#{callable})", auto_wire: [])
|
6
6
|
if callable.is_a?(Class) && callable < Nested.operation_class
|
7
|
-
|
7
|
+
caller_location = caller_locations(2, 1)[0]
|
8
|
+
warn "[Trailblazer]#{caller_location.absolute_path}: " \
|
9
|
+
"Using the `Nested()` macro with operations and activities is deprecated. " \
|
10
|
+
"Replace `Nested(#{callable})` with `Subprocess(#{callable})`."
|
11
|
+
|
8
12
|
return Nested.operation_class.Subprocess(callable)
|
9
13
|
end
|
10
14
|
|
@@ -28,11 +28,8 @@ module Trailblazer
|
|
28
28
|
# TODO: remove me in 2.2.
|
29
29
|
module Rescue
|
30
30
|
def self.deprecate_positional_handler_signature(handler)
|
31
|
-
return handler if handler.is_a?(Symbol) # can't do
|
32
|
-
|
33
|
-
arity = handler.is_a?(Class) ? handler.method(:call).arity : handler.arity
|
34
|
-
|
35
|
-
return handler if arity != 2 # means (exception, (ctx, flow_options), *, &block), "new style"
|
31
|
+
return handler if handler.is_a?(Symbol) # can't do nothing about this.
|
32
|
+
return handler if handler.method(:call).arity != 2 # means (exception, (ctx, flow_options), *, &block), "new style"
|
36
33
|
|
37
34
|
->(exception, (ctx, flow_options), **circuit_options, &block) do
|
38
35
|
warn "[Trailblazer] Rescue handlers have a new signature: (exception, *, &block)"
|
data/test/docs/model_test.rb
CHANGED
@@ -16,7 +16,7 @@ class DocsModelTest < Minitest::Spec
|
|
16
16
|
|
17
17
|
#:op
|
18
18
|
class Create < Trailblazer::Operation
|
19
|
-
step Model(
|
19
|
+
step Model(Song, :new)
|
20
20
|
# ..
|
21
21
|
end
|
22
22
|
#:op end
|
@@ -121,4 +121,18 @@ class DocsModelTest < Minitest::Spec
|
|
121
121
|
result.success?.must_equal true
|
122
122
|
result[:model].inspect.must_equal %{#<struct DocsModelTest::Song id=100, title=nil>}
|
123
123
|
end
|
124
|
+
|
125
|
+
it "allows injecting {:model.class} and friends" do
|
126
|
+
class Hit < Song
|
127
|
+
end
|
128
|
+
|
129
|
+
result = Create.(params: {}, :"model.class" => Hit)
|
130
|
+
|
131
|
+
result[:model].inspect.must_equal %{#<struct DocsModelTest::Hit id=nil, title=nil>}
|
132
|
+
|
133
|
+
# inject all variables
|
134
|
+
result = Create.(params: {title: "Olympia"}, "model.class": Hit, "model.action": :find_by, "model.find_by_key": :title)
|
135
|
+
|
136
|
+
result[:model].inspect.must_equal %{#<struct DocsModelTest::Hit id=2, title="Olympia">}
|
137
|
+
end
|
124
138
|
end
|
data/test/docs/rescue_test.rb
CHANGED
@@ -66,7 +66,7 @@ plain Rescue()
|
|
66
66
|
=begin
|
67
67
|
Rescue( handler: X )
|
68
68
|
=end
|
69
|
-
class
|
69
|
+
class RescueWithClassHandlerTest < Minitest::Spec
|
70
70
|
Memo = Class.new
|
71
71
|
|
72
72
|
#:rescue-handler
|
@@ -97,10 +97,35 @@ Rescue( handler: X )
|
|
97
97
|
it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq, :exception_class).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
|
98
98
|
end
|
99
99
|
|
100
|
+
class RescueWithModuleHandlerTest < Minitest::Spec
|
101
|
+
Memo = Class.new
|
102
|
+
|
103
|
+
module MyHandler
|
104
|
+
def self.call(exception, (ctx), *)
|
105
|
+
ctx[:exception_class] = exception.class
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class Memo::Create < Trailblazer::Operation
|
110
|
+
step :find_model
|
111
|
+
step Rescue( RuntimeError, handler: MyHandler ) {
|
112
|
+
step :update
|
113
|
+
step :rehash
|
114
|
+
}
|
115
|
+
step :notify
|
116
|
+
fail :log_error
|
117
|
+
include T.def_steps(:find_model, :update, :notify, :log_error)
|
118
|
+
include Rehash
|
119
|
+
end
|
120
|
+
|
121
|
+
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] >} }
|
123
|
+
end
|
124
|
+
|
100
125
|
=begin
|
101
126
|
Rescue( handler: :instance_method )
|
102
127
|
=end
|
103
|
-
class
|
128
|
+
class RescueWithMethodHandlerTest < Minitest::Spec
|
104
129
|
Memo = Class.new
|
105
130
|
|
106
131
|
#:rescue-method
|
@@ -62,4 +62,15 @@ class NestedTest < Minitest::Spec
|
|
62
62
|
|
63
63
|
exception.inspect.must_match 'No `db_error` output found'
|
64
64
|
end
|
65
|
+
|
66
|
+
it "shows warning if `Nested()` is being used instead of `Subprocess()` for static activities" do
|
67
|
+
_, warnings = capture_io do
|
68
|
+
Class.new(Trailblazer::Operation) do
|
69
|
+
step Nested(SignUp)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
warnings.must_equal %Q{[Trailblazer]#{__FILE__}: Using the `Nested()` macro with operations and activities is deprecated. Replace `Nested(NestedTest::SignUp)` with `Subprocess(NestedTest::SignUp)`.
|
74
|
+
}
|
75
|
+
end
|
65
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-macro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-11-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
188
|
- !ruby/object:Gem::Version
|
189
189
|
version: '0'
|
190
190
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
191
|
+
rubygems_version: 3.0.8
|
192
192
|
signing_key:
|
193
193
|
specification_version: 4
|
194
194
|
summary: 'Macros for Trailblazer''s operation: Policy, Wrap, Rescue and more.'
|