interactor_with_steroids 1.0.0 → 1.1.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/context.rb +11 -6
- data/lib/interactor/declaration.rb +10 -10
- data/spec/interactor/declaration_spec.rb +11 -11
- 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: d16db7c2aa725346ef74ec5025bf6a3997e977c1d270b58db4041aa1ddd1b3c8
|
4
|
+
data.tar.gz: 3cd4d95ed845f5529dcedb0df3b7f3e74c87e8fd5811619434a81e690243715d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1a785d1bf09cbdc6c11dd36503d1396cdc88f32f05c11c7888324562fd5e62a6303dda64de8df7730200646bd8d3c8d3eadc832af68be5ce7f687e813812bf6
|
7
|
+
data.tar.gz: 2e14390b06e5efaad86ffcffcee498e681175f5fbbd192fb5de37e3a6401f799d1555a8a6ab9351714af44912733549261dd536c3db7c4e253bbbead4f8ac715
|
data/interactor.gemspec
CHANGED
data/lib/interactor/context.rb
CHANGED
@@ -53,15 +53,14 @@ module Interactor
|
|
53
53
|
#
|
54
54
|
# Returns the Interactor::Context.
|
55
55
|
def self.build(context = {})
|
56
|
-
new
|
56
|
+
new.tap do |instance|
|
57
|
+
instance.assign_attributes(context.to_h)
|
58
|
+
end
|
57
59
|
end
|
58
60
|
|
59
61
|
attr_accessor :error
|
60
62
|
delegate :to_s, to: :to_h
|
61
63
|
|
62
|
-
def initialize(*)
|
63
|
-
end
|
64
|
-
|
65
64
|
# Public: Whether the Interactor::Context is successful. By default, a new
|
66
65
|
# context is successful and only changes when explicitly failed.
|
67
66
|
#
|
@@ -126,12 +125,18 @@ module Interactor
|
|
126
125
|
# # => Interactor::Failure: #<Interactor::Context foo="baz">
|
127
126
|
#
|
128
127
|
# Raises Interactor::Failure initialized with the Interactor::Context.
|
129
|
-
def fail!(
|
130
|
-
|
128
|
+
def fail!(params = {})
|
129
|
+
assign_attributes(params)
|
131
130
|
@failure = true
|
132
131
|
raise Failure, self
|
133
132
|
end
|
134
133
|
|
134
|
+
def assign_attributes(params)
|
135
|
+
params.each do |attribute, value|
|
136
|
+
self.send("#{attribute}=", value)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
135
140
|
def to_h
|
136
141
|
{ error: error }
|
137
142
|
end
|
@@ -37,19 +37,19 @@ module Interactor
|
|
37
37
|
end
|
38
38
|
|
39
39
|
class_eval %Q<
|
40
|
-
def
|
40
|
+
def self.build(
|
41
41
|
#{new_required_arguments.map { |a| "#{a}:" }.join(', ')}#{new_required_arguments.empty? ? '' : ', '}
|
42
42
|
**rest
|
43
43
|
)
|
44
|
-
super(**rest)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
super(**rest).tap do |instance|
|
45
|
+
#{new_required_arguments.map { |a| "instance.#{a} = #{a}" }.join(';')}
|
46
|
+
|
47
|
+
#{
|
48
|
+
optional_arguments.keys.map do |k|
|
49
|
+
"instance.instance_variable_set('@#{k}', rest[:#{k}]) if rest.key?(:#{k})"
|
50
|
+
end.join("\n")
|
51
|
+
}
|
52
|
+
end
|
53
53
|
end
|
54
54
|
>
|
55
55
|
|
@@ -23,11 +23,11 @@ module Interactor
|
|
23
23
|
}
|
24
24
|
|
25
25
|
it "cannot be initialized without foo" do
|
26
|
-
expect { subject.
|
26
|
+
expect { subject.build }.to raise_error(ArgumentError)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "can be initialized with foo" do
|
30
|
-
expect(subject.
|
30
|
+
expect(subject.build(foo: 'bar').foo).to eq('bar')
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'when duplicated in a submodule' do
|
@@ -52,7 +52,7 @@ module Interactor
|
|
52
52
|
before { stub_const("Submodule", submodule) }
|
53
53
|
|
54
54
|
it "can be initialized with foo" do
|
55
|
-
expect(subject.
|
55
|
+
expect(subject.build(foo: 'bar').foo).to eq('bar')
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -67,15 +67,15 @@ module Interactor
|
|
67
67
|
}
|
68
68
|
|
69
69
|
it "can be initialized without foo" do
|
70
|
-
expect(subject.
|
70
|
+
expect(subject.build.foo).to eq('bar')
|
71
71
|
end
|
72
72
|
|
73
73
|
it "can be initialized with foo" do
|
74
|
-
expect(subject.
|
74
|
+
expect(subject.build(foo: 'baz').foo).to eq('baz')
|
75
75
|
end
|
76
76
|
|
77
77
|
it "can be initialized with nil" do
|
78
|
-
expect(subject.
|
78
|
+
expect(subject.build(foo: nil).foo).to be nil
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -87,11 +87,11 @@ module Interactor
|
|
87
87
|
}
|
88
88
|
|
89
89
|
it "can be initialized without foo" do
|
90
|
-
expect(subject.
|
90
|
+
expect(subject.build.foo).to be nil
|
91
91
|
end
|
92
92
|
|
93
93
|
it "can be initialized with foo" do
|
94
|
-
expect(subject.
|
94
|
+
expect(subject.build(foo: 'baz').foo).to eq('baz')
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -103,11 +103,11 @@ module Interactor
|
|
103
103
|
}
|
104
104
|
|
105
105
|
it "can be initialized without foo" do
|
106
|
-
expect(subject.
|
106
|
+
expect(subject.build(bar: 'bar').foo).to eq('bar')
|
107
107
|
end
|
108
108
|
|
109
109
|
it "can be initialized with foo" do
|
110
|
-
expect(subject.
|
110
|
+
expect(subject.build(bar: 'bar', foo: 'baz').foo).to eq('baz')
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
@@ -121,7 +121,7 @@ module Interactor
|
|
121
121
|
}
|
122
122
|
|
123
123
|
it 'can hold foo' do
|
124
|
-
c = subject.
|
124
|
+
c = subject.build
|
125
125
|
c.foo = 'bar'
|
126
126
|
expect(c.foo).to eq('bar')
|
127
127
|
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.1.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: 2022-01-
|
11
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|