interactify 0.1.0.pre.alpha.1 → 0.2.0.pre.alpha.1
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/.rubocop.yml +23 -0
- data/CHANGELOG.md +4 -0
- data/README.md +154 -42
- data/lib/interactify/async_job_klass.rb +61 -0
- data/lib/interactify/call_wrapper.rb +2 -0
- data/lib/interactify/contract_failure.rb +6 -0
- data/lib/interactify/contract_helpers.rb +9 -9
- data/lib/interactify/dsl.rb +4 -2
- data/lib/interactify/each_chain.rb +2 -0
- data/lib/interactify/if_interactor.rb +3 -1
- data/lib/interactify/interactor_wiring/callable_representation.rb +79 -0
- data/lib/interactify/interactor_wiring/constants.rb +125 -0
- data/lib/interactify/interactor_wiring/error_context.rb +41 -0
- data/lib/interactify/interactor_wiring/files.rb +51 -0
- data/lib/interactify/interactor_wiring.rb +57 -272
- data/lib/interactify/job_maker.rb +20 -69
- data/lib/interactify/jobable.rb +9 -7
- data/lib/interactify/mismatching_promise_error.rb +17 -0
- data/lib/interactify/organizer_call_monkey_patch.rb +7 -2
- data/lib/interactify/promising.rb +34 -0
- data/lib/interactify/rspec/matchers.rb +9 -11
- data/lib/interactify/version.rb +1 -1
- data/lib/interactify.rb +39 -9
- metadata +11 -2
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "interactify/mismatching_promise_error"
|
4
|
+
|
5
|
+
module Interactify
|
6
|
+
class Promising
|
7
|
+
attr_reader :interactor, :promising
|
8
|
+
|
9
|
+
def self.validate(interactor, *promising)
|
10
|
+
new(interactor, *promising).validate
|
11
|
+
|
12
|
+
interactor
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(interactor, *promising)
|
16
|
+
@interactor = interactor
|
17
|
+
@promising = format_keys promising
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate
|
21
|
+
return if promising == promised_keys
|
22
|
+
|
23
|
+
raise MismatchingPromiseError.new(interactor, promising, promised_keys)
|
24
|
+
end
|
25
|
+
|
26
|
+
def promised_keys
|
27
|
+
format_keys interactor.promised_keys
|
28
|
+
end
|
29
|
+
|
30
|
+
def format_keys(keys)
|
31
|
+
Array(keys).compact.map(&:to_sym).sort
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "interactify/interactor_wiring"
|
2
4
|
|
3
5
|
# Custom matcher that implements expect_inputs
|
4
6
|
# e.g.
|
@@ -6,7 +8,9 @@ require 'interactify/interactor_wiring'
|
|
6
8
|
|
7
9
|
RSpec::Matchers.define :expect_inputs do |*expected_inputs|
|
8
10
|
match do |actual|
|
9
|
-
|
11
|
+
next false unless actual.respond_to?(:expected_keys)
|
12
|
+
|
13
|
+
actual_inputs = Array(actual.expected_keys)
|
10
14
|
@missing_inputs = expected_inputs - actual_inputs
|
11
15
|
@extra_inputs = actual_inputs - expected_inputs
|
12
16
|
|
@@ -19,17 +23,15 @@ RSpec::Matchers.define :expect_inputs do |*expected_inputs|
|
|
19
23
|
message += "\n\textra inputs: #{@extra_inputs}" if @extra_inputs
|
20
24
|
message
|
21
25
|
end
|
22
|
-
|
23
|
-
def expected_keys(klass)
|
24
|
-
Array(klass.contract.expectations.instance_eval { @terms }.json&.rules&.keys)
|
25
|
-
end
|
26
26
|
end
|
27
27
|
|
28
28
|
# Custom matcher that implements promise_outputs
|
29
29
|
# e.g. expect(described_class).to promise_outputs(:request_logger)
|
30
30
|
RSpec::Matchers.define :promise_outputs do |*expected_outputs|
|
31
31
|
match do |actual|
|
32
|
-
|
32
|
+
next false unless actual.respond_to?(:promised_keys)
|
33
|
+
|
34
|
+
actual_outputs = Array(actual.promised_keys)
|
33
35
|
@missing_outputs = expected_outputs - actual_outputs
|
34
36
|
@extra_outputs = actual_outputs - expected_outputs
|
35
37
|
|
@@ -42,10 +44,6 @@ RSpec::Matchers.define :promise_outputs do |*expected_outputs|
|
|
42
44
|
message += "\n\textra outputs: #{@extra_outputs}" if @extra_outputs
|
43
45
|
message
|
44
46
|
end
|
45
|
-
|
46
|
-
def promised_keys(klass)
|
47
|
-
Array(klass.contract.promises.instance_eval { @terms }.json&.rules&.keys)
|
48
|
-
end
|
49
47
|
end
|
50
48
|
|
51
49
|
# Custom matcher that implements organize_interactors
|
data/lib/interactify/version.rb
CHANGED
data/lib/interactify.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "interactor"
|
4
|
+
require "interactor-contracts"
|
5
|
+
require "rails"
|
6
|
+
require "active_support/all"
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
8
|
+
require "interactify/version"
|
9
|
+
require "interactify/contract_helpers"
|
10
|
+
require "interactify/dsl"
|
11
|
+
require "interactify/interactor_wiring"
|
12
|
+
require "interactify/promising"
|
12
13
|
|
13
14
|
module Interactify
|
14
15
|
extend ActiveSupport::Concern
|
@@ -18,6 +19,12 @@ module Interactify
|
|
18
19
|
Interactify::InteractorWiring.new(root: Interactify.configuration.root, ignore:).validate_app
|
19
20
|
end
|
20
21
|
|
22
|
+
def reset
|
23
|
+
@on_contract_breach = nil
|
24
|
+
@before_raise_hook = nil
|
25
|
+
@configuration = nil
|
26
|
+
end
|
27
|
+
|
21
28
|
def trigger_contract_breach_hook(...)
|
22
29
|
@on_contract_breach&.call(...)
|
23
30
|
end
|
@@ -75,11 +82,34 @@ module Interactify
|
|
75
82
|
interactor_job
|
76
83
|
end
|
77
84
|
|
85
|
+
class_methods do
|
86
|
+
def promising(*args)
|
87
|
+
Promising.validate(self, *args)
|
88
|
+
end
|
89
|
+
|
90
|
+
def promised_keys
|
91
|
+
_interactify_extract_keys(contract.promises)
|
92
|
+
end
|
93
|
+
|
94
|
+
def expected_keys
|
95
|
+
_interactify_extract_keys(contract.expectations)
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
# this is the most brittle part of the code, relying on
|
101
|
+
# interactor-contracts internals
|
102
|
+
# so extracted it to here so change is isolated
|
103
|
+
def _interactify_extract_keys(clauses)
|
104
|
+
clauses.instance_eval { @terms }.json&.rules&.keys
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
78
108
|
class Configuration
|
79
109
|
attr_writer :root
|
80
110
|
|
81
111
|
def root
|
82
|
-
@root ||= Rails.root /
|
112
|
+
@root ||= Rails.root / "app"
|
83
113
|
end
|
84
114
|
end
|
85
115
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interactify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.pre.alpha.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Burns
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: interactor
|
@@ -109,20 +109,29 @@ extensions: []
|
|
109
109
|
extra_rdoc_files: []
|
110
110
|
files:
|
111
111
|
- ".rspec"
|
112
|
+
- ".rubocop.yml"
|
112
113
|
- CHANGELOG.md
|
113
114
|
- LICENSE.txt
|
114
115
|
- README.md
|
115
116
|
- Rakefile
|
116
117
|
- lib/interactify.rb
|
118
|
+
- lib/interactify/async_job_klass.rb
|
117
119
|
- lib/interactify/call_wrapper.rb
|
120
|
+
- lib/interactify/contract_failure.rb
|
118
121
|
- lib/interactify/contract_helpers.rb
|
119
122
|
- lib/interactify/dsl.rb
|
120
123
|
- lib/interactify/each_chain.rb
|
121
124
|
- lib/interactify/if_interactor.rb
|
122
125
|
- lib/interactify/interactor_wiring.rb
|
126
|
+
- lib/interactify/interactor_wiring/callable_representation.rb
|
127
|
+
- lib/interactify/interactor_wiring/constants.rb
|
128
|
+
- lib/interactify/interactor_wiring/error_context.rb
|
129
|
+
- lib/interactify/interactor_wiring/files.rb
|
123
130
|
- lib/interactify/job_maker.rb
|
124
131
|
- lib/interactify/jobable.rb
|
132
|
+
- lib/interactify/mismatching_promise_error.rb
|
125
133
|
- lib/interactify/organizer_call_monkey_patch.rb
|
134
|
+
- lib/interactify/promising.rb
|
126
135
|
- lib/interactify/rspec/matchers.rb
|
127
136
|
- lib/interactify/version.rb
|
128
137
|
- sig/interactify.rbs
|