interactor_with_steroids 1.5.0 → 1.5.1
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 +6 -1
- data/spec/interactor/declaration_spec.rb +12 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67bd7f73460605c15913de2b7600e2688ce69d3522aa977ebbdaa7b48dfb7174
|
4
|
+
data.tar.gz: 7ea029bbf6175cdda0daef695c3adb2203c56d2f17e071c8ae5a6d51c45db8ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afe86c28c86697ed2a72a39a6fc255ed52862220a987eb86390466d2a04f50102780fe0ca62fa1ec2f54ae257e5f388235d00fd14e17d2f58616bf34c8bbf9f0
|
7
|
+
data.tar.gz: a5c27b60c2f6058d079d2962035866bea1587e2183d1ac66219410dc42d6d5666b1f231e50cbc5eec9b5b6e9c516b9674d92d065e72ae36a758fedbeed27d8de
|
data/interactor.gemspec
CHANGED
@@ -18,7 +18,8 @@ module Interactor
|
|
18
18
|
new_required_arguments = required_arguments - @required_arguments
|
19
19
|
@required_arguments += new_required_arguments
|
20
20
|
|
21
|
-
|
21
|
+
required_arguments.each { |arg| received_arguments << arg }
|
22
|
+
optional_arguments.keys.each { |arg| received_optional_arguments << arg }
|
22
23
|
|
23
24
|
delegate(*new_required_arguments, to: :context) unless new_required_arguments.empty?
|
24
25
|
delegate(*optional_arguments.keys, to: :context) unless optional_arguments.empty?
|
@@ -69,6 +70,10 @@ module Interactor
|
|
69
70
|
@received_arguments ||= []
|
70
71
|
end
|
71
72
|
|
73
|
+
def received_optional_arguments
|
74
|
+
@received_optional_arguments ||= []
|
75
|
+
end
|
76
|
+
|
72
77
|
def hold(*held_fields, **held_fields_with_default_value)
|
73
78
|
attributes = [*held_fields, *held_fields_with_default_value.keys]
|
74
79
|
delegate(*attributes, to: :context)
|
@@ -83,11 +83,11 @@ module Interactor
|
|
83
83
|
end
|
84
84
|
|
85
85
|
context 'with a nil default value' do
|
86
|
-
let(:declared)
|
86
|
+
let(:declared) do
|
87
87
|
build_declared do
|
88
88
|
receive foo: nil
|
89
89
|
end
|
90
|
-
|
90
|
+
end
|
91
91
|
|
92
92
|
it 'can be initialized without foo' do
|
93
93
|
expect(subject.build.foo).to be nil
|
@@ -99,11 +99,11 @@ module Interactor
|
|
99
99
|
end
|
100
100
|
|
101
101
|
context 'with a Proc default value' do
|
102
|
-
let(:declared)
|
102
|
+
let(:declared) do
|
103
103
|
build_declared do
|
104
104
|
receive :bar, foo: ->(context) { context.bar }
|
105
105
|
end
|
106
|
-
|
106
|
+
end
|
107
107
|
|
108
108
|
it 'can be initialized without foo' do
|
109
109
|
expect(subject.build(bar: 'bar').foo).to eq('bar')
|
@@ -114,18 +114,19 @@ module Interactor
|
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'can introspect the received arguments' do
|
117
|
-
expect(declared.received_arguments).to eq(%i[bar
|
117
|
+
expect(declared.received_arguments).to eq(%i[bar])
|
118
|
+
expect(declared.received_optional_arguments).to eq(%i[foo])
|
118
119
|
end
|
119
120
|
end
|
120
121
|
end
|
121
122
|
end
|
122
123
|
|
123
124
|
describe '#hold' do
|
124
|
-
let(:declared)
|
125
|
+
let(:declared) do
|
125
126
|
build_declared do
|
126
127
|
hold :foo
|
127
128
|
end
|
128
|
-
|
129
|
+
end
|
129
130
|
|
130
131
|
it 'can hold foo' do
|
131
132
|
c = subject.build
|
@@ -138,11 +139,11 @@ module Interactor
|
|
138
139
|
end
|
139
140
|
|
140
141
|
context 'with default value' do
|
141
|
-
let(:declared)
|
142
|
+
let(:declared) do
|
142
143
|
build_declared do
|
143
144
|
hold foo: 'bar'
|
144
145
|
end
|
145
|
-
|
146
|
+
end
|
146
147
|
|
147
148
|
it 'can hold foo with default value' do
|
148
149
|
c = subject.build
|
@@ -153,11 +154,11 @@ module Interactor
|
|
153
154
|
end
|
154
155
|
|
155
156
|
context 'when default value is a proc' do
|
156
|
-
let(:declared)
|
157
|
+
let(:declared) do
|
157
158
|
build_declared do
|
158
159
|
hold foo: proc { [] }
|
159
160
|
end
|
160
|
-
|
161
|
+
end
|
161
162
|
|
162
163
|
it 'can hold foo with default value different for each new context through proc' do
|
163
164
|
c = subject.build
|