interaktor 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/publish.yml +0 -1
- data/.github/workflows/tests.yml +5 -5
- data/.gitignore +3 -0
- data/Gemfile +1 -1
- data/Gemfile.ci +6 -0
- data/README.md +65 -29
- data/interaktor.gemspec +3 -2
- data/lib/interaktor.rb +11 -16
- data/lib/interaktor/callable.rb +235 -108
- data/lib/interaktor/error/attribute_error.rb +3 -1
- data/lib/interaktor/error/attribute_schema_validation_error.rb +54 -0
- data/lib/interaktor/error/missing_explicit_success_error.rb +5 -0
- data/lib/interaktor/error/option_error.rb +3 -1
- data/lib/interaktor/error/organizer_missing_passed_attribute_error.rb +21 -0
- data/lib/interaktor/error/organizer_success_attribute_missing_error.rb +20 -0
- data/lib/interaktor/organizer.rb +33 -7
- data/spec/integration_spec.rb +142 -71
- data/spec/{interactor → interaktor}/context_spec.rb +1 -1
- data/spec/{interactor → interaktor}/hooks_spec.rb +1 -1
- data/spec/interaktor/organizer_spec.rb +249 -0
- data/spec/interaktor_spec.rb +2 -2
- data/spec/spec_helper.rb +20 -0
- data/spec/support/helpers.rb +14 -0
- data/spec/support/lint.rb +403 -166
- metadata +31 -12
- data/.travis.yml +0 -14
- data/lib/interaktor/error/missing_attribute_error.rb +0 -5
- data/spec/interactor/organizer_spec.rb +0 -128
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interaktor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Thurlow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-schema
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: zeitwerk
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +53,7 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '13.0'
|
41
55
|
description: A common interface for building service objects.
|
42
|
-
email:
|
56
|
+
email: thurlow@hey.com
|
43
57
|
executables: []
|
44
58
|
extensions: []
|
45
59
|
extra_rdoc_files: []
|
@@ -50,8 +64,8 @@ files:
|
|
50
64
|
- ".rspec"
|
51
65
|
- ".rubocop.yml"
|
52
66
|
- ".ruby-version"
|
53
|
-
- ".travis.yml"
|
54
67
|
- Gemfile
|
68
|
+
- Gemfile.ci
|
55
69
|
- Guardfile
|
56
70
|
- README.md
|
57
71
|
- Rakefile
|
@@ -60,21 +74,25 @@ files:
|
|
60
74
|
- lib/interaktor/callable.rb
|
61
75
|
- lib/interaktor/context.rb
|
62
76
|
- lib/interaktor/error/attribute_error.rb
|
77
|
+
- lib/interaktor/error/attribute_schema_validation_error.rb
|
63
78
|
- lib/interaktor/error/base.rb
|
64
79
|
- lib/interaktor/error/disallowed_attribute_assignment_error.rb
|
65
|
-
- lib/interaktor/error/
|
80
|
+
- lib/interaktor/error/missing_explicit_success_error.rb
|
66
81
|
- lib/interaktor/error/option_error.rb
|
82
|
+
- lib/interaktor/error/organizer_missing_passed_attribute_error.rb
|
83
|
+
- lib/interaktor/error/organizer_success_attribute_missing_error.rb
|
67
84
|
- lib/interaktor/error/unknown_attribute_error.rb
|
68
85
|
- lib/interaktor/error/unknown_option_error.rb
|
69
86
|
- lib/interaktor/failure.rb
|
70
87
|
- lib/interaktor/hooks.rb
|
71
88
|
- lib/interaktor/organizer.rb
|
72
89
|
- spec/integration_spec.rb
|
73
|
-
- spec/
|
74
|
-
- spec/
|
75
|
-
- spec/
|
90
|
+
- spec/interaktor/context_spec.rb
|
91
|
+
- spec/interaktor/hooks_spec.rb
|
92
|
+
- spec/interaktor/organizer_spec.rb
|
76
93
|
- spec/interaktor_spec.rb
|
77
94
|
- spec/spec_helper.rb
|
95
|
+
- spec/support/helpers.rb
|
78
96
|
- spec/support/lint.rb
|
79
97
|
homepage: https://github.com/taylorthurlow/interaktor
|
80
98
|
licenses:
|
@@ -96,15 +114,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
114
|
version: '0'
|
97
115
|
requirements: []
|
98
116
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.7.6.
|
117
|
+
rubygems_version: 2.7.6.3
|
100
118
|
signing_key:
|
101
119
|
specification_version: 4
|
102
120
|
summary: Simple service object implementation
|
103
121
|
test_files:
|
104
122
|
- spec/integration_spec.rb
|
105
|
-
- spec/
|
106
|
-
- spec/
|
107
|
-
- spec/
|
123
|
+
- spec/interaktor/context_spec.rb
|
124
|
+
- spec/interaktor/hooks_spec.rb
|
125
|
+
- spec/interaktor/organizer_spec.rb
|
108
126
|
- spec/interaktor_spec.rb
|
109
127
|
- spec/spec_helper.rb
|
128
|
+
- spec/support/helpers.rb
|
110
129
|
- spec/support/lint.rb
|
data/.travis.yml
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
module Interaktor
|
2
|
-
describe Organizer do
|
3
|
-
let(:organizer) { Class.new.include(described_class) }
|
4
|
-
|
5
|
-
include_examples "lint"
|
6
|
-
|
7
|
-
describe ".organize" do
|
8
|
-
let(:interaktor2) { instance_double(Interaktor) }
|
9
|
-
let(:interaktor3) { instance_double(Interaktor) }
|
10
|
-
|
11
|
-
it "sets interaktors given class arguments" do
|
12
|
-
expect {
|
13
|
-
organizer.organize(interaktor2, interaktor3)
|
14
|
-
}.to change(organizer, :organized).from([]).to([interaktor2, interaktor3])
|
15
|
-
end
|
16
|
-
|
17
|
-
it "sets interaktors given an array of classes" do
|
18
|
-
expect {
|
19
|
-
organizer.organize([interaktor2, interaktor3])
|
20
|
-
}.to change(organizer, :organized).from([]).to([interaktor2, interaktor3])
|
21
|
-
end
|
22
|
-
|
23
|
-
it "allows multiple organize calls" do
|
24
|
-
interaktor4 = instance_double(Interaktor)
|
25
|
-
expect {
|
26
|
-
organizer.organize(interaktor2, interaktor3)
|
27
|
-
organizer.organize(interaktor4)
|
28
|
-
}.to change(organizer, :organized).from([]).to([interaktor2, interaktor3, interaktor4])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe ".organized" do
|
33
|
-
it "is empty by default" do
|
34
|
-
expect(organizer.organized).to eq([])
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#call" do
|
39
|
-
it "calls each interaktor in order" do
|
40
|
-
organizer.class_eval { required :foo }
|
41
|
-
|
42
|
-
interaktor2 = Class.new.include(Interaktor)
|
43
|
-
interaktor2.class_eval { required :foo }
|
44
|
-
interaktor2.define_method(:call) { self.foo = "bar" }
|
45
|
-
|
46
|
-
interaktor3 = Class.new.include(Interaktor)
|
47
|
-
interaktor3.class_eval { required :foo }
|
48
|
-
interaktor3.define_method(:call) { self.foo = "baz" }
|
49
|
-
|
50
|
-
interaktor4 = Class.new.include(Interaktor)
|
51
|
-
interaktor4.class_eval { required :foo }
|
52
|
-
interaktor4.define_method(:call) { self.foo = "wadus" }
|
53
|
-
|
54
|
-
allow(organizer).to receive(:organized) {
|
55
|
-
[interaktor2, interaktor3, interaktor4]
|
56
|
-
}
|
57
|
-
|
58
|
-
expect(interaktor2).to receive(:call!).once.ordered.and_call_original
|
59
|
-
expect(interaktor3).to receive(:call!).once.ordered.and_call_original
|
60
|
-
expect(interaktor4).to receive(:call!).once.ordered.and_call_original
|
61
|
-
|
62
|
-
result = organizer.call(foo: "asdf")
|
63
|
-
|
64
|
-
expect(result.foo).to eq "wadus"
|
65
|
-
end
|
66
|
-
|
67
|
-
it "calls each interaktor in order and passes success attributes" do
|
68
|
-
organizer.class_eval { required :foo }
|
69
|
-
|
70
|
-
interaktor2 = Class.new.include(Interaktor)
|
71
|
-
interaktor2.class_eval do
|
72
|
-
required :foo
|
73
|
-
success :bar
|
74
|
-
end
|
75
|
-
interaktor2.define_method(:call) { success!(bar: "baz") }
|
76
|
-
|
77
|
-
interaktor3 = Class.new.include(Interaktor)
|
78
|
-
interaktor3.class_eval { required :bar }
|
79
|
-
interaktor3.define_method(:call) { self.bar = "wadus" }
|
80
|
-
|
81
|
-
allow(organizer).to receive(:organized) {
|
82
|
-
[interaktor2, interaktor3]
|
83
|
-
}
|
84
|
-
|
85
|
-
expect(interaktor2).to receive(:call!).once.ordered.and_call_original
|
86
|
-
expect(interaktor3).to receive(:call!).once.ordered.and_call_original
|
87
|
-
|
88
|
-
result = organizer.call(foo: "asdf")
|
89
|
-
|
90
|
-
expect(result.bar).to eq "wadus"
|
91
|
-
end
|
92
|
-
|
93
|
-
it "raises an exception if the organizer attributes do not satisfy the first interaktor" do
|
94
|
-
organizer.class_eval { required :foo }
|
95
|
-
|
96
|
-
interaktor2 = Class.new.include(Interaktor)
|
97
|
-
interaktor2.class_eval { required :bar }
|
98
|
-
|
99
|
-
allow(organizer).to receive(:organized).and_return([interaktor2])
|
100
|
-
|
101
|
-
expect(interaktor2).to receive(:call!).once.ordered.and_call_original
|
102
|
-
|
103
|
-
expect {
|
104
|
-
organizer.call(foo: "bar")
|
105
|
-
}.to raise_error(an_instance_of(Interaktor::Error::MissingAttributeError).and having_attributes(attributes: [:bar]))
|
106
|
-
end
|
107
|
-
|
108
|
-
it "raises an exception if the organizer attributes do not satisfy a non-first interaktor" do
|
109
|
-
organizer.class_eval { required :foo }
|
110
|
-
|
111
|
-
interaktor2 = Class.new.include(Interaktor)
|
112
|
-
interaktor2.class_eval { required :foo }
|
113
|
-
|
114
|
-
interaktor3 = Class.new.include(Interaktor)
|
115
|
-
interaktor3.class_eval { required :bar }
|
116
|
-
|
117
|
-
allow(organizer).to receive(:organized).and_return([interaktor2, interaktor3])
|
118
|
-
|
119
|
-
expect(interaktor2).to receive(:call!).once.ordered.and_call_original
|
120
|
-
expect(interaktor3).to receive(:call!).once.ordered.and_call_original
|
121
|
-
|
122
|
-
expect {
|
123
|
-
organizer.call(foo: "bar")
|
124
|
-
}.to raise_error(an_instance_of(Interaktor::Error::MissingAttributeError).and having_attributes(attributes: [:bar]))
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|