dry-transaction 0.14.0 → 0.16.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 +18 -0
- data/LICENSE +1 -1
- data/README.md +5 -12
- data/dry-transaction.gemspec +6 -6
- data/lib/dry/transaction/builder.rb +6 -5
- data/lib/dry/transaction/dsl.rb +3 -2
- data/lib/dry/transaction/instance_methods.rb +10 -8
- data/lib/dry/transaction/operation.rb +2 -4
- data/lib/dry/transaction/operation_resolver.rb +3 -3
- data/lib/dry/transaction/result_matcher.rb +1 -1
- data/lib/dry/transaction/step.rb +9 -8
- data/lib/dry/transaction/step_adapter.rb +1 -1
- data/lib/dry/transaction/step_adapters/around.rb +2 -5
- data/lib/dry/transaction/step_adapters/check.rb +1 -1
- data/lib/dry/transaction/step_adapters/map.rb +1 -1
- data/lib/dry/transaction/step_adapters/raw.rb +3 -3
- data/lib/dry/transaction/step_adapters/tee.rb +1 -1
- data/lib/dry/transaction/step_adapters/try.rb +3 -3
- data/lib/dry/transaction/step_adapters.rb +7 -9
- data/lib/dry/transaction/step_failure.rb +2 -0
- data/lib/dry/transaction/version.rb +1 -1
- data/lib/dry/transaction.rb +3 -0
- metadata +22 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4cd9e9404fa18118f81eda69c2c826bf78d115db2011ffc7aaa61142cbbab26
|
4
|
+
data.tar.gz: e3d1503de5353ab0204f727f71b2189895ff78989ff43478b0f9ab13c3819831
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b11d66011be4757691bd017cb12906c840343b93daa94912bc99fd0d9e0efc8392b501e1333f2bbda0635a1f34e308b74aedbeed95ee62026b5f52d9589e6054
|
7
|
+
data.tar.gz: 18149f9703d95a138f3536cb8b5a1f59ed5007a0ac99d5ade9b56f8e1c01e547afb4bbb7864e0d54d1271e83e67e91c073aff719a80c1f8512fe900c8febc134
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 0.16.0 2024-01-17
|
4
|
+
|
5
|
+
|
6
|
+
### Changed
|
7
|
+
|
8
|
+
- Dependency on dry-matcher bumped to 1.0 (@santiagodoldan in #149)
|
9
|
+
|
10
|
+
[Compare v0.15.0...v0.16.0](https://github.com/dry-rb/dry-transaction/compare/v0.15.0...v0.16.0)
|
11
|
+
|
12
|
+
## 0.15.0 2022-11-16
|
13
|
+
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
- Dependencies were bumped to exclude dry-container (@flash-gordon)
|
18
|
+
|
19
|
+
[Compare v0.14.0...v0.15.0](https://github.com/dry-rb/dry-transaction/compare/v0.14.0...v0.15.0)
|
20
|
+
|
3
21
|
## 0.14.0 2022-10-21
|
4
22
|
|
5
23
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,22 @@
|
|
1
1
|
<!--- this file is synced from dry-rb/template-gem project -->
|
2
|
+
|
2
3
|
[gem]: https://rubygems.org/gems/dry-transaction
|
3
4
|
[actions]: https://github.com/dry-rb/dry-transaction/actions
|
4
|
-
[codacy]: https://www.codacy.com/gh/dry-rb/dry-transaction
|
5
|
-
[chat]: https://dry-rb.zulipchat.com
|
6
|
-
[inchpages]: http://inch-ci.org/github/dry-rb/dry-transaction
|
7
|
-
|
8
|
-
# dry-transaction [][chat]
|
9
5
|
|
10
|
-
[][gem]
|
11
|
-
[][actions]
|
12
|
-
[][codacy]
|
13
|
-
[][codacy]
|
14
|
-
[][inchpages]
|
6
|
+
# dry-transaction [][gem] [][actions]
|
15
7
|
|
16
8
|
## Links
|
17
9
|
|
18
10
|
* [User documentation](https://dry-rb.org/gems/dry-transaction)
|
19
11
|
* [API documentation](http://rubydoc.info/gems/dry-transaction)
|
12
|
+
* [Forum](https://discourse.dry-rb.org)
|
20
13
|
|
21
14
|
## Supported Ruby versions
|
22
15
|
|
23
16
|
This library officially supports the following Ruby versions:
|
24
17
|
|
25
|
-
* MRI `>=
|
26
|
-
* jruby `>= 9.
|
18
|
+
* MRI `>= 3.0`
|
19
|
+
* jruby `>= 9.4` (not tested on CI)
|
27
20
|
|
28
21
|
## License
|
29
22
|
|
data/dry-transaction.gemspec
CHANGED
@@ -22,16 +22,16 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
-
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-transaction/blob/
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-transaction/blob/main/CHANGELOG.md"
|
26
26
|
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-transaction"
|
27
27
|
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-transaction/issues"
|
28
28
|
|
29
|
-
spec.required_ruby_version = ">=
|
29
|
+
spec.required_ruby_version = ">= 3.0"
|
30
30
|
|
31
31
|
# to update dependencies edit project.yml
|
32
|
-
spec.add_runtime_dependency "dry-
|
33
|
-
spec.add_runtime_dependency "dry-events", "
|
34
|
-
spec.add_runtime_dependency "dry-matcher", "
|
35
|
-
spec.add_runtime_dependency "dry-monads", "
|
32
|
+
spec.add_runtime_dependency "dry-core", "~> 1.0"
|
33
|
+
spec.add_runtime_dependency "dry-events", "~> 1.0"
|
34
|
+
spec.add_runtime_dependency "dry-matcher", "~> 1.0"
|
35
|
+
spec.add_runtime_dependency "dry-monads", "~> 1.6"
|
36
36
|
|
37
37
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "dry/transaction/step"
|
4
|
+
require "dry/transaction/dsl"
|
5
|
+
require "dry/transaction/instance_methods"
|
6
|
+
require "dry/transaction/operation_resolver"
|
7
7
|
|
8
8
|
module Dry
|
9
9
|
module Transaction
|
@@ -11,7 +11,8 @@ module Dry
|
|
11
11
|
attr_reader :dsl_mod
|
12
12
|
attr_reader :resolver_mod
|
13
13
|
|
14
|
-
def initialize(container: nil
|
14
|
+
def initialize(step_adapters:, container: nil)
|
15
|
+
super()
|
15
16
|
@dsl_mod = DSL.new(step_adapters: step_adapters)
|
16
17
|
@resolver_mod = OperationResolver.new(container)
|
17
18
|
end
|
data/lib/dry/transaction/dsl.rb
CHANGED
@@ -4,6 +4,7 @@ module Dry
|
|
4
4
|
module Transaction
|
5
5
|
class DSL < Module
|
6
6
|
def initialize(step_adapters:)
|
7
|
+
super()
|
7
8
|
@step_adapters = step_adapters
|
8
9
|
|
9
10
|
define_steps
|
@@ -11,7 +12,7 @@ module Dry
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def inspect
|
14
|
-
"Dry::Transaction::DSL(#{@step_adapters.keys.sort.join(
|
15
|
+
"Dry::Transaction::DSL(#{@step_adapters.keys.sort.join(", ")})"
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
@@ -35,7 +36,7 @@ module Dry
|
|
35
36
|
name: step_name,
|
36
37
|
operation_name: operation_name,
|
37
38
|
operation: nil, # operations are resolved only when transactions are instantiated
|
38
|
-
options: options
|
39
|
+
options: options
|
39
40
|
)
|
40
41
|
end
|
41
42
|
end
|
@@ -1,20 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require 'dry/transaction/stack'
|
3
|
+
require "dry/transaction/result_matcher"
|
4
|
+
require "dry/transaction/stack"
|
6
5
|
|
7
6
|
module Dry
|
8
7
|
module Transaction
|
9
8
|
module InstanceMethods
|
10
|
-
include Dry::Monads
|
9
|
+
include Dry::Monads[:result]
|
11
10
|
|
12
11
|
attr_reader :steps
|
13
12
|
attr_reader :operations
|
14
13
|
attr_reader :listeners
|
15
14
|
attr_reader :stack
|
16
15
|
|
17
|
-
def initialize(steps:
|
16
|
+
def initialize(steps: self.class.steps, listeners: nil, **operations)
|
18
17
|
@steps = steps.map { |step|
|
19
18
|
operation = resolve_operation(step, **operations)
|
20
19
|
step.with(operation: operation)
|
@@ -78,7 +77,10 @@ module Dry
|
|
78
77
|
super unless step
|
79
78
|
|
80
79
|
operation = operations[step.name]
|
81
|
-
|
80
|
+
unless operation
|
81
|
+
raise NotImplementedError,
|
82
|
+
"no operation +#{step.operation_name}+ defined for step +#{step.name}+"
|
83
|
+
end
|
82
84
|
|
83
85
|
operation.(*args, &block)
|
84
86
|
end
|
@@ -91,9 +93,9 @@ module Dry
|
|
91
93
|
elsif operations[step.name].respond_to?(:call)
|
92
94
|
operations[step.name]
|
93
95
|
elsif operations[step.name]
|
94
|
-
raise InvalidStepError
|
96
|
+
raise InvalidStepError, step.name
|
95
97
|
else
|
96
|
-
raise MissingStepError
|
98
|
+
raise MissingStepError, step.name
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
@@ -1,15 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require 'dry/matcher'
|
5
|
-
require 'dry/matcher/result_matcher'
|
3
|
+
require "dry/matcher/result_matcher"
|
6
4
|
|
7
5
|
module Dry
|
8
6
|
module Transaction
|
9
7
|
module Operation
|
10
8
|
def self.included(klass)
|
11
9
|
klass.class_eval do
|
12
|
-
include Dry::Monads
|
10
|
+
include Dry::Monads[:result]
|
13
11
|
include Dry::Matcher.for(:call, with: Dry::Matcher::ResultMatcher)
|
14
12
|
end
|
15
13
|
end
|
@@ -6,9 +6,9 @@ module Dry
|
|
6
6
|
def initialize(container)
|
7
7
|
module_exec(container) do |ops_container|
|
8
8
|
define_method :initialize do |**kwargs|
|
9
|
-
operation_kwargs = self.class.steps.select(&:operation_name).
|
9
|
+
operation_kwargs = self.class.steps.select(&:operation_name).to_h { |step|
|
10
10
|
operation = kwargs.fetch(step.name) {
|
11
|
-
if ops_container
|
11
|
+
if ops_container&.key?(step.operation_name)
|
12
12
|
ops_container[step.operation_name]
|
13
13
|
else
|
14
14
|
nil
|
@@ -16,7 +16,7 @@ module Dry
|
|
16
16
|
}
|
17
17
|
|
18
18
|
[step.name, operation]
|
19
|
-
}
|
19
|
+
}
|
20
20
|
|
21
21
|
super(**kwargs, **operation_kwargs)
|
22
22
|
end
|
data/lib/dry/transaction/step.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require 'dry/transaction/step_failure'
|
6
|
-
require 'dry/transaction/step_adapter'
|
3
|
+
require "dry/transaction/step_failure"
|
4
|
+
require "dry/transaction/step_adapter"
|
7
5
|
|
8
6
|
module Dry
|
9
7
|
module Transaction
|
@@ -13,7 +11,7 @@ module Dry
|
|
13
11
|
RETURN = -> x { x }
|
14
12
|
|
15
13
|
include Dry::Events::Publisher[name || object_id]
|
16
|
-
include Dry::Monads
|
14
|
+
include Dry::Monads[:result]
|
17
15
|
|
18
16
|
register_event(:step)
|
19
17
|
register_event(:step_succeeded)
|
@@ -24,12 +22,15 @@ module Dry
|
|
24
22
|
attr_reader :operation_name
|
25
23
|
attr_reader :call_args
|
26
24
|
|
27
|
-
|
28
|
-
|
25
|
+
# rubocop:disable Metrics/ParameterLists
|
26
|
+
def initialize(adapter:, name:, operation_name:, options:, operation: nil, call_args: [])
|
27
|
+
@adapter = StepAdapter[adapter, operation,
|
28
|
+
{**options, step_name: name, operation_name: operation_name}]
|
29
29
|
@name = name
|
30
30
|
@operation_name = operation_name
|
31
31
|
@call_args = call_args
|
32
32
|
end
|
33
|
+
# rubocop:enable Metrics/ParameterLists
|
33
34
|
|
34
35
|
def with(operation: UNDEFINED, call_args: UNDEFINED)
|
35
36
|
return self if operation == UNDEFINED && call_args == UNDEFINED
|
@@ -43,7 +44,7 @@ module Dry
|
|
43
44
|
operation_name: operation_name,
|
44
45
|
operation: new_operation,
|
45
46
|
options: adapter.options,
|
46
|
-
call_args: new_call_args
|
47
|
+
call_args: new_call_args
|
47
48
|
)
|
48
49
|
end
|
49
50
|
|
@@ -1,20 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'dry/monads/result'
|
4
|
-
require 'dry/transaction/errors'
|
5
|
-
|
6
3
|
module Dry
|
7
4
|
module Transaction
|
8
5
|
class StepAdapters
|
9
6
|
# @api private
|
10
7
|
class Around
|
11
|
-
include Dry::Monads
|
8
|
+
include Dry::Monads[:result]
|
12
9
|
|
13
10
|
def call(operation, options, args, &block)
|
14
11
|
result = operation.(*args, &block)
|
15
12
|
|
16
13
|
unless result.is_a?(Dry::Monads::Result)
|
17
|
-
raise InvalidResultError
|
14
|
+
raise InvalidResultError, options[:step_name]
|
18
15
|
end
|
19
16
|
|
20
17
|
result
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "dry/monads/result"
|
4
|
+
require "dry/transaction/errors"
|
5
|
+
require "dry/transaction/step_adapters/around"
|
6
6
|
|
7
7
|
module Dry
|
8
8
|
module Transaction
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dry/transaction/errors"
|
4
4
|
|
5
5
|
module Dry
|
6
6
|
module Transaction
|
7
7
|
class StepAdapters
|
8
8
|
# @api private
|
9
9
|
class Try
|
10
|
-
include Dry::Monads
|
10
|
+
include Dry::Monads[:result]
|
11
11
|
|
12
12
|
def call(operation, options, args)
|
13
13
|
unless options[:catch]
|
14
|
-
raise MissingCatchListError
|
14
|
+
raise MissingCatchListError, options[:step_name]
|
15
15
|
end
|
16
16
|
|
17
17
|
result = operation.(*args)
|
@@ -1,18 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'dry-container'
|
4
|
-
|
5
3
|
module Dry
|
6
4
|
module Transaction
|
7
5
|
class StepAdapters
|
8
|
-
extend Dry::Container::Mixin
|
6
|
+
extend Dry::Core::Container::Mixin
|
9
7
|
end
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
11
|
+
require "dry/transaction/step_adapters/check"
|
12
|
+
require "dry/transaction/step_adapters/map"
|
13
|
+
require "dry/transaction/step_adapters/raw"
|
14
|
+
require "dry/transaction/step_adapters/tee"
|
15
|
+
require "dry/transaction/step_adapters/try"
|
16
|
+
require "dry/transaction/step_adapters/around"
|
@@ -10,12 +10,14 @@ module Dry
|
|
10
10
|
|
11
11
|
# @api private
|
12
12
|
def self.call(step, value)
|
13
|
+
# rubocop:disable Style/CaseEquality
|
13
14
|
if self === value
|
14
15
|
value
|
15
16
|
else
|
16
17
|
yield
|
17
18
|
new(step, value)
|
18
19
|
end
|
20
|
+
# rubocop:enable Style/CaseEquality
|
19
21
|
end
|
20
22
|
|
21
23
|
def initialize(step, value)
|
data/lib/dry/transaction.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-transaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Riley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: dry-
|
14
|
+
name: dry-core
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dry-events
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: dry-matcher
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '1.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '1.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: dry-monads
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '1.6'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '1.6'
|
69
69
|
description: Business Transaction Flow DSL
|
70
70
|
email:
|
71
71
|
- tim@icelab.com.au
|
@@ -104,7 +104,7 @@ licenses:
|
|
104
104
|
- MIT
|
105
105
|
metadata:
|
106
106
|
allowed_push_host: https://rubygems.org
|
107
|
-
changelog_uri: https://github.com/dry-rb/dry-transaction/blob/
|
107
|
+
changelog_uri: https://github.com/dry-rb/dry-transaction/blob/main/CHANGELOG.md
|
108
108
|
source_code_uri: https://github.com/dry-rb/dry-transaction
|
109
109
|
bug_tracker_uri: https://github.com/dry-rb/dry-transaction/issues
|
110
110
|
post_install_message:
|
@@ -115,14 +115,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
118
|
+
version: '3.0'
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
|
-
rubygems_version: 3.
|
125
|
+
rubygems_version: 3.3.26
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Business Transaction Flow DSL
|