interactor_with_steroids 1.4.0 → 1.5.1

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: 2e5289e3868d4b8ae37dbe8078ff4c96e0206bc39e94fa465f32bf4c73bb4c65
4
- data.tar.gz: 66d785650382be1320340c0791ad9d7c2efbdbbe6245e24e9048d4d82197ca09
3
+ metadata.gz: 67bd7f73460605c15913de2b7600e2688ce69d3522aa977ebbdaa7b48dfb7174
4
+ data.tar.gz: 7ea029bbf6175cdda0daef695c3adb2203c56d2f17e071c8ae5a6d51c45db8ff
5
5
  SHA512:
6
- metadata.gz: 2208ac798a7531e5e8615683e9ed8251bc3377bd243a14047f433e672f1a5e37b869a84cc19918b9059c225211ee2eb73e211851566fc29138104238b1448e6e
7
- data.tar.gz: ac631eb1de4cea38bcae466cb0ff7726fdfb04a582b0c5f483fe106da5ad0b88c106f2cec29bbc5f529f79c61119ca92796a6ff62f22c08c0f85e003ebca74fe
6
+ metadata.gz: afe86c28c86697ed2a72a39a6fc255ed52862220a987eb86390466d2a04f50102780fe0ca62fa1ec2f54ae257e5f388235d00fd14e17d2f58616bf34c8bbf9f0
7
+ data.tar.gz: a5c27b60c2f6058d079d2962035866bea1587e2183d1ac66219410dc42d6d5666b1f231e50cbc5eec9b5b6e9c516b9674d92d065e72ae36a758fedbeed27d8de
data/interactor.gemspec CHANGED
@@ -2,7 +2,7 @@ require "English"
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "interactor_with_steroids"
5
- spec.version = "1.4.0"
5
+ spec.version = "1.5.1"
6
6
 
7
7
  spec.author = "Collective Idea/Sorare Team"
8
8
  spec.email = "hello@sorare.com"
@@ -18,6 +18,9 @@ module Interactor
18
18
  new_required_arguments = required_arguments - @required_arguments
19
19
  @required_arguments += new_required_arguments
20
20
 
21
+ required_arguments.each { |arg| received_arguments << arg }
22
+ optional_arguments.keys.each { |arg| received_optional_arguments << arg }
23
+
21
24
  delegate(*new_required_arguments, to: :context) unless new_required_arguments.empty?
22
25
  delegate(*optional_arguments.keys, to: :context) unless optional_arguments.empty?
23
26
 
@@ -63,10 +66,20 @@ module Interactor
63
66
  end
64
67
  end
65
68
 
69
+ def received_arguments
70
+ @received_arguments ||= []
71
+ end
72
+
73
+ def received_optional_arguments
74
+ @received_optional_arguments ||= []
75
+ end
76
+
66
77
  def hold(*held_fields, **held_fields_with_default_value)
67
78
  attributes = [*held_fields, *held_fields_with_default_value.keys]
68
79
  delegate(*attributes, to: :context)
69
80
 
81
+ attributes.each { |attr| held_attributes << attr }
82
+
70
83
  self.context_class = Class.new(context_class) do
71
84
  attr_accessor *held_fields
72
85
  attr_writer *held_fields_with_default_value.keys
@@ -88,6 +101,10 @@ module Interactor
88
101
  end
89
102
 
90
103
  end
104
+
105
+ def held_attributes
106
+ @held_attributes ||= []
107
+ end
91
108
  end
92
109
  end
93
110
  end
@@ -14,22 +14,26 @@ module Interactor
14
14
 
15
15
  subject { declared.context_class }
16
16
 
17
- describe "#receive" do
18
- context "with a required argument" do
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 "cannot be initialized without foo" do
25
+ it 'cannot be initialized without foo' do
26
26
  expect { subject.build }.to raise_error(ArgumentError)
27
27
  end
28
28
 
29
- it "can be initialized with foo" do
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,84 +45,88 @@ 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("Submodule", submodule) }
56
+ before { stub_const('Submodule', submodule) }
53
57
 
54
- it "can be initialized with foo" do
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 "with an optional argument" do
62
- context "with a constant default value" do
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 "can be initialized without foo" do
72
+ it 'can be initialized without foo' do
70
73
  expect(subject.build.foo).to eq('bar')
71
74
  end
72
75
 
73
- it "can be initialized with foo" do
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 "can be initialized with nil" do
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 "with a nil default value" do
83
- let(:declared) {
85
+ context 'with a nil default value' do
86
+ let(:declared) do
84
87
  build_declared do
85
88
  receive foo: nil
86
89
  end
87
- }
90
+ end
88
91
 
89
- it "can be initialized without foo" do
92
+ it 'can be initialized without foo' do
90
93
  expect(subject.build.foo).to be nil
91
94
  end
92
95
 
93
- it "can be initialized with foo" do
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 "with a Proc default value" do
99
- let(:declared) {
101
+ context 'with a Proc default value' do
102
+ let(:declared) do
100
103
  build_declared do
101
104
  receive :bar, foo: ->(context) { context.bar }
102
105
  end
103
- }
106
+ end
104
107
 
105
- it "can be initialized without foo" do
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 "can be initialized with foo" do
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])
118
+ expect(declared.received_optional_arguments).to eq(%i[foo])
119
+ end
112
120
  end
113
121
  end
114
122
  end
115
123
 
116
- describe "#hold" do
117
- let(:declared) {
124
+ describe '#hold' do
125
+ let(:declared) do
118
126
  build_declared do
119
127
  hold :foo
120
128
  end
121
- }
129
+ end
122
130
 
123
131
  it 'can hold foo' do
124
132
  c = subject.build
@@ -126,12 +134,16 @@ module Interactor
126
134
  expect(c.foo).to eq('bar')
127
135
  end
128
136
 
137
+ it 'can introspect the held attributes' do
138
+ expect(declared.held_attributes).to eq([:foo])
139
+ end
140
+
129
141
  context 'with default value' do
130
- let(:declared) {
142
+ let(:declared) do
131
143
  build_declared do
132
144
  hold foo: 'bar'
133
145
  end
134
- }
146
+ end
135
147
 
136
148
  it 'can hold foo with default value' do
137
149
  c = subject.build
@@ -141,12 +153,12 @@ module Interactor
141
153
  expect(c.foo).to eq('baz')
142
154
  end
143
155
 
144
- context 'when default value is a proc' do
145
- let(:declared) {
156
+ context 'when default value is a proc' do
157
+ let(:declared) do
146
158
  build_declared do
147
159
  hold foo: proc { [] }
148
160
  end
149
- }
161
+ end
150
162
 
151
163
  it 'can hold foo with default value different for each new context through proc' do
152
164
  c = subject.build
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.0
4
+ version: 1.5.1
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-01-04 00:00:00.000000000 Z
11
+ date: 2023-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport