hubbado-trailblazer 1.1.0 → 1.3.0
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/CHANGELOG.md +16 -0
- data/README.md +7 -1
- data/hubbado-trailblazer.gemspec +1 -1
- data/lib/hubbado/trailblazer/macro/{prepopulate_contract.rb → deserialize_contract_params.rb} +3 -3
- data/lib/hubbado/trailblazer/rspec_matchers/have_deserialized_params.rb +19 -0
- data/lib/hubbado/trailblazer/run_operation.rb +31 -1
- data/lib/hubbado-trailblazer.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 236eb296eba6cbbfe62d8501dbb1a9984a3f286de4d3f1e61ec494713cc6fcc8
|
|
4
|
+
data.tar.gz: ae8c2c869e63aba3503902e6d1b229d414f1a33d78378d20c1dcca9b48a7da2d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4fff16b5816e5ece06716e01e9bf44f6fa6fc20d2db1abff64af8d526824ed1d47668bfbc6d3912e50697151e8582647d219973c86ecbcef53bb5a954a5f82e4
|
|
7
|
+
data.tar.gz: 415fcc8495e1e3c9c099b502cf8dc4ed0a14dab9fc4dc66a4ff452f5c37eb76bcc558dc0d93a9449009f39df54c859031103b29f7f8f63d92a2fc8ed79ca94cf
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.3.0] - 2025-11-26
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Support for `result.not_found { ... }` block to handle operations with `:not_found` terminus.
|
|
13
|
+
|
|
14
|
+
## [1.2.0] - 2025-07-19
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- rspec matcher `:have_deserialized_params` for DeserializeContractParams
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- PrepopulateContract is renamed to DeserializeContractParams
|
|
23
|
+
|
|
8
24
|
## [1.1.0] - 2025-07-08
|
|
9
25
|
|
|
10
26
|
### Changed
|
data/README.md
CHANGED
|
@@ -137,10 +137,16 @@ Prepopulate Reform contracts with values from params without validation:
|
|
|
137
137
|
class Users::Edit < Trailblazer::Operation
|
|
138
138
|
step Model(User, :find)
|
|
139
139
|
step Contract::Build(constant: Users::UpdateContract)
|
|
140
|
-
step Hubbado::Trailblazer::Macro::
|
|
140
|
+
step Hubbado::Trailblazer::Macro::DeserializeContractParams()
|
|
141
141
|
end
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
+
In addition, there is a RSpec matcher `have_deserialized_params` for this macro and
|
|
145
|
+
has to be required manually:
|
|
146
|
+
```ruby
|
|
147
|
+
require 'hubbado/trailblazer/rspec_matchers/have_deserialized_params'
|
|
148
|
+
```
|
|
149
|
+
|
|
144
150
|
## Operation Tracing
|
|
145
151
|
|
|
146
152
|
Debug operation execution by setting the `TRACE_OPERATION` environment variable:
|
data/hubbado-trailblazer.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "hubbado-trailblazer"
|
|
3
|
-
s.version = "1.
|
|
3
|
+
s.version = "1.3.0"
|
|
4
4
|
s.summary = "Enhanced Trailblazer operation utilities for Ruby applications with improved error handling, operation execution patterns, and ActiveRecord integration."
|
|
5
5
|
|
|
6
6
|
s.authors = ["Hubbado Devs"]
|
data/lib/hubbado/trailblazer/macro/{prepopulate_contract.rb → deserialize_contract_params.rb}
RENAMED
|
@@ -7,9 +7,9 @@ module Hubbado
|
|
|
7
7
|
# For example, a contract, for a not yet saved assignment, might have
|
|
8
8
|
# timesheet approvers that depend on the client company ID in the
|
|
9
9
|
# contract
|
|
10
|
-
def self.
|
|
10
|
+
def self.DeserializeContractParams(key: nil)
|
|
11
11
|
task = ->((ctx, flow_options), _) do
|
|
12
|
-
ctx[:
|
|
12
|
+
ctx[:deserialized_params] = key || true
|
|
13
13
|
|
|
14
14
|
params = key ? ctx[:params][key] : ctx[:params]
|
|
15
15
|
|
|
@@ -20,7 +20,7 @@ module Hubbado
|
|
|
20
20
|
[::Trailblazer::Activity::Right, [ctx, flow_options]]
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
{ task: task, id: "
|
|
23
|
+
{ task: task, id: "DeserializeContractParams" }
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Hubbado
|
|
2
|
+
module Trailblazer
|
|
3
|
+
module RspecMatchers
|
|
4
|
+
module DeserializeContractParams
|
|
5
|
+
extend RSpec::Matchers::DSL
|
|
6
|
+
|
|
7
|
+
matcher :have_deserialized_params do |key: nil|
|
|
8
|
+
match(notify_expectation_failures: true) do |ctx|
|
|
9
|
+
expect(ctx[:deserialized_params]).to eq(key || true)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
RSpec.configure do |rspec|
|
|
14
|
+
rspec.include self, type: :operation
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -16,6 +16,10 @@ module Hubbado
|
|
|
16
16
|
# result.raise_policy_failed
|
|
17
17
|
# end
|
|
18
18
|
#
|
|
19
|
+
# result.not_found do |ctx|
|
|
20
|
+
# ...
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
19
23
|
# result.validation_failed do |ctx|
|
|
20
24
|
# ...
|
|
21
25
|
# end
|
|
@@ -34,6 +38,9 @@ module Hubbado
|
|
|
34
38
|
# If there is a policy failure and you have not implemented
|
|
35
39
|
# `result.policy_failed` then an exception will be raised.
|
|
36
40
|
#
|
|
41
|
+
# If the operation has not_found terminus and you have not
|
|
42
|
+
# implemented `result.not_found` then ActiveRecord::RecordNotFound will be raised.
|
|
43
|
+
#
|
|
37
44
|
# If the operation fails (due to non-policy error) and you have not
|
|
38
45
|
# implemented `result.otherwise` then an exception will be raised.
|
|
39
46
|
#
|
|
@@ -87,7 +94,9 @@ module Hubbado
|
|
|
87
94
|
|
|
88
95
|
if ctx['result.policy.default']&.failure?
|
|
89
96
|
result.raise_policy_failed unless result.policy_failed_executed?
|
|
90
|
-
elsif
|
|
97
|
+
elsif !result.not_found_executed? && ctx.terminus.to_h[:semantic] == :not_found
|
|
98
|
+
result.raise_not_found
|
|
99
|
+
elsif ctx.failure? && !result.validation_failed_executed? && !result.not_found_executed? && !result.otherwise_executed?
|
|
91
100
|
result.raise_operation_failed
|
|
92
101
|
end
|
|
93
102
|
|
|
@@ -159,6 +168,16 @@ module Hubbado
|
|
|
159
168
|
@returned
|
|
160
169
|
end
|
|
161
170
|
|
|
171
|
+
def not_found
|
|
172
|
+
return unless ctx.terminus.to_h[:semantic] == :not_found
|
|
173
|
+
|
|
174
|
+
@not_found_executed = true
|
|
175
|
+
@returned = yield(ctx)
|
|
176
|
+
|
|
177
|
+
logger.send(log_level, "Not found block executed for operation #{operation}")
|
|
178
|
+
@returned
|
|
179
|
+
end
|
|
180
|
+
|
|
162
181
|
def otherwise
|
|
163
182
|
return if executed?
|
|
164
183
|
|
|
@@ -169,6 +188,12 @@ module Hubbado
|
|
|
169
188
|
@returned
|
|
170
189
|
end
|
|
171
190
|
|
|
191
|
+
def raise_not_found
|
|
192
|
+
msg = "Record for operation #{operation.name} not found"
|
|
193
|
+
|
|
194
|
+
raise ActiveRecord::RecordNotFound, msg
|
|
195
|
+
end
|
|
196
|
+
|
|
172
197
|
def raise_operation_failed
|
|
173
198
|
msg = "Operation #{operation.name} failed"
|
|
174
199
|
|
|
@@ -203,6 +228,10 @@ module Hubbado
|
|
|
203
228
|
!!@validation_failed_executed
|
|
204
229
|
end
|
|
205
230
|
|
|
231
|
+
def not_found_executed?
|
|
232
|
+
!!@not_found_executed
|
|
233
|
+
end
|
|
234
|
+
|
|
206
235
|
def otherwise_executed?
|
|
207
236
|
!!@otherwise_executed
|
|
208
237
|
end
|
|
@@ -211,6 +240,7 @@ module Hubbado
|
|
|
211
240
|
success_executed? ||
|
|
212
241
|
policy_failed_executed? ||
|
|
213
242
|
validation_failed_executed? ||
|
|
243
|
+
not_found_executed? ||
|
|
214
244
|
otherwise_executed?
|
|
215
245
|
end
|
|
216
246
|
|
data/lib/hubbado-trailblazer.rb
CHANGED
|
@@ -11,4 +11,4 @@ require 'hubbado/trailblazer/trace_operation'
|
|
|
11
11
|
|
|
12
12
|
require 'hubbado/trailblazer/macro/decorate_model'
|
|
13
13
|
require 'hubbado/trailblazer/macro/policy'
|
|
14
|
-
require 'hubbado/trailblazer/macro/
|
|
14
|
+
require 'hubbado/trailblazer/macro/deserialize_contract_params'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hubbado-trailblazer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hubbado Devs
|
|
@@ -191,8 +191,9 @@ files:
|
|
|
191
191
|
- lib/hubbado/trailblazer.rb
|
|
192
192
|
- lib/hubbado/trailblazer/errors.rb
|
|
193
193
|
- lib/hubbado/trailblazer/macro/decorate_model.rb
|
|
194
|
+
- lib/hubbado/trailblazer/macro/deserialize_contract_params.rb
|
|
194
195
|
- lib/hubbado/trailblazer/macro/policy.rb
|
|
195
|
-
- lib/hubbado/trailblazer/
|
|
196
|
+
- lib/hubbado/trailblazer/rspec_matchers/have_deserialized_params.rb
|
|
196
197
|
- lib/hubbado/trailblazer/run_operation.rb
|
|
197
198
|
- lib/hubbado/trailblazer/trace_operation.rb
|
|
198
199
|
- lib/hubbado/trailblazer/transaction.rb
|
|
@@ -216,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
216
217
|
- !ruby/object:Gem::Version
|
|
217
218
|
version: '0'
|
|
218
219
|
requirements: []
|
|
219
|
-
rubygems_version: 3.
|
|
220
|
+
rubygems_version: 3.7.2
|
|
220
221
|
specification_version: 4
|
|
221
222
|
summary: Enhanced Trailblazer operation utilities for Ruby applications with improved
|
|
222
223
|
error handling, operation execution patterns, and ActiveRecord integration.
|