actioninteractor 0.2.4 → 0.2.6
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/test/base_test.rb +9 -18
- data/test/composite_test.rb +5 -10
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00a01113647d3932b0ffce8322fe50ee90ab9107f72fb3528bcbedbd01a98b02
|
4
|
+
data.tar.gz: 98df5c50fee5474d053a306da91d2f9a6a884bad8575e708b38aaddfd045b2dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 587f1fce129817fc8bfd4b9ef935834188443583f125116d226e53431fa1415accf2793b720ec8585a7848c9760f544e3626bb17b942a3da4051c5b48f951088
|
7
|
+
data.tar.gz: c71833661aa327d4fe6fc21f7d340856fb501082e69dc4af85a43dfebcb797f7fd430e3b715f22b121b1cd7ec2330109f636f5e22f070b1bd62257f4fa8c94bf
|
@@ -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
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Hashimoto
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,7 +78,7 @@ homepage: https://github.com/ryohashimoto/lightrails
|
|
78
78
|
licenses:
|
79
79
|
- MIT
|
80
80
|
metadata: {}
|
81
|
-
post_install_message:
|
81
|
+
post_install_message:
|
82
82
|
rdoc_options: []
|
83
83
|
require_paths:
|
84
84
|
- lib
|
@@ -93,8 +93,8 @@ 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.
|
97
|
-
signing_key:
|
96
|
+
rubygems_version: 3.4.6
|
97
|
+
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Action Interactor provides a simple interface for performing operations (part
|
100
100
|
of Lightrails).
|