trailblazer-macro 2.1.6 → 2.1.7

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: d789d88096949c41a15147feed363efab5c86e586b4f76c819e12f6e8f2d4a70
4
- data.tar.gz: fbe7775b4330bc7b607058da66c896fe461e73b1337e747c23eb87acb04b8d30
3
+ metadata.gz: 2b94581daf3c1a0afeea2d8a3d9f470393b15fbfe57fe01dc29c5d1f247beb7c
4
+ data.tar.gz: dff368470d21d9fb0f9522bf610ef1e62b51eebf59f9c41f371298d12d11b8e5
5
5
  SHA512:
6
- metadata.gz: df7f0de0c1107ea8c9b3803e8343907c0deb78e943ac2298a114db9fedb6de88252f5055a247b516fa3c80a2432f52913fd6d84ceb189779b58c87da6204a20f
7
- data.tar.gz: a1e7a11851d02b26badfbff8aa6932810bc2e32ae3d1f4ce5fd73f2bf26284bff62a88b1fd27d29f5b82a7962e61fd0655b97f483483ff6df5cffdb3326f51e0
6
+ metadata.gz: 0a2547701dec5fd643a229313dfeab1d047b1b469208ba54c950cf6f496ef07aa950e6674fb96221fea898dcaff8329f2f3d2ff1f9bec7fa0b758599a96e6329
7
+ data.tar.gz: a0fb745ffb5a9a313764a08972f5271f66e2f07c097759bd5cccb0521b1f80cf72eadaf3c71ae1dc5abdc8bd311abf0aabf6aed4dbea728328a9c590249d9e24
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 2.1.7
2
+
3
+ * Improve `Nested()` warning message.
4
+ * Fix exception in `Rescue()` macro when it's handler is a `Module`.
5
+
1
6
  # 2.1.6
2
7
 
3
8
  * Allow connecting ends of the dynamically selected activity for `Nested()` using `:auto_wire`.
@@ -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
- warn %{[Trailblazer] Using the `Nested()` macro with operations and activities is deprecated. Replace `Nested(Create)` with `Subprocess(Create)`.}
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 nutting about this.
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)"
@@ -1,7 +1,7 @@
1
1
  module Trailblazer
2
2
  module Version
3
3
  module Macro
4
- VERSION = "2.1.6"
4
+ VERSION = "2.1.7"
5
5
  end
6
6
  end
7
7
  end
@@ -16,7 +16,7 @@ class DocsModelTest < Minitest::Spec
16
16
 
17
17
  #:op
18
18
  class Create < Trailblazer::Operation
19
- step Model( Song, :new )
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
@@ -66,7 +66,7 @@ plain Rescue()
66
66
  =begin
67
67
  Rescue( handler: X )
68
68
  =end
69
- class RescueWithHandlerTest < Minitest::Spec
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 RescueWithHandlerTest < Minitest::Spec
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.6
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-03-11 00:00:00.000000000 Z
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.2.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.'