dry-transaction-extra 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/README.md +14 -7
- data/lib/dry/transaction/extra/steps/maybe.rb +7 -3
- data/lib/dry/transaction/extra/version.rb +1 -1
- 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: b418dfe409a43af2be1442c9816531076a476c16aa459b5203b49fb32d840836
|
4
|
+
data.tar.gz: be20845e12107f4e7b7b8b086dbead6b7920a1baf1bce41bd847922807c3e9d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d48878a62c1a65a8202021d7ccbb4a4e7c63cc4bc75e825a9f115c6060b75fefdd53abb2a2412acd869edaf9cb5f659f8a93804cd9d7d1a9fbf98f887cc464a9
|
7
|
+
data.tar.gz: c5fca1261a2e76d32a2b45ca33c0ab0f51cd911c61f8904306ff8437c6896a183d1108e6d6fbc8d26ec0fdb208d947e52707aa401efd6738e4eb1ad153d1d401
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -25,11 +25,18 @@ require "dry-transaction-extra"
|
|
25
25
|
|
26
26
|
Dry::Transaction::Extra defines a few extra steps you can use:
|
27
27
|
|
28
|
-
* [merge]
|
29
|
-
|
28
|
+
* [merge](#merge) -- Merges the output of the step with the input args. Best
|
29
|
+
used with keyword arguments.
|
30
|
+
* [tap](#tap) -- Similar to Ruby `Kernel#tap`, discards the return value of the step
|
30
31
|
and returns the original input. If the step fails, then returns the Failure
|
31
32
|
instead.
|
32
|
-
* [valid]
|
33
|
+
* [valid](#valid) -- Runs a Dry::Schema or Dry::Validation::Contract on the
|
34
|
+
input, and transforms the validation Result to a Result monad.
|
35
|
+
* [use](#use) -- Invokes another transaction (or any other callable), and
|
36
|
+
merges the result.
|
37
|
+
* [maybe](#maybe) -- Optionally invokes another transaction by first
|
38
|
+
attempting to invoke the validator. If the validation fails, it continues to
|
39
|
+
the next step without failing.
|
33
40
|
|
34
41
|
#### `merge`
|
35
42
|
|
@@ -173,8 +180,8 @@ valid ParamsValidator
|
|
173
180
|
|
174
181
|
#### `maybe`
|
175
182
|
|
176
|
-
Maybe combines the [`use`]
|
177
|
-
extension]
|
183
|
+
Maybe combines the [`use`]( #use ) step with the [Validation
|
184
|
+
extension]( #validation ). Before attempting to run the provided transaction, it
|
178
185
|
first runs its defined validator. If that validation passes, then it invokes
|
179
186
|
the transaction. If the validation fails, however, then the transaction
|
180
187
|
continues on, silently ignoring the failure. This is useful in several
|
@@ -227,7 +234,7 @@ class CreateUser
|
|
227
234
|
|
228
235
|
#### Validation
|
229
236
|
|
230
|
-
In addition to the [valid]
|
237
|
+
In addition to the [valid]( #valid ) step adapter, Dry::Transaction::Extra has
|
231
238
|
support for an explicit "pre-flight" validation that runs as the first step.
|
232
239
|
|
233
240
|
```ruby
|
@@ -263,7 +270,7 @@ MyTransaction.new.call(args)
|
|
263
270
|
MyTransaction.call(args)
|
264
271
|
```
|
265
272
|
|
266
|
-
This is particularly useful when invoking transactions via the [`use`]
|
273
|
+
This is particularly useful when invoking transactions via the [`use`]( #use ) and [`maybe`]( #maybe ) steps:
|
267
274
|
|
268
275
|
```
|
269
276
|
use MyTransaction
|
@@ -41,9 +41,13 @@ module Dry
|
|
41
41
|
txn = container[key] if key
|
42
42
|
raise NoValidatorError, txn unless txn.respond_to? :validator
|
43
43
|
|
44
|
-
result = txn.validator.new.call(*args)
|
45
|
-
result.
|
46
|
-
|
44
|
+
result = txn.validator.new.call(*args)
|
45
|
+
if result.failure?
|
46
|
+
# Rails.logger.debug "Skipping #{txn} because of errors: #{result.errors.to_h}"
|
47
|
+
return Success(*args)
|
48
|
+
end
|
49
|
+
|
50
|
+
txn.call(*args)
|
47
51
|
end
|
48
52
|
rescue NoMethodError => e
|
49
53
|
raise e unless e.name == :name
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-transaction-extra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Sadauskas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-monads
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
|
-
rubygems_version: 3.4.
|
131
|
+
rubygems_version: 3.4.10
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Extra steps and functionality for Dry::Transaction
|