interactor_with_steroids 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/interactor.gemspec +1 -1
- data/lib/interactor/declaration.rb +12 -0
- data/spec/interactor/declaration_spec.rb +37 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a641ca1acbb8c2de2ec87757ef54c644189997860477ccdbfd138ded126ccd3b
|
4
|
+
data.tar.gz: c5d85b0aa88784f4b60c5dafbc49338d7508674f589528a75671568dcc697383
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e703700a5efd8100e78c846fd31aa9b6ee1bd535608f8bfb92f6d8512804e279e73b2a62f2b9d70bcd822a1cbd1e0ad16012d6d874aa519bf2edf32682c209b4
|
7
|
+
data.tar.gz: 55c97b6ad6da3e4f9f35ccc6be6df32414e8bf12a00c3c865af9fe72dfa3d19ab895e53d1bf7fd182b3994d91dbbb0aeb7f57de7097edeca67c68bcc7ccaf84b
|
data/interactor.gemspec
CHANGED
@@ -18,6 +18,8 @@ module Interactor
|
|
18
18
|
new_required_arguments = required_arguments - @required_arguments
|
19
19
|
@required_arguments += new_required_arguments
|
20
20
|
|
21
|
+
(required_arguments + optional_arguments.keys).each { |arg| received_arguments << arg }
|
22
|
+
|
21
23
|
delegate(*new_required_arguments, to: :context) unless new_required_arguments.empty?
|
22
24
|
delegate(*optional_arguments.keys, to: :context) unless optional_arguments.empty?
|
23
25
|
|
@@ -63,10 +65,16 @@ module Interactor
|
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
68
|
+
def received_arguments
|
69
|
+
@received_arguments ||= []
|
70
|
+
end
|
71
|
+
|
66
72
|
def hold(*held_fields, **held_fields_with_default_value)
|
67
73
|
attributes = [*held_fields, *held_fields_with_default_value.keys]
|
68
74
|
delegate(*attributes, to: :context)
|
69
75
|
|
76
|
+
attributes.each { |attr| held_attributes << attr }
|
77
|
+
|
70
78
|
self.context_class = Class.new(context_class) do
|
71
79
|
attr_accessor *held_fields
|
72
80
|
attr_writer *held_fields_with_default_value.keys
|
@@ -88,6 +96,10 @@ module Interactor
|
|
88
96
|
end
|
89
97
|
|
90
98
|
end
|
99
|
+
|
100
|
+
def held_attributes
|
101
|
+
@held_attributes ||= []
|
102
|
+
end
|
91
103
|
end
|
92
104
|
end
|
93
105
|
end
|
@@ -14,22 +14,26 @@ module Interactor
|
|
14
14
|
|
15
15
|
subject { declared.context_class }
|
16
16
|
|
17
|
-
describe
|
18
|
-
context
|
19
|
-
let(:declared)
|
17
|
+
describe '#receive' do
|
18
|
+
context 'with a required argument' do
|
19
|
+
let(:declared) do
|
20
20
|
build_declared do
|
21
21
|
receive :foo
|
22
22
|
end
|
23
|
-
|
23
|
+
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it 'cannot be initialized without foo' do
|
26
26
|
expect { subject.build }.to raise_error(ArgumentError)
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'can be initialized with foo' do
|
30
30
|
expect(subject.build(foo: 'bar').foo).to eq('bar')
|
31
31
|
end
|
32
32
|
|
33
|
+
it 'can introspect the received arguments' do
|
34
|
+
expect(declared.received_arguments).to eq([:foo])
|
35
|
+
end
|
36
|
+
|
33
37
|
context 'when duplicated in a submodule' do
|
34
38
|
let(:submodule) do
|
35
39
|
Module.new do
|
@@ -41,79 +45,82 @@ module Interactor
|
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
let(:declared)
|
48
|
+
let(:declared) do
|
45
49
|
build_declared do
|
46
50
|
include Submodule
|
47
51
|
|
48
52
|
receive :foo
|
49
53
|
end
|
50
|
-
|
54
|
+
end
|
51
55
|
|
52
|
-
before { stub_const(
|
56
|
+
before { stub_const('Submodule', submodule) }
|
53
57
|
|
54
|
-
it
|
58
|
+
it 'can be initialized with foo' do
|
55
59
|
expect(subject.build(foo: 'bar').foo).to eq('bar')
|
56
60
|
end
|
57
61
|
end
|
58
|
-
|
59
62
|
end
|
60
63
|
|
61
|
-
context
|
62
|
-
context
|
63
|
-
let(:declared)
|
64
|
+
context 'with an optional argument' do
|
65
|
+
context 'with a constant default value' do
|
66
|
+
let(:declared) do
|
64
67
|
build_declared do
|
65
68
|
receive foo: 'bar'
|
66
69
|
end
|
67
|
-
|
70
|
+
end
|
68
71
|
|
69
|
-
it
|
72
|
+
it 'can be initialized without foo' do
|
70
73
|
expect(subject.build.foo).to eq('bar')
|
71
74
|
end
|
72
75
|
|
73
|
-
it
|
76
|
+
it 'can be initialized with foo' do
|
74
77
|
expect(subject.build(foo: 'baz').foo).to eq('baz')
|
75
78
|
end
|
76
79
|
|
77
|
-
it
|
80
|
+
it 'can be initialized with nil' do
|
78
81
|
expect(subject.build(foo: nil).foo).to be nil
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
82
|
-
context
|
85
|
+
context 'with a nil default value' do
|
83
86
|
let(:declared) {
|
84
87
|
build_declared do
|
85
88
|
receive foo: nil
|
86
89
|
end
|
87
90
|
}
|
88
91
|
|
89
|
-
it
|
92
|
+
it 'can be initialized without foo' do
|
90
93
|
expect(subject.build.foo).to be nil
|
91
94
|
end
|
92
95
|
|
93
|
-
it
|
96
|
+
it 'can be initialized with foo' do
|
94
97
|
expect(subject.build(foo: 'baz').foo).to eq('baz')
|
95
98
|
end
|
96
99
|
end
|
97
100
|
|
98
|
-
context
|
101
|
+
context 'with a Proc default value' do
|
99
102
|
let(:declared) {
|
100
103
|
build_declared do
|
101
104
|
receive :bar, foo: ->(context) { context.bar }
|
102
105
|
end
|
103
106
|
}
|
104
107
|
|
105
|
-
it
|
108
|
+
it 'can be initialized without foo' do
|
106
109
|
expect(subject.build(bar: 'bar').foo).to eq('bar')
|
107
110
|
end
|
108
111
|
|
109
|
-
it
|
112
|
+
it 'can be initialized with foo' do
|
110
113
|
expect(subject.build(bar: 'bar', foo: 'baz').foo).to eq('baz')
|
111
114
|
end
|
115
|
+
|
116
|
+
it 'can introspect the received arguments' do
|
117
|
+
expect(declared.received_arguments).to eq(%i[bar foo])
|
118
|
+
end
|
112
119
|
end
|
113
120
|
end
|
114
121
|
end
|
115
122
|
|
116
|
-
describe
|
123
|
+
describe '#hold' do
|
117
124
|
let(:declared) {
|
118
125
|
build_declared do
|
119
126
|
hold :foo
|
@@ -126,6 +133,10 @@ module Interactor
|
|
126
133
|
expect(c.foo).to eq('bar')
|
127
134
|
end
|
128
135
|
|
136
|
+
it 'can introspect the held attributes' do
|
137
|
+
expect(declared.held_attributes).to eq([:foo])
|
138
|
+
end
|
139
|
+
|
129
140
|
context 'with default value' do
|
130
141
|
let(:declared) {
|
131
142
|
build_declared do
|
@@ -141,7 +152,7 @@ module Interactor
|
|
141
152
|
expect(c.foo).to eq('baz')
|
142
153
|
end
|
143
154
|
|
144
|
-
context 'when default value is a proc' do
|
155
|
+
context 'when default value is a proc' do
|
145
156
|
let(:declared) {
|
146
157
|
build_declared do
|
147
158
|
hold foo: proc { [] }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interactor_with_steroids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Collective Idea/Sorare Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|