interaktor 0.2.0 → 0.4.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 +4 -4
- data/.github/workflows/publish.yml +5 -4
- data/.github/workflows/tests.yml +5 -5
- data/.gitignore +3 -0
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Gemfile.ci +6 -0
- data/README.md +65 -29
- data/interaktor.gemspec +3 -2
- 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/organizer_missing_passed_attribute_error.rb +21 -0
- data/lib/interaktor/error/organizer_success_attribute_missing_error.rb +20 -0
- data/lib/interaktor/hooks.rb +16 -0
- data/lib/interaktor/organizer.rb +33 -7
- data/lib/interaktor.rb +11 -16
- data/spec/integration_spec.rb +142 -71
- data/spec/{interactor → interaktor}/context_spec.rb +1 -1
- data/spec/{interactor → interaktor}/hooks_spec.rb +100 -2
- 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 -17
- data/.travis.yml +0 -14
- data/lib/interaktor/error/disallowed_attribute_assignment_error.rb +0 -9
- data/lib/interaktor/error/missing_attribute_error.rb +0 -5
- data/lib/interaktor/error/option_error.rb +0 -16
- data/lib/interaktor/error/unknown_attribute_error.rb +0 -5
- data/lib/interaktor/error/unknown_option_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.4.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: 2023-02-18 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,21 @@ 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
|
-
- lib/interaktor/error/
|
65
|
-
- lib/interaktor/error/
|
66
|
-
- lib/interaktor/error/
|
67
|
-
- lib/interaktor/error/unknown_attribute_error.rb
|
68
|
-
- lib/interaktor/error/unknown_option_error.rb
|
79
|
+
- lib/interaktor/error/missing_explicit_success_error.rb
|
80
|
+
- lib/interaktor/error/organizer_missing_passed_attribute_error.rb
|
81
|
+
- lib/interaktor/error/organizer_success_attribute_missing_error.rb
|
69
82
|
- lib/interaktor/failure.rb
|
70
83
|
- lib/interaktor/hooks.rb
|
71
84
|
- lib/interaktor/organizer.rb
|
72
85
|
- spec/integration_spec.rb
|
73
|
-
- spec/
|
74
|
-
- spec/
|
75
|
-
- spec/
|
86
|
+
- spec/interaktor/context_spec.rb
|
87
|
+
- spec/interaktor/hooks_spec.rb
|
88
|
+
- spec/interaktor/organizer_spec.rb
|
76
89
|
- spec/interaktor_spec.rb
|
77
90
|
- spec/spec_helper.rb
|
91
|
+
- spec/support/helpers.rb
|
78
92
|
- spec/support/lint.rb
|
79
93
|
homepage: https://github.com/taylorthurlow/interaktor
|
80
94
|
licenses:
|
@@ -95,16 +109,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
111
|
requirements: []
|
98
|
-
|
99
|
-
rubygems_version: 2.7.6.2
|
112
|
+
rubygems_version: 3.4.6
|
100
113
|
signing_key:
|
101
114
|
specification_version: 4
|
102
115
|
summary: Simple service object implementation
|
103
116
|
test_files:
|
104
117
|
- spec/integration_spec.rb
|
105
|
-
- spec/
|
106
|
-
- spec/
|
107
|
-
- spec/
|
118
|
+
- spec/interaktor/context_spec.rb
|
119
|
+
- spec/interaktor/hooks_spec.rb
|
120
|
+
- spec/interaktor/organizer_spec.rb
|
108
121
|
- spec/interaktor_spec.rb
|
109
122
|
- spec/spec_helper.rb
|
123
|
+
- spec/support/helpers.rb
|
110
124
|
- spec/support/lint.rb
|
data/.travis.yml
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
class Interaktor::Error::DisallowedAttributeAssignmentError < Interaktor::Error::AttributeError
|
2
|
-
def message
|
3
|
-
<<~MESSAGE.strip.tr("\n", "")
|
4
|
-
Attempted a disallowed assignment to the '#{attributes.first}'
|
5
|
-
attribute which was not included when the #{interaktor} interaktor was
|
6
|
-
originally called.
|
7
|
-
MESSAGE
|
8
|
-
end
|
9
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class Interaktor::Error::OptionError < Interaktor::Error::Base
|
2
|
-
# @return [Hash{Symbol=>Object}]
|
3
|
-
attr_reader :options
|
4
|
-
|
5
|
-
# @param interaktor [Class]
|
6
|
-
# @param options [Hash{Symbol=>Object}]
|
7
|
-
def initialize(interaktor, options)
|
8
|
-
super(interaktor)
|
9
|
-
|
10
|
-
@options = options
|
11
|
-
end
|
12
|
-
|
13
|
-
def message
|
14
|
-
raise NotImplementedError
|
15
|
-
end
|
16
|
-
end
|
@@ -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
|