interactor_with_steroids 1.2.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/lib/interactor/error.rb +7 -0
- data/spec/interactor/declaration_spec.rb +36 -0
- data/spec/interactor/error_spec.rb +29 -0
- metadata +5 -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
|
data/lib/interactor/error.rb
CHANGED
@@ -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
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Interactor
|
2
|
+
describe Failure do
|
3
|
+
describe ".cause_stack" do
|
4
|
+
subject { failure.cause_stack }
|
5
|
+
|
6
|
+
let(:exception_1) { Class.new(Exception) }
|
7
|
+
let(:exception_2) { Class.new(Exception) }
|
8
|
+
let(:interactor) do
|
9
|
+
Class.new.send(:include, Interactor) do
|
10
|
+
def call
|
11
|
+
begin
|
12
|
+
raise exception_1
|
13
|
+
rescue StandardError
|
14
|
+
raise exception_2
|
15
|
+
end
|
16
|
+
rescue StandardError
|
17
|
+
context.fail!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns an empty stack" do
|
23
|
+
interactor.call!
|
24
|
+
rescue Failure => e
|
25
|
+
expect(e.cause_stack).to contain_exactly(described_class, exception_1, exception_2)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
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
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/interactor/organizer.rb
|
78
78
|
- spec/interactor/context_spec.rb
|
79
79
|
- spec/interactor/declaration_spec.rb
|
80
|
+
- spec/interactor/error_spec.rb
|
80
81
|
- spec/interactor/hooks_spec.rb
|
81
82
|
- spec/interactor/organizer_spec.rb
|
82
83
|
- spec/interactor_spec.rb
|
@@ -100,13 +101,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
101
|
- !ruby/object:Gem::Version
|
101
102
|
version: '0'
|
102
103
|
requirements: []
|
103
|
-
rubygems_version: 3.3.
|
104
|
+
rubygems_version: 3.3.7
|
104
105
|
signing_key:
|
105
106
|
specification_version: 4
|
106
107
|
summary: Simple interactor implementation
|
107
108
|
test_files:
|
108
109
|
- spec/interactor/context_spec.rb
|
109
110
|
- spec/interactor/declaration_spec.rb
|
111
|
+
- spec/interactor/error_spec.rb
|
110
112
|
- spec/interactor/hooks_spec.rb
|
111
113
|
- spec/interactor/organizer_spec.rb
|
112
114
|
- spec/interactor_spec.rb
|