dry-transaction 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -3
- data/lib/dry/transaction/instance_methods.rb +6 -2
- data/lib/dry/transaction/version.rb +1 -1
- data/spec/examples.txt +60 -58
- data/spec/integration/publishing_step_events_spec.rb +41 -8
- data/spec/spec_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 297ac423123374945b62db51967e5a84ab01cadf
|
4
|
+
data.tar.gz: 72b12c2f322edea6c349bedb12eb8f032a02badf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c935fb4f6c44ebdf251d519262d8276039cf1dbc565c35d16d80ab7915d4ffe4de7a9eb2189a20ca6af0061ce8c23a90abe3c20ff4cec06f9811c81a70a26c27
|
7
|
+
data.tar.gz: 9eb6512ac995b4c5c7121f5c5d254f07fae98849c1bf9270ccd90e3eb46e00a933b409e9a0c75e9e29bcf9603b2904d9414e73f67a852cc65cb4308b219c7182
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dry-transaction (0.10.
|
4
|
+
dry-transaction (0.10.1)
|
5
5
|
dry-container (>= 0.2.8)
|
6
6
|
dry-matcher (>= 0.5.0)
|
7
7
|
dry-monads (>= 0.0.1)
|
@@ -23,9 +23,12 @@ GEM
|
|
23
23
|
dry-container (0.6.0)
|
24
24
|
concurrent-ruby (~> 1.0)
|
25
25
|
dry-configurable (~> 0.1, >= 0.1.3)
|
26
|
+
dry-core (0.3.1)
|
27
|
+
concurrent-ruby (~> 1.0)
|
26
28
|
dry-equalizer (0.2.0)
|
27
29
|
dry-matcher (0.6.0)
|
28
|
-
dry-monads (0.
|
30
|
+
dry-monads (0.3.1)
|
31
|
+
dry-core
|
29
32
|
dry-equalizer
|
30
33
|
json (1.8.6)
|
31
34
|
method_source (0.8.2)
|
@@ -65,7 +68,7 @@ GEM
|
|
65
68
|
simplecov-html (0.10.0)
|
66
69
|
slop (3.6.0)
|
67
70
|
unicode-display_width (1.1.1)
|
68
|
-
wisper (
|
71
|
+
wisper (2.0.0)
|
69
72
|
yard (0.8.7.6)
|
70
73
|
|
71
74
|
PLATFORMS
|
@@ -6,13 +6,15 @@ module Dry
|
|
6
6
|
module InstanceMethods
|
7
7
|
attr_reader :steps
|
8
8
|
attr_reader :operations
|
9
|
+
attr_reader :listeners
|
9
10
|
|
10
|
-
def initialize(steps: (self.class.steps), **operations)
|
11
|
+
def initialize(steps: (self.class.steps), listeners: nil, **operations)
|
11
12
|
@steps = steps.map { |step|
|
12
13
|
operation = methods.include?(step.step_name) ? method(step.step_name) : operations[step.step_name]
|
13
14
|
step.with(operation: operation)
|
14
15
|
}
|
15
16
|
@operations = operations
|
17
|
+
subscribe(listeners) unless listeners.nil?
|
16
18
|
end
|
17
19
|
|
18
20
|
def call(input, &block)
|
@@ -31,6 +33,8 @@ module Dry
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def subscribe(listeners)
|
36
|
+
@listeners = listeners
|
37
|
+
|
34
38
|
if listeners.is_a?(Hash)
|
35
39
|
listeners.each do |step_name, listener|
|
36
40
|
steps.detect { |step| step.step_name == step_name }.subscribe(listener)
|
@@ -53,7 +57,7 @@ module Dry
|
|
53
57
|
end
|
54
58
|
}
|
55
59
|
|
56
|
-
self.class.new(steps: new_steps, **operations)
|
60
|
+
self.class.new(steps: new_steps, listeners: listeners, **operations)
|
57
61
|
end
|
58
62
|
|
59
63
|
private
|
data/spec/examples.txt
CHANGED
@@ -1,62 +1,64 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
-------------------------------------------------------- | ------ | --------------- |
|
3
|
-
./spec/integration/custom_step_adapters_spec.rb[1:1] | passed | 0.
|
4
|
-
./spec/integration/operation_spec.rb[1:1] | passed | 0.
|
5
|
-
./spec/integration/operation_spec.rb[1:2] | passed | 0.
|
6
|
-
./spec/integration/passing_step_arguments_spec.rb[1:1:1] | passed | 0.
|
7
|
-
./spec/integration/passing_step_arguments_spec.rb[1:2:1] | passed | 0.
|
8
|
-
./spec/integration/passing_step_arguments_spec.rb[1:3:1] | passed | 0.
|
9
|
-
./spec/integration/publishing_step_events_spec.rb[1:1:1] | passed | 0.
|
10
|
-
./spec/integration/publishing_step_events_spec.rb[1:1:2] | passed | 0.
|
11
|
-
./spec/integration/publishing_step_events_spec.rb[1:2:1] | passed | 0.
|
12
|
-
./spec/integration/publishing_step_events_spec.rb[1:2:2] | passed | 0.
|
13
|
-
./spec/integration/
|
14
|
-
./spec/integration/
|
15
|
-
./spec/integration/transaction_spec.rb[1:1:
|
16
|
-
./spec/integration/transaction_spec.rb[1:1:
|
17
|
-
./spec/integration/transaction_spec.rb[1:1:
|
18
|
-
./spec/integration/transaction_spec.rb[1:
|
19
|
-
./spec/integration/transaction_spec.rb[1:
|
20
|
-
./spec/integration/transaction_spec.rb[1:
|
21
|
-
./spec/integration/transaction_spec.rb[1:
|
22
|
-
./spec/integration/transaction_spec.rb[1:
|
23
|
-
./spec/integration/transaction_spec.rb[1:
|
24
|
-
./spec/integration/transaction_spec.rb[1:
|
25
|
-
./spec/integration/transaction_spec.rb[1:7:
|
26
|
-
./spec/integration/transaction_spec.rb[1:7:
|
27
|
-
./spec/integration/transaction_spec.rb[1:7:
|
28
|
-
./spec/integration/transaction_spec.rb[1:7:
|
29
|
-
./spec/integration/transaction_spec.rb[1:
|
30
|
-
./spec/integration/transaction_spec.rb[1:
|
31
|
-
./spec/integration/transaction_spec.rb[1:8:
|
32
|
-
./spec/integration/transaction_spec.rb[1:8:
|
33
|
-
./spec/integration/transaction_spec.rb[1:8:
|
34
|
-
./spec/integration/transaction_spec.rb[1:
|
35
|
-
./spec/
|
36
|
-
./spec/
|
37
|
-
./spec/unit/step_adapters/
|
38
|
-
./spec/unit/step_adapters/
|
39
|
-
./spec/unit/step_adapters/raw_spec.rb[1:1:
|
40
|
-
./spec/unit/step_adapters/raw_spec.rb[1:1:
|
41
|
-
./spec/unit/step_adapters/raw_spec.rb[1:1:
|
42
|
-
./spec/unit/step_adapters/
|
43
|
-
./spec/unit/step_adapters/
|
44
|
-
./spec/unit/step_adapters/
|
3
|
+
./spec/integration/custom_step_adapters_spec.rb[1:1] | passed | 0.00213 seconds |
|
4
|
+
./spec/integration/operation_spec.rb[1:1] | passed | 0.00313 seconds |
|
5
|
+
./spec/integration/operation_spec.rb[1:2] | passed | 0.00127 seconds |
|
6
|
+
./spec/integration/passing_step_arguments_spec.rb[1:1:1] | passed | 0.0008 seconds |
|
7
|
+
./spec/integration/passing_step_arguments_spec.rb[1:2:1] | passed | 0.00036 seconds |
|
8
|
+
./spec/integration/passing_step_arguments_spec.rb[1:3:1] | passed | 0.00197 seconds |
|
9
|
+
./spec/integration/publishing_step_events_spec.rb[1:1:1] | passed | 0.00074 seconds |
|
10
|
+
./spec/integration/publishing_step_events_spec.rb[1:1:2] | passed | 0.00065 seconds |
|
11
|
+
./spec/integration/publishing_step_events_spec.rb[1:2:1] | passed | 0.00072 seconds |
|
12
|
+
./spec/integration/publishing_step_events_spec.rb[1:2:2] | passed | 0.00062 seconds |
|
13
|
+
./spec/integration/publishing_step_events_spec.rb[1:3:1] | passed | 0.00226 seconds |
|
14
|
+
./spec/integration/publishing_step_events_spec.rb[1:3:2] | passed | 0.00066 seconds |
|
15
|
+
./spec/integration/transaction_spec.rb[1:1:1] | passed | 0.00043 seconds |
|
16
|
+
./spec/integration/transaction_spec.rb[1:1:2] | passed | 0.00109 seconds |
|
17
|
+
./spec/integration/transaction_spec.rb[1:1:3] | passed | 0.00096 seconds |
|
18
|
+
./spec/integration/transaction_spec.rb[1:1:4] | passed | 0.00111 seconds |
|
19
|
+
./spec/integration/transaction_spec.rb[1:1:5] | passed | 0.00126 seconds |
|
20
|
+
./spec/integration/transaction_spec.rb[1:2:1] | passed | 0.00034 seconds |
|
21
|
+
./spec/integration/transaction_spec.rb[1:3:1] | passed | 0.00072 seconds |
|
22
|
+
./spec/integration/transaction_spec.rb[1:4:1] | passed | 0.00094 seconds |
|
23
|
+
./spec/integration/transaction_spec.rb[1:5:1] | passed | 0.00043 seconds |
|
24
|
+
./spec/integration/transaction_spec.rb[1:6:1] | passed | 0.0007 seconds |
|
25
|
+
./spec/integration/transaction_spec.rb[1:7:1] | passed | 0.00061 seconds |
|
26
|
+
./spec/integration/transaction_spec.rb[1:7:2] | passed | 0.00096 seconds |
|
27
|
+
./spec/integration/transaction_spec.rb[1:7:3] | passed | 0.00097 seconds |
|
28
|
+
./spec/integration/transaction_spec.rb[1:7:4] | passed | 0.00093 seconds |
|
29
|
+
./spec/integration/transaction_spec.rb[1:7:5] | passed | 0.00053 seconds |
|
30
|
+
./spec/integration/transaction_spec.rb[1:7:6] | passed | 0.00073 seconds |
|
31
|
+
./spec/integration/transaction_spec.rb[1:8:1] | passed | 0.00086 seconds |
|
32
|
+
./spec/integration/transaction_spec.rb[1:8:2] | passed | 0.00074 seconds |
|
33
|
+
./spec/integration/transaction_spec.rb[1:8:3] | passed | 0.00072 seconds |
|
34
|
+
./spec/integration/transaction_spec.rb[1:8:4] | passed | 0.00032 seconds |
|
35
|
+
./spec/integration/transaction_spec.rb[1:8:5] | passed | 0.00044 seconds |
|
36
|
+
./spec/integration/transaction_spec.rb[1:9:1] | passed | 0.00096 seconds |
|
37
|
+
./spec/unit/step_adapters/map_spec.rb[1:1:1] | passed | 0.00013 seconds |
|
38
|
+
./spec/unit/step_adapters/map_spec.rb[1:1:2] | passed | 0.00026 seconds |
|
39
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:1:1] | passed | 0.00204 seconds |
|
40
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:2:1] | passed | 0.00019 seconds |
|
41
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:2:2] | passed | 0.00017 seconds |
|
42
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:3:1] | passed | 0.00012 seconds |
|
43
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:3:2] | passed | 0.00015 seconds |
|
44
|
+
./spec/unit/step_adapters/tee_spec.rb[1:1:1] | passed | 0.00194 seconds |
|
45
|
+
./spec/unit/step_adapters/tee_spec.rb[1:1:2] | passed | 0.00163 seconds |
|
46
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:1:1] | passed | 0.00017 seconds |
|
45
47
|
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:1] | passed | 0.00013 seconds |
|
46
48
|
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:2] | passed | 0.00019 seconds |
|
47
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:1] | passed | 0.
|
48
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:2] | passed | 0.
|
49
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:1] | passed | 0.
|
50
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:2] | passed | 0.
|
51
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:3:1] | passed | 0.
|
52
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:3:2] | passed | 0.
|
53
|
-
./spec/unit/step_spec.rb[1:1:1:1] | passed | 0.
|
54
|
-
./spec/unit/step_spec.rb[1:1:1:2] | passed | 0.
|
55
|
-
./spec/unit/step_spec.rb[1:1:2:1] | passed | 0.
|
56
|
-
./spec/unit/step_spec.rb[1:1:2:2] | passed | 0.
|
57
|
-
./spec/unit/step_spec.rb[1:1:2:3] | passed | 0.
|
58
|
-
./spec/unit/step_spec.rb[1:2:1:1] | passed | 0.
|
59
|
-
./spec/unit/step_spec.rb[1:2:2:1] | passed | 0.
|
60
|
-
./spec/unit/step_spec.rb[1:2:3:1] | passed | 0.
|
61
|
-
./spec/unit/step_spec.rb[1:3:1:1] | passed | 0.
|
62
|
-
./spec/unit/step_spec.rb[1:3:2:1] | passed | 0.
|
49
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:1] | passed | 0.00014 seconds |
|
50
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:2] | passed | 0.00013 seconds |
|
51
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:1] | passed | 0.00014 seconds |
|
52
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:2] | passed | 0.00012 seconds |
|
53
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:3:1] | passed | 0.00011 seconds |
|
54
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:3:2] | passed | 0.00012 seconds |
|
55
|
+
./spec/unit/step_spec.rb[1:1:1:1] | passed | 0.00026 seconds |
|
56
|
+
./spec/unit/step_spec.rb[1:1:1:2] | passed | 0.01897 seconds |
|
57
|
+
./spec/unit/step_spec.rb[1:1:2:1] | passed | 0.00028 seconds |
|
58
|
+
./spec/unit/step_spec.rb[1:1:2:2] | passed | 0.0024 seconds |
|
59
|
+
./spec/unit/step_spec.rb[1:1:2:3] | passed | 0.00062 seconds |
|
60
|
+
./spec/unit/step_spec.rb[1:2:1:1] | passed | 0.0001 seconds |
|
61
|
+
./spec/unit/step_spec.rb[1:2:2:1] | passed | 0.00014 seconds |
|
62
|
+
./spec/unit/step_spec.rb[1:2:3:1] | passed | 0.00015 seconds |
|
63
|
+
./spec/unit/step_spec.rb[1:3:1:1] | passed | 0.00013 seconds |
|
64
|
+
./spec/unit/step_spec.rb[1:3:2:1] | passed | 0.00016 seconds |
|
@@ -1,4 +1,14 @@
|
|
1
1
|
RSpec.describe "publishing step events" do
|
2
|
+
let(:container) {
|
3
|
+
Class.new do
|
4
|
+
extend Dry::Container::Mixin
|
5
|
+
|
6
|
+
register :process, -> input { {name: input["name"]} }
|
7
|
+
register :verify, -> input { input[:name].to_s != "" ? Dry::Monads.Right(input) : Dry::Monads.Left("no name") }
|
8
|
+
register :persist, -> input { Test::DB << input and true }
|
9
|
+
end
|
10
|
+
}
|
11
|
+
|
2
12
|
let(:transaction) {
|
3
13
|
Class.new do
|
4
14
|
include Dry::Transaction(container: Test::Container)
|
@@ -13,14 +23,7 @@ RSpec.describe "publishing step events" do
|
|
13
23
|
|
14
24
|
before do
|
15
25
|
Test::DB = []
|
16
|
-
|
17
|
-
module Test
|
18
|
-
Container = {
|
19
|
-
process: -> input { {name: input["name"]} },
|
20
|
-
verify: -> input { input[:name].to_s != "" ? Dry::Monads.Right(input) : Dry::Monads.Left("no name") },
|
21
|
-
persist: -> input { Test::DB << input and true }
|
22
|
-
}
|
23
|
-
end
|
26
|
+
Test::Container = container
|
24
27
|
end
|
25
28
|
|
26
29
|
context "subscribing to all step events" do
|
@@ -64,4 +67,34 @@ RSpec.describe "publishing step events" do
|
|
64
67
|
expect(subscriber).to have_received(:verify_failure).with({name: ""}, "no name")
|
65
68
|
end
|
66
69
|
end
|
70
|
+
|
71
|
+
context "subscribing to step events when passing step arguments" do
|
72
|
+
before do
|
73
|
+
transaction.subscribe(verify: subscriber)
|
74
|
+
end
|
75
|
+
|
76
|
+
let(:container) {
|
77
|
+
Class.new do
|
78
|
+
extend Dry::Container::Mixin
|
79
|
+
|
80
|
+
register :process, -> input { {name: input["name"]} }
|
81
|
+
register :verify, -> input, name { input[:name].to_s == name ? Dry::Monads.Right(input) : Dry::Monads.Left("wrong name") }
|
82
|
+
register :persist, -> input { Test::DB << input and true }
|
83
|
+
end
|
84
|
+
}
|
85
|
+
|
86
|
+
specify "subscriber receives success event for the specified step" do
|
87
|
+
transaction.with_step_args(verify: ["Jane"]).call("name" => "Jane")
|
88
|
+
|
89
|
+
expect(subscriber).to have_received(:verify_success).with(name: "Jane")
|
90
|
+
expect(subscriber).not_to have_received(:process_success)
|
91
|
+
expect(subscriber).not_to have_received(:persist_success)
|
92
|
+
end
|
93
|
+
|
94
|
+
specify "subscriber receives failure event for the specified step" do
|
95
|
+
transaction.with_step_args(verify: ["Jade"]).call("name" => "")
|
96
|
+
|
97
|
+
expect(subscriber).to have_received(:verify_failure).with({name: ""}, "Jade", "wrong name")
|
98
|
+
end
|
99
|
+
end
|
67
100
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,6 +12,7 @@ rescue LoadError; end
|
|
12
12
|
require "dry-transaction"
|
13
13
|
require "dry-matcher"
|
14
14
|
require "dry-monads"
|
15
|
+
require "dry-container"
|
15
16
|
|
16
17
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
17
18
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
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.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Riley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-container
|