interactor_with_steroids 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5950fda4e46e568c276b41e623411ae08073b2a02867b60c2f3afe420696baf0
4
- data.tar.gz: 882a09e58b5284d9fa742ca470c31fb6ce6be9c63a1653914772457c1ff78606
3
+ metadata.gz: d16db7c2aa725346ef74ec5025bf6a3997e977c1d270b58db4041aa1ddd1b3c8
4
+ data.tar.gz: 3cd4d95ed845f5529dcedb0df3b7f3e74c87e8fd5811619434a81e690243715d
5
5
  SHA512:
6
- metadata.gz: 3f4b9cb3c6aa2405b8f59bb5c01edd5524233e2f094cfee2c42e2a563cc10474db78aa287b6480d2697c90c3377b2a5c1887e67ceb96b5ca5d2944c5ac5bf658
7
- data.tar.gz: cac7cb2a8d7139e8112bc4d18a72cd0dc488ef30d2c991953049d50c67f4f496853a9d8b56aa0254dba0fab147467a89db00c87bf9f1e084a09016851b531d1b
6
+ metadata.gz: d1a785d1bf09cbdc6c11dd36503d1396cdc88f32f05c11c7888324562fd5e62a6303dda64de8df7730200646bd8d3c8d3eadc832af68be5ce7f687e813812bf6
7
+ data.tar.gz: 2e14390b06e5efaad86ffcffcee498e681175f5fbbd192fb5de37e3a6401f799d1555a8a6ab9351714af44912733549261dd536c3db7c4e253bbbead4f8ac715
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.0.0"
5
+ spec.version = "1.1.0"
6
6
 
7
7
  spec.author = "Collective Idea/Sorare Team"
8
8
  spec.email = "hello@sorare.com"
@@ -53,15 +53,14 @@ module Interactor
53
53
  #
54
54
  # Returns the Interactor::Context.
55
55
  def self.build(context = {})
56
- new(**context.to_h)
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!(error: nil)
130
- self.error = error
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 initialize(
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
- #{new_required_arguments.map { |a| "self.#{a} = #{a}" }.join(';')}
47
-
48
- #{
49
- optional_arguments.keys.map do |k|
50
- "instance_variable_set('@#{k}', rest[:#{k}]) if rest.key?(:#{k})"
51
- end.join("\n")
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.new }.to raise_error(ArgumentError)
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.new(foo: 'bar').foo).to eq('bar')
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.new(foo: 'bar').foo).to eq('bar')
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.new.foo).to eq('bar')
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.new(foo: 'baz').foo).to eq('baz')
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.new(foo: nil).foo).to be nil
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.new.foo).to be nil
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.new(foo: 'baz').foo).to eq('baz')
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.new(bar: 'bar').foo).to eq('bar')
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.new(bar: 'bar', foo: 'baz').foo).to eq('baz')
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.new
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.0.0
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 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport