interactor_with_steroids 1.3.0 → 1.4.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 +14 -6
- data/spec/interactor/declaration_spec.rb +36 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e5289e3868d4b8ae37dbe8078ff4c96e0206bc39e94fa465f32bf4c73bb4c65
|
4
|
+
data.tar.gz: 66d785650382be1320340c0791ad9d7c2efbdbbe6245e24e9048d4d82197ca09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2208ac798a7531e5e8615683e9ed8251bc3377bd243a14047f433e672f1a5e37b869a84cc19918b9059c225211ee2eb73e211851566fc29138104238b1448e6e
|
7
|
+
data.tar.gz: ac631eb1de4cea38bcae466cb0ff7726fdfb04a582b0c5f483fe106da5ad0b88c106f2cec29bbc5f529f79c61119ca92796a6ff62f22c08c0f85e003ebca74fe
|
data/interactor.gemspec
CHANGED
@@ -63,18 +63,26 @@ module Interactor
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
def hold(*held_fields)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
delegate(*@held_fields, to: :context)
|
66
|
+
def hold(*held_fields, **held_fields_with_default_value)
|
67
|
+
attributes = [*held_fields, *held_fields_with_default_value.keys]
|
68
|
+
delegate(*attributes, to: :context)
|
71
69
|
|
72
70
|
self.context_class = Class.new(context_class) do
|
73
71
|
attr_accessor *held_fields
|
72
|
+
attr_writer *held_fields_with_default_value.keys
|
73
|
+
|
74
|
+
held_fields_with_default_value.each do |k, v|
|
75
|
+
define_method(k) do
|
76
|
+
ivar = "@#{k}"
|
77
|
+
return instance_variable_get(ivar) if instance_variable_defined?(ivar)
|
78
|
+
|
79
|
+
instance_variable_set(ivar, v.is_a?(Proc) ? instance_eval(&v) : v)
|
80
|
+
end
|
81
|
+
end
|
74
82
|
|
75
83
|
class_eval %Q<
|
76
84
|
def to_h
|
77
|
-
super.merge(#{
|
85
|
+
super.merge(#{attributes.map { |f| "#{f}: self.#{f}"}.join(', ')})
|
78
86
|
end
|
79
87
|
>
|
80
88
|
end
|
@@ -125,6 +125,42 @@ module Interactor
|
|
125
125
|
c.foo = 'bar'
|
126
126
|
expect(c.foo).to eq('bar')
|
127
127
|
end
|
128
|
+
|
129
|
+
context 'with default value' do
|
130
|
+
let(:declared) {
|
131
|
+
build_declared do
|
132
|
+
hold foo: 'bar'
|
133
|
+
end
|
134
|
+
}
|
135
|
+
|
136
|
+
it 'can hold foo with default value' do
|
137
|
+
c = subject.build
|
138
|
+
expect(c.foo).to eq('bar')
|
139
|
+
|
140
|
+
c.foo = 'baz'
|
141
|
+
expect(c.foo).to eq('baz')
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when default value is a proc' do
|
145
|
+
let(:declared) {
|
146
|
+
build_declared do
|
147
|
+
hold foo: proc { [] }
|
148
|
+
end
|
149
|
+
}
|
150
|
+
|
151
|
+
it 'can hold foo with default value different for each new context through proc' do
|
152
|
+
c = subject.build
|
153
|
+
expect(c.foo).to eq([])
|
154
|
+
|
155
|
+
other_c = subject.build
|
156
|
+
expect(other_c.foo).to eq([])
|
157
|
+
|
158
|
+
c.foo << 'baz'
|
159
|
+
expect(c.foo).to eq(['baz'])
|
160
|
+
expect(other_c.foo).to eq([])
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
128
164
|
end
|
129
165
|
end
|
130
166
|
end
|
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.4.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:
|
11
|
+
date: 2023-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
|
-
rubygems_version: 3.3.
|
104
|
+
rubygems_version: 3.3.7
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Simple interactor implementation
|