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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6482218b9fe304483abc4ae16d38e51c8de0cd6b9fe9c1155caaca1bff6a660c
4
- data.tar.gz: 98db252d344409893580173b7f982419db14986a598e7b772eba8bca22ce5ed6
3
+ metadata.gz: 00a01113647d3932b0ffce8322fe50ee90ab9107f72fb3528bcbedbd01a98b02
4
+ data.tar.gz: 98df5c50fee5474d053a306da91d2f9a6a884bad8575e708b38aaddfd045b2dd
5
5
  SHA512:
6
- metadata.gz: bb962e73b235f0ebe37c906d00904ee71e1efce001eeef1d3e756317c9994cc2473443629b538451c25024aeb6b6fe949b0542f0a5c324aeb92fa4fe10e9377b
7
- data.tar.gz: 6fa15f43b82685f294d5e63a5a01fdde4775cae10405c99023c48aa698ce79da9dc7ba246a337221869037e17bd9e7e8031a07ef83c2e74eb4ab1ef6d66a027d
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 empty), mark as failure.
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
@@ -13,7 +13,7 @@ module ActionInteractor
13
13
  attr_reader :interactors
14
14
 
15
15
  # Initialize with payload and an array for containing interactors.
16
- def initialize(payload)
16
+ def initialize(payload = {})
17
17
  super
18
18
  @interactors = []
19
19
  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
- payload = {}
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
- payload = {}
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
- payload = {}
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
- payload = {}
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
- payload = {}
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
- payload = {}
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
- payload = {}
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
- payload = {}
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
- payload = {}
56
- interactor = ActionInteractor::Base.new(payload)
47
+ interactor = ActionInteractor::Base.new
57
48
  interactor.abort!
58
49
  assert interactor.aborted?
59
50
  end
@@ -32,16 +32,14 @@ end
32
32
 
33
33
  class CompositeTest < Test::Unit::TestCase
34
34
  test "initialized successfully" do
35
- payload = {}
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
- payload = {}
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
- payload = {}
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
- payload = {}
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
- payload = {}
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
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: 2021-04-11 00:00:00.000000000 Z
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.1.4
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).