dry-transaction 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -3
- data/lib/dry/transaction.rb +3 -1
- data/lib/dry/transaction/dsl.rb +5 -2
- data/lib/dry/transaction/result_matcher.rb +18 -26
- data/lib/dry/transaction/sequence.rb +16 -8
- data/lib/dry/transaction/step_failure.rb +6 -17
- data/lib/dry/transaction/version.rb +1 -1
- data/spec/examples.txt +59 -40
- data/spec/integration/custom_matcher_spec.rb +53 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/unit/step_adapters/map_spec.rb +23 -0
- data/spec/unit/step_adapters/raw_spec.rb +52 -0
- data/spec/unit/step_adapters/tee_spec.rb +23 -0
- metadata +23 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 469bb10618cdbe431bbeace9d17e4865551af4ea
|
4
|
+
data.tar.gz: 876b92d26de8ddf5c97aedb1e01f1228c4faa435
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c63eb2b015d1c503e72deeca01b7a7fd4af28ad6b22d38c523d2c6d85babdb076001935ced8a69ecc68ee1d48a590bb3e9b4a28776e1b7fb14c983c6e4826193
|
7
|
+
data.tar.gz: eba9fba94389262aac0b0a342fc3a36203c84160b54bd664f8952660be4772a58f83f32e1f66cf07d393ac15d6b1a1dcd7631e0ad973d2eb0c62b866acf586e7
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dry-transaction (0.
|
4
|
+
dry-transaction (0.8.0)
|
5
5
|
dry-container (>= 0.2.8)
|
6
|
-
dry-
|
6
|
+
dry-matcher (>= 0.5.0)
|
7
|
+
dry-monads (>= 0.0.1)
|
7
8
|
wisper (>= 1.6.0)
|
8
9
|
|
9
10
|
GEM
|
@@ -21,7 +22,8 @@ GEM
|
|
21
22
|
dry-container (0.3.1)
|
22
23
|
concurrent-ruby (~> 1.0)
|
23
24
|
dry-configurable (~> 0.1, >= 0.1.3)
|
24
|
-
dry-
|
25
|
+
dry-matcher (0.5.0)
|
26
|
+
dry-monads (0.0.2)
|
25
27
|
json (1.8.3)
|
26
28
|
method_source (0.8.2)
|
27
29
|
pry (0.10.3)
|
data/lib/dry/transaction.rb
CHANGED
@@ -44,8 +44,10 @@ module Dry
|
|
44
44
|
#
|
45
45
|
# @param options [Hash] the options hash
|
46
46
|
# @option options [#[]] :container the operations container
|
47
|
+
# @option options [#[]] :step_adapters (Dry::Transaction::StepAdapters) a custom container of step adapters
|
48
|
+
# @option options [Dry::Matcher] :matcher (Dry::Transaction::ResultMatcher) a custom matcher object for result matching block API
|
47
49
|
#
|
48
|
-
# @return [Dry::Transaction::
|
50
|
+
# @return [Dry::Transaction::Sequence] the transaction object
|
49
51
|
#
|
50
52
|
# @api public
|
51
53
|
def self.Transaction(options = {}, &block)
|
data/lib/dry/transaction/dsl.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "dry/transaction/result_matcher"
|
1
2
|
require "dry/transaction/step"
|
2
3
|
require "dry/transaction/step_adapters"
|
3
4
|
require "dry/transaction/sequence"
|
@@ -9,11 +10,13 @@ module Dry
|
|
9
10
|
attr_reader :container
|
10
11
|
attr_reader :step_adapters
|
11
12
|
attr_reader :steps
|
13
|
+
attr_reader :matcher
|
12
14
|
|
13
15
|
def initialize(options, &block)
|
14
16
|
@container = options.fetch(:container)
|
15
|
-
@step_adapters = options.fetch(:step_adapters
|
17
|
+
@step_adapters = options.fetch(:step_adapters) { StepAdapters }
|
16
18
|
@steps = []
|
19
|
+
@matcher = options.fetch(:matcher) { ResultMatcher }
|
17
20
|
|
18
21
|
instance_eval(&block)
|
19
22
|
end
|
@@ -35,7 +38,7 @@ module Dry
|
|
35
38
|
end
|
36
39
|
|
37
40
|
def call
|
38
|
-
Sequence.new(steps)
|
41
|
+
Sequence.new(steps, matcher)
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
@@ -1,30 +1,22 @@
|
|
1
|
+
require "dry-matcher"
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
module Transaction
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def failure(step_name = nil, &block)
|
22
|
-
return output unless result.left?
|
23
|
-
|
24
|
-
if step_name.nil? || step_name == result.value.__step_name
|
25
|
-
@output = block.call(result.value)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
5
|
+
ResultMatcher = Dry::Matcher.new(
|
6
|
+
success: Dry::Matcher::Case.new(
|
7
|
+
match: -> result { result.right? },
|
8
|
+
resolve: -> result { result.value },
|
9
|
+
),
|
10
|
+
failure: Dry::Matcher::Case.new(
|
11
|
+
match: -> result, step_name = nil {
|
12
|
+
if step_name
|
13
|
+
result.left? && result.value.step_name == step_name
|
14
|
+
else
|
15
|
+
result.left?
|
16
|
+
end
|
17
|
+
},
|
18
|
+
resolve: -> result { result.value.value },
|
19
|
+
)
|
20
|
+
)
|
29
21
|
end
|
30
22
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require "dry/
|
1
|
+
require "dry/monads/either"
|
2
|
+
require "dry/transaction/dsl"
|
2
3
|
|
3
4
|
module Dry
|
4
5
|
module Transaction
|
@@ -9,8 +10,12 @@ module Dry
|
|
9
10
|
attr_reader :steps
|
10
11
|
|
11
12
|
# @api private
|
12
|
-
|
13
|
+
attr_reader :matcher
|
14
|
+
|
15
|
+
# @api private
|
16
|
+
def initialize(steps, matcher)
|
13
17
|
@steps = steps
|
18
|
+
@matcher = matcher
|
14
19
|
end
|
15
20
|
|
16
21
|
# Run the transaction.
|
@@ -50,9 +55,12 @@ module Dry
|
|
50
55
|
result = steps.inject(Right(input), :bind)
|
51
56
|
|
52
57
|
if block
|
53
|
-
|
58
|
+
matcher.(result, &block)
|
54
59
|
else
|
55
|
-
result
|
60
|
+
result.or { |step_failure|
|
61
|
+
# Unwrap the value from the StepFailure and return it directly
|
62
|
+
Left(step_failure.value)
|
63
|
+
}
|
56
64
|
end
|
57
65
|
end
|
58
66
|
alias_method :[], :call
|
@@ -136,7 +144,7 @@ module Dry
|
|
136
144
|
def prepend(other = nil, **options, &block)
|
137
145
|
other = accept_or_build_transaction(other, **options, &block)
|
138
146
|
|
139
|
-
self.class.new(other.steps + steps)
|
147
|
+
self.class.new(other.steps + steps, matcher)
|
140
148
|
end
|
141
149
|
|
142
150
|
# Return a transaction with the steps from the provided transaction
|
@@ -177,7 +185,7 @@ module Dry
|
|
177
185
|
def append(other = nil, **options, &block)
|
178
186
|
other = accept_or_build_transaction(other, **options, &block)
|
179
187
|
|
180
|
-
self.class.new(steps + other.steps)
|
188
|
+
self.class.new(steps + other.steps, matcher)
|
181
189
|
end
|
182
190
|
|
183
191
|
# Return a transaction with the steps from the provided transaction
|
@@ -230,7 +238,7 @@ module Dry
|
|
230
238
|
other = accept_or_build_transaction(other, **options, &block)
|
231
239
|
index = steps.index { |step| step.step_name == insertion_step } + (!!after ? 1 : 0)
|
232
240
|
|
233
|
-
self.class.new(steps.dup.insert(index, *other.steps))
|
241
|
+
self.class.new(steps.dup.insert(index, *other.steps), matcher)
|
234
242
|
end
|
235
243
|
|
236
244
|
# @overload remove(step, ...)
|
@@ -252,7 +260,7 @@ module Dry
|
|
252
260
|
#
|
253
261
|
# @api public
|
254
262
|
def remove(*steps_to_remove)
|
255
|
-
self.class.new(steps.reject { |step| steps_to_remove.include?(step.step_name) })
|
263
|
+
self.class.new(steps.reject { |step| steps_to_remove.include?(step.step_name) }, matcher)
|
256
264
|
end
|
257
265
|
|
258
266
|
private
|
@@ -1,23 +1,12 @@
|
|
1
1
|
module Dry
|
2
2
|
module Transaction
|
3
|
-
class StepFailure
|
4
|
-
attr_reader :
|
3
|
+
class StepFailure
|
4
|
+
attr_reader :step_name
|
5
|
+
attr_reader :value
|
5
6
|
|
6
|
-
def initialize(step_name,
|
7
|
-
@
|
8
|
-
@
|
9
|
-
end
|
10
|
-
|
11
|
-
def method_missing(name, *args, &block)
|
12
|
-
@__object.public_send(name, *args, &block)
|
13
|
-
end
|
14
|
-
|
15
|
-
def respond_to_missing?(name, include_private = false)
|
16
|
-
@__object.respond_to?(name, include_private)
|
17
|
-
end
|
18
|
-
|
19
|
-
def ==(other)
|
20
|
-
@__object == other
|
7
|
+
def initialize(step_name, value)
|
8
|
+
@step_name = step_name
|
9
|
+
@value = value
|
21
10
|
end
|
22
11
|
end
|
23
12
|
end
|
data/spec/examples.txt
CHANGED
@@ -1,45 +1,64 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
-------------------------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/integration/custom_matcher_spec.rb[1:1] | passed | 0.00028 seconds |
|
3
4
|
./spec/integration/custom_step_adapters_spec.rb[1:1] | passed | 0.00027 seconds |
|
4
|
-
./spec/integration/passing_step_arguments_spec.rb[1:1:1] | passed | 0.
|
5
|
-
./spec/integration/passing_step_arguments_spec.rb[1:2:1] | passed | 0.
|
6
|
-
./spec/integration/passing_step_arguments_spec.rb[1:3:1] | passed | 0.
|
7
|
-
./spec/integration/publishing_step_events_spec.rb[1:1:1] | passed | 0.
|
8
|
-
./spec/integration/publishing_step_events_spec.rb[1:1:2] | passed | 0.
|
9
|
-
./spec/integration/publishing_step_events_spec.rb[1:2:1] | passed | 0.
|
10
|
-
./spec/integration/publishing_step_events_spec.rb[1:2:2] | passed | 0.
|
11
|
-
./spec/integration/transaction_spec.rb[1:1:1] | passed | 0.
|
12
|
-
./spec/integration/transaction_spec.rb[1:1:2] | passed | 0.
|
13
|
-
./spec/integration/transaction_spec.rb[1:1:3] | passed | 0.
|
14
|
-
./spec/integration/transaction_spec.rb[1:1:4] | passed | 0.
|
15
|
-
./spec/integration/transaction_spec.rb[1:1:5] | passed | 0.
|
16
|
-
./spec/integration/transaction_spec.rb[1:2:1] | passed | 0.
|
17
|
-
./spec/integration/transaction_spec.rb[1:2:2] | passed | 0.
|
18
|
-
./spec/integration/transaction_spec.rb[1:2:3] | passed | 0.
|
19
|
-
./spec/integration/transaction_spec.rb[1:2:4] | passed | 0.
|
20
|
-
./spec/integration/transaction_spec.rb[1:2:5] | passed | 0.
|
21
|
-
./spec/integration/transaction_spec.rb[1:2:6] | passed | 0.
|
22
|
-
./spec/integration/transaction_spec.rb[1:3:1] | passed | 0.
|
23
|
-
./spec/integration/transaction_spec.rb[1:3:2] | passed | 0.
|
24
|
-
./spec/integration/transaction_spec.rb[1:3:3] | passed | 0.
|
25
|
-
./spec/integration/transaction_spec.rb[1:3:4] | passed | 0.
|
26
|
-
./spec/integration/transaction_spec.rb[1:3:5] | passed | 0.
|
27
|
-
./spec/integration/transaction_spec.rb[1:4:1] | passed | 0.
|
28
|
-
./spec/unit/sequence_spec.rb[1:1:1] | passed | 0.
|
29
|
-
./spec/unit/sequence_spec.rb[1:1:2] | passed | 0.
|
30
|
-
./spec/unit/sequence_spec.rb[1:1:3] | passed | 0.
|
5
|
+
./spec/integration/passing_step_arguments_spec.rb[1:1:1] | passed | 0.00021 seconds |
|
6
|
+
./spec/integration/passing_step_arguments_spec.rb[1:2:1] | passed | 0.0002 seconds |
|
7
|
+
./spec/integration/passing_step_arguments_spec.rb[1:3:1] | passed | 0.00017 seconds |
|
8
|
+
./spec/integration/publishing_step_events_spec.rb[1:1:1] | passed | 0.00046 seconds |
|
9
|
+
./spec/integration/publishing_step_events_spec.rb[1:1:2] | passed | 0.00043 seconds |
|
10
|
+
./spec/integration/publishing_step_events_spec.rb[1:2:1] | passed | 0.00043 seconds |
|
11
|
+
./spec/integration/publishing_step_events_spec.rb[1:2:2] | passed | 0.00178 seconds |
|
12
|
+
./spec/integration/transaction_spec.rb[1:1:1] | passed | 0.00152 seconds |
|
13
|
+
./spec/integration/transaction_spec.rb[1:1:2] | passed | 0.00023 seconds |
|
14
|
+
./spec/integration/transaction_spec.rb[1:1:3] | passed | 0.00022 seconds |
|
15
|
+
./spec/integration/transaction_spec.rb[1:1:4] | passed | 0.0003 seconds |
|
16
|
+
./spec/integration/transaction_spec.rb[1:1:5] | passed | 0.00021 seconds |
|
17
|
+
./spec/integration/transaction_spec.rb[1:2:1] | passed | 0.00258 seconds |
|
18
|
+
./spec/integration/transaction_spec.rb[1:2:2] | passed | 0.00033 seconds |
|
19
|
+
./spec/integration/transaction_spec.rb[1:2:3] | passed | 0.00043 seconds |
|
20
|
+
./spec/integration/transaction_spec.rb[1:2:4] | passed | 0.00026 seconds |
|
21
|
+
./spec/integration/transaction_spec.rb[1:2:5] | passed | 0.00114 seconds |
|
22
|
+
./spec/integration/transaction_spec.rb[1:2:6] | passed | 0.00028 seconds |
|
23
|
+
./spec/integration/transaction_spec.rb[1:3:1] | passed | 0.00185 seconds |
|
24
|
+
./spec/integration/transaction_spec.rb[1:3:2] | passed | 0.00028 seconds |
|
25
|
+
./spec/integration/transaction_spec.rb[1:3:3] | passed | 0.00019 seconds |
|
26
|
+
./spec/integration/transaction_spec.rb[1:3:4] | passed | 0.00038 seconds |
|
27
|
+
./spec/integration/transaction_spec.rb[1:3:5] | passed | 0.00025 seconds |
|
28
|
+
./spec/integration/transaction_spec.rb[1:4:1] | passed | 0.00026 seconds |
|
29
|
+
./spec/unit/sequence_spec.rb[1:1:1] | passed | 0.00019 seconds |
|
30
|
+
./spec/unit/sequence_spec.rb[1:1:2] | passed | 0.00016 seconds |
|
31
|
+
./spec/unit/sequence_spec.rb[1:1:3] | passed | 0.00013 seconds |
|
31
32
|
./spec/unit/sequence_spec.rb[1:1:4] | passed | 0.00015 seconds |
|
32
|
-
./spec/unit/sequence_spec.rb[1:2:1] | passed | 0.
|
33
|
-
./spec/unit/sequence_spec.rb[1:2:2] | passed | 0.
|
34
|
-
./spec/unit/sequence_spec.rb[1:2:3] | passed | 0.
|
35
|
-
./spec/unit/sequence_spec.rb[1:2:4] | passed | 0.
|
36
|
-
./spec/unit/sequence_spec.rb[1:3:1] | passed | 0.
|
33
|
+
./spec/unit/sequence_spec.rb[1:2:1] | passed | 0.00018 seconds |
|
34
|
+
./spec/unit/sequence_spec.rb[1:2:2] | passed | 0.00016 seconds |
|
35
|
+
./spec/unit/sequence_spec.rb[1:2:3] | passed | 0.00015 seconds |
|
36
|
+
./spec/unit/sequence_spec.rb[1:2:4] | passed | 0.0002 seconds |
|
37
|
+
./spec/unit/sequence_spec.rb[1:3:1] | passed | 0.00017 seconds |
|
37
38
|
./spec/unit/sequence_spec.rb[1:3:2] | passed | 0.00017 seconds |
|
38
|
-
./spec/unit/sequence_spec.rb[1:4:1] | passed | 0.
|
39
|
-
./spec/unit/sequence_spec.rb[1:4:2] | passed | 0.
|
40
|
-
./spec/unit/sequence_spec.rb[1:4:3] | passed | 0.
|
41
|
-
./spec/unit/sequence_spec.rb[1:4:4] | passed | 0.
|
42
|
-
./spec/unit/sequence_spec.rb[1:4:5:1] | passed | 0.
|
43
|
-
./spec/unit/sequence_spec.rb[1:4:5:2] | passed | 0.
|
44
|
-
./spec/unit/sequence_spec.rb[1:4:6:1] | passed | 0.
|
45
|
-
./spec/unit/sequence_spec.rb[1:4:6:2] | passed | 0.
|
39
|
+
./spec/unit/sequence_spec.rb[1:4:1] | passed | 0.00022 seconds |
|
40
|
+
./spec/unit/sequence_spec.rb[1:4:2] | passed | 0.00019 seconds |
|
41
|
+
./spec/unit/sequence_spec.rb[1:4:3] | passed | 0.00013 seconds |
|
42
|
+
./spec/unit/sequence_spec.rb[1:4:4] | passed | 0.00014 seconds |
|
43
|
+
./spec/unit/sequence_spec.rb[1:4:5:1] | passed | 0.0002 seconds |
|
44
|
+
./spec/unit/sequence_spec.rb[1:4:5:2] | passed | 0.0002 seconds |
|
45
|
+
./spec/unit/sequence_spec.rb[1:4:6:1] | passed | 0.00022 seconds |
|
46
|
+
./spec/unit/sequence_spec.rb[1:4:6:2] | passed | 0.00018 seconds |
|
47
|
+
./spec/unit/step_adapters/map_spec.rb[1:1:1] | passed | 0.00011 seconds |
|
48
|
+
./spec/unit/step_adapters/map_spec.rb[1:1:2] | passed | 0.0001 seconds |
|
49
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:1:1] | passed | 0.00153 seconds |
|
50
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:2:1] | passed | 0.00011 seconds |
|
51
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:2:2] | passed | 0.00015 seconds |
|
52
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:3:1] | passed | 0.00096 seconds |
|
53
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:3:2] | passed | 0.00092 seconds |
|
54
|
+
./spec/unit/step_adapters/tee_spec.rb[1:1:1] | passed | 0.00009 seconds |
|
55
|
+
./spec/unit/step_adapters/tee_spec.rb[1:1:2] | passed | 0.00015 seconds |
|
56
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:1:1] | passed | 0.00015 seconds |
|
57
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:1] | passed | 0.00012 seconds |
|
58
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:2] | passed | 0.00016 seconds |
|
59
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:1] | passed | 0.00015 seconds |
|
60
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:2] | passed | 0.00014 seconds |
|
61
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:1] | passed | 0.00012 seconds |
|
62
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:2] | passed | 0.00011 seconds |
|
63
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:3:1] | passed | 0.00012 seconds |
|
64
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:3:2] | passed | 0.00012 seconds |
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "dry-matcher"
|
2
|
+
require "dry-monads"
|
3
|
+
|
4
|
+
RSpec.describe "Custom matcher" do
|
5
|
+
let(:transaction) {
|
6
|
+
Dry.Transaction(container: container, matcher: Test::CustomMatcher) do
|
7
|
+
step :process
|
8
|
+
step :validate
|
9
|
+
step :persist
|
10
|
+
end
|
11
|
+
}
|
12
|
+
|
13
|
+
let(:container) {
|
14
|
+
{
|
15
|
+
process: -> input { Dry::Monads.Right(name: input["name"], email: input["email"]) },
|
16
|
+
validate: -> input { input[:email].nil? ? Dry::Monads.Left(:email_required) : Dry::Monads.Right(input) },
|
17
|
+
persist: -> input { Test::DB << input and Dry::Monads.Right(input) }
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
before do
|
22
|
+
Test::DB = []
|
23
|
+
Test::QUEUE = []
|
24
|
+
|
25
|
+
module Test
|
26
|
+
CustomMatcher = Dry::Matcher.new(
|
27
|
+
yep: Dry::Matcher::Case.new(
|
28
|
+
match: -> result { result.right? },
|
29
|
+
resolve: -> result { result.value }
|
30
|
+
),
|
31
|
+
nup: Dry::Matcher::Case.new(
|
32
|
+
match: -> result { result.left? },
|
33
|
+
resolve: -> result { result.value.value }
|
34
|
+
)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "supports a custom matcher" do
|
40
|
+
matches = -> m {
|
41
|
+
m.yep { |v| "Yep! #{v[:email]}" }
|
42
|
+
m.nup { |v| "Nup. #{v.to_s}" }
|
43
|
+
}
|
44
|
+
|
45
|
+
input = {"name" => "Jane", "email" => "jane@doe.com"}
|
46
|
+
result = transaction.(input, &matches)
|
47
|
+
expect(result).to eq "Yep! jane@doe.com"
|
48
|
+
|
49
|
+
input = {"name" => "Jane"}
|
50
|
+
result = transaction.(input, &matches)
|
51
|
+
expect(result).to eq "Nup. email_required"
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
RSpec.describe Dry::Transaction::StepAdapters::Map do
|
2
|
+
|
3
|
+
subject { described_class.new }
|
4
|
+
|
5
|
+
let(:operation) {
|
6
|
+
-> (input) { input.upcase }
|
7
|
+
}
|
8
|
+
|
9
|
+
let(:step) {
|
10
|
+
Dry::Transaction::Step.new(subject, :step, :step, operation, {})
|
11
|
+
}
|
12
|
+
|
13
|
+
describe "#call" do
|
14
|
+
|
15
|
+
it "return a Right Monad" do
|
16
|
+
expect(subject.call(step, 'input')).to be_a Dry::Monads::Either::Right
|
17
|
+
end
|
18
|
+
|
19
|
+
it "return the result of the operation as output" do
|
20
|
+
expect(subject.call(step, 'input').value).to eql 'INPUT'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
RSpec.describe Dry::Transaction::StepAdapters::Raw do
|
2
|
+
|
3
|
+
subject { described_class.new }
|
4
|
+
|
5
|
+
let(:operation) {
|
6
|
+
-> (input) { input.upcase }
|
7
|
+
}
|
8
|
+
|
9
|
+
let(:step) {
|
10
|
+
Dry::Transaction::Step.new(subject, :step, :step, operation, {})
|
11
|
+
}
|
12
|
+
|
13
|
+
describe "#call" do
|
14
|
+
|
15
|
+
context "when the result of the operation is NOT a Dry::Monads::Either" do
|
16
|
+
|
17
|
+
it "raises an ArgumentError" do
|
18
|
+
expect do
|
19
|
+
subject.call(step, 'input')
|
20
|
+
end.to raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when the result of the operation is a Left Monad" do
|
25
|
+
let(:operation) {
|
26
|
+
-> (input) { Left(input.upcase) }
|
27
|
+
}
|
28
|
+
|
29
|
+
it "return a Left Monad" do
|
30
|
+
expect(subject.call(step, 'input')).to be_a Dry::Monads::Either::Left
|
31
|
+
end
|
32
|
+
|
33
|
+
it "return the result of the operation as output" do
|
34
|
+
expect(subject.call(step, 'input').value).to eql 'INPUT'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when the result of the operation is a Right Monad" do
|
39
|
+
let(:operation) {
|
40
|
+
-> (input) { Right(input.upcase) }
|
41
|
+
}
|
42
|
+
|
43
|
+
it "return a Right Monad" do
|
44
|
+
expect(subject.call(step, 'input')).to be_a Dry::Monads::Either::Right
|
45
|
+
end
|
46
|
+
|
47
|
+
it "return the result of the operation as output" do
|
48
|
+
expect(subject.call(step, 'input').value).to eql 'INPUT'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
RSpec.describe Dry::Transaction::StepAdapters::Tee do
|
2
|
+
|
3
|
+
subject { described_class.new }
|
4
|
+
|
5
|
+
let(:operation) {
|
6
|
+
-> (input) { input.upcase }
|
7
|
+
}
|
8
|
+
|
9
|
+
let(:step) {
|
10
|
+
Dry::Transaction::Step.new(subject, :step, :step, operation, {})
|
11
|
+
}
|
12
|
+
|
13
|
+
describe "#call" do
|
14
|
+
|
15
|
+
it "return a Right Monad" do
|
16
|
+
expect(subject.call(step, 'input')).to be_a Dry::Monads::Either::Right
|
17
|
+
end
|
18
|
+
|
19
|
+
it "return the original input as output" do
|
20
|
+
expect(subject.call(step, 'input').value).to eql 'input'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-transaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.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: 2016-06
|
11
|
+
date: 2016-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-container
|
@@ -24,18 +24,32 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.2.8
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-matcher
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.5.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: dry-monads
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: 0.0.1
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: 0.0.1
|
41
55
|
- !ruby/object:Gem::Dependency
|
@@ -148,6 +162,7 @@ files:
|
|
148
162
|
- lib/dry/transaction/step_failure.rb
|
149
163
|
- lib/dry/transaction/version.rb
|
150
164
|
- spec/examples.txt
|
165
|
+
- spec/integration/custom_matcher_spec.rb
|
151
166
|
- spec/integration/custom_step_adapters_spec.rb
|
152
167
|
- spec/integration/passing_step_arguments_spec.rb
|
153
168
|
- spec/integration/publishing_step_events_spec.rb
|
@@ -156,6 +171,9 @@ files:
|
|
156
171
|
- spec/support/either_mixin.rb
|
157
172
|
- spec/support/test_module_constants.rb
|
158
173
|
- spec/unit/sequence_spec.rb
|
174
|
+
- spec/unit/step_adapters/map_spec.rb
|
175
|
+
- spec/unit/step_adapters/raw_spec.rb
|
176
|
+
- spec/unit/step_adapters/tee_spec.rb
|
159
177
|
- spec/unit/step_adapters/try_spec.rb
|
160
178
|
homepage: https://github.com/dry-rb/dry-transaction
|
161
179
|
licenses:
|
@@ -169,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
187
|
requirements:
|
170
188
|
- - ">="
|
171
189
|
- !ruby/object:Gem::Version
|
172
|
-
version: 2.
|
190
|
+
version: 2.1.0
|
173
191
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
192
|
requirements:
|
175
193
|
- - ">="
|