actioninteractor 0.2.0 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/action_interactor/base.rb +4 -4
- data/lib/action_interactor/composite.rb +1 -1
- data/lib/action_interactor/errors.rb +1 -1
- data/test/base_test.rb +9 -18
- data/test/composite_test.rb +5 -10
- 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: 50aa89e85f82a36be6c208c040ad6658e72e5c97c17910715bad3b3a80dc3fce
|
4
|
+
data.tar.gz: 13e94c42cbd82290513a05bd5d265fa11c071db00f7d300e72a3d1fc778a96c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4652f87548ab82a699c1fff983d3ffc2bf7fe9007850ccd2640f1736ea7610fb952571065679d260b41dc272b79e7d6b289a63c795f7f8e0f315f3b9be3c2349
|
7
|
+
data.tar.gz: ff20e0e20695f355261633c972c75eb21a76bd7c34d7aa065056eaae936055007788b42f76a7998816dbecbf79212a42edd701876389c1291928d61f8dee434d
|
@@ -27,7 +27,7 @@ module ActionInteractor
|
|
27
27
|
|
28
28
|
# Initialize with payload
|
29
29
|
# Errors and Results data and initial state will be set.
|
30
|
-
def initialize(payload)
|
30
|
+
def initialize(payload = {})
|
31
31
|
@payload = payload
|
32
32
|
@errors = payload[:errors] || Errors.new
|
33
33
|
@results = payload[:results] || Results.new
|
@@ -40,7 +40,7 @@ module ActionInteractor
|
|
40
40
|
def execute
|
41
41
|
# if the interactor already finished execution, do nothing.
|
42
42
|
return if finished?
|
43
|
-
# if contract is not satisfied= (ex: payload is
|
43
|
+
# if contract is not satisfied= (ex: payload is nil), mark as failure.
|
44
44
|
return failure! if payload.nil?
|
45
45
|
# (Implement some codes for the operation.)
|
46
46
|
|
@@ -108,13 +108,13 @@ module ActionInteractor
|
|
108
108
|
|
109
109
|
class << self
|
110
110
|
# Execute the operation with given payload.
|
111
|
-
def execute(payload)
|
111
|
+
def execute(payload = {})
|
112
112
|
new(payload).tap(&:execute)
|
113
113
|
end
|
114
114
|
|
115
115
|
# Execute the operation with given payload.
|
116
116
|
# If there are some errors, ActionInteractor::ExeuctionError will be raised.
|
117
|
-
def execute!(payload)
|
117
|
+
def execute!(payload = {})
|
118
118
|
new(payload).tap(&:execute!)
|
119
119
|
end
|
120
120
|
end
|
@@ -11,7 +11,7 @@ module ActionInteractor
|
|
11
11
|
|
12
12
|
attr_reader :errors
|
13
13
|
|
14
|
-
def_delegators :@errors, :clear, :keys, :values, :[], :empty?, :any?, :
|
14
|
+
def_delegators :@errors, :clear, :keys, :values, :[], :empty?, :any?, :each_pair
|
15
15
|
|
16
16
|
def initialize(*)
|
17
17
|
@errors = {}
|
data/test/base_test.rb
CHANGED
@@ -3,57 +3,48 @@ require_relative "../lib/actioninteractor"
|
|
3
3
|
|
4
4
|
class BaseTest < Test::Unit::TestCase
|
5
5
|
test "initialized successfully" do
|
6
|
-
|
7
|
-
interactor = ActionInteractor::Base.new(payload)
|
6
|
+
interactor = ActionInteractor::Base.new
|
8
7
|
assert_equal(interactor.success?, false)
|
9
8
|
assert_equal(interactor.finished?, false)
|
10
9
|
assert_equal(interactor.errors.empty?, true)
|
11
10
|
end
|
12
11
|
|
13
12
|
test ".execute does not raise error" do
|
14
|
-
|
15
|
-
assert_nothing_raised { ActionInteractor::Base.execute(payload) }
|
13
|
+
assert_nothing_raised { ActionInteractor::Base.execute }
|
16
14
|
end
|
17
15
|
|
18
16
|
test ".execute returns an ActionInteractor::Base instance" do
|
19
|
-
|
20
|
-
interactor = ActionInteractor::Base.execute(payload)
|
17
|
+
interactor = ActionInteractor::Base.execute
|
21
18
|
assert_instance_of(ActionInteractor::Base, interactor)
|
22
19
|
end
|
23
20
|
|
24
21
|
test ".execute! also returns an ActionInteractor::Base instance" do
|
25
|
-
|
26
|
-
interactor = ActionInteractor::Base.execute!(payload)
|
22
|
+
interactor = ActionInteractor::Base.execute!
|
27
23
|
assert_instance_of(ActionInteractor::Base, interactor)
|
28
24
|
end
|
29
25
|
|
30
26
|
test "the result is an instance of ActionInteractor::Results" do
|
31
|
-
|
32
|
-
interactor = ActionInteractor::Base.execute(payload)
|
27
|
+
interactor = ActionInteractor::Base.execute
|
33
28
|
assert_instance_of(ActionInteractor::Results, interactor.results)
|
34
29
|
end
|
35
30
|
|
36
31
|
test "#successful? is true" do
|
37
|
-
|
38
|
-
interactor = ActionInteractor::Base.execute(payload)
|
32
|
+
interactor = ActionInteractor::Base.execute
|
39
33
|
assert interactor.successful?
|
40
34
|
end
|
41
35
|
|
42
36
|
test "#success? (alias) is true" do
|
43
|
-
|
44
|
-
interactor = ActionInteractor::Base.execute(payload)
|
37
|
+
interactor = ActionInteractor::Base.execute
|
45
38
|
assert interactor.success?
|
46
39
|
end
|
47
40
|
|
48
41
|
test "#finished? is true" do
|
49
|
-
|
50
|
-
interactor = ActionInteractor::Base.execute(payload)
|
42
|
+
interactor = ActionInteractor::Base.execute
|
51
43
|
assert interactor.finished?
|
52
44
|
end
|
53
45
|
|
54
46
|
test "#aborted? is true after #abort!" do
|
55
|
-
|
56
|
-
interactor = ActionInteractor::Base.new(payload)
|
47
|
+
interactor = ActionInteractor::Base.new
|
57
48
|
interactor.abort!
|
58
49
|
assert interactor.aborted?
|
59
50
|
end
|
data/test/composite_test.rb
CHANGED
@@ -32,16 +32,14 @@ end
|
|
32
32
|
|
33
33
|
class CompositeTest < Test::Unit::TestCase
|
34
34
|
test "initialized successfully" do
|
35
|
-
|
36
|
-
interactor = ActionInteractor::Composite.new(payload)
|
35
|
+
interactor = ActionInteractor::Composite.new
|
37
36
|
assert_equal(interactor.success?, false)
|
38
37
|
assert_equal(interactor.finished?, false)
|
39
38
|
assert_equal(interactor.errors.empty?, true)
|
40
39
|
end
|
41
40
|
|
42
41
|
test "add interactors" do
|
43
|
-
|
44
|
-
chief_interactor = ChiefInteractor.new(payload)
|
42
|
+
chief_interactor = ChiefInteractor.new
|
45
43
|
cook_interactor = CookInteractor.new(interactor_name: "cook")
|
46
44
|
arrange_interactor = ArrangeInteractor.new(interactor_name: "arrange")
|
47
45
|
chief_interactor.add(cook_interactor)
|
@@ -51,8 +49,7 @@ class CompositeTest < Test::Unit::TestCase
|
|
51
49
|
end
|
52
50
|
|
53
51
|
test "remove interactor" do
|
54
|
-
|
55
|
-
chief_interactor = ChiefInteractor.new(payload)
|
52
|
+
chief_interactor = ChiefInteractor.new
|
56
53
|
cook_interactor = CookInteractor.new(interactor_name: "cook")
|
57
54
|
arrange_interactor = ArrangeInteractor.new(interactor_name: "arrange")
|
58
55
|
chief_interactor.add(cook_interactor)
|
@@ -63,8 +60,7 @@ class CompositeTest < Test::Unit::TestCase
|
|
63
60
|
end
|
64
61
|
|
65
62
|
test "successful in executing all interactors" do
|
66
|
-
|
67
|
-
chief_interactor = ChiefInteractor.new(payload)
|
63
|
+
chief_interactor = ChiefInteractor.new
|
68
64
|
cook_interactor = CookInteractor.new(interactor_name: "cook")
|
69
65
|
arrange_interactor = ArrangeInteractor.new(interactor_name: "arrange")
|
70
66
|
chief_interactor.add(cook_interactor)
|
@@ -76,8 +72,7 @@ class CompositeTest < Test::Unit::TestCase
|
|
76
72
|
end
|
77
73
|
|
78
74
|
test "failure in executing the last interactor" do
|
79
|
-
|
80
|
-
chief_interactor = ChiefInteractor.new(payload)
|
75
|
+
chief_interactor = ChiefInteractor.new
|
81
76
|
cook_interactor = CookInteractor.new(interactor_name: "cook")
|
82
77
|
arrange_interactor = ArrangeInteractor.new(interactor_name: "arrange", broken_dish: true)
|
83
78
|
chief_interactor.add(cook_interactor)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actioninteractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Hashimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: 1.8.11
|
95
95
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.1.4
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Action Interactor provides a simple interface for performing operations (part
|