ii_interactor 1.2.0 → 2.0.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: 9e2c11382c90fb3533448d1ddc3ed2f1ca922abb204570beba2eed4ad264fbef
4
- data.tar.gz: dd2cd0bab63421c2c45b595438e2b4ef2f914abc041ce1cb1a655cd6ac98575c
3
+ metadata.gz: a2fdfb2e93eb53ee2b70845fb78c285aae26c237681537ae59893675873974f1
4
+ data.tar.gz: b85095ca4396ccc3523fbe6f212ed335f057a77dc60e87b0969c14666a5e0d0f
5
5
  SHA512:
6
- metadata.gz: e4ba848c2b8582434360c1f9f47b646fcea0e1954ec64419d8beb1b46b8bedd73876cc49de3f0a2f6258dc49db034e468b34bb90794a00c8807060cc2304ddb3
7
- data.tar.gz: e765a8adb58f62202ca6e35e302846185d575776805aaed73bc9495de7ebd6bca800f864d47bb176da5731b012af6897272e9810efee7f22af56b3807019d7a2
6
+ metadata.gz: 2b1321aee1be7d0c362315ef1020db0113d77445366617de0e0f9ff010c49d1118f7a26f5182102065efa60eb832616ded910f1e3bd222fc897d5fcaa0947236
7
+ data.tar.gz: a0d731eb5334b3846530e60858146c9b1f748d01b313917ee7e50153ab5f22f9fdb8a2cc53c24d08459ff7f074ee203579752c4d778bfad618e269c3361e318f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.0
4
+
5
+ * Replace interaction feature with coactive.
6
+
3
7
  ## 1.2.0
4
8
 
5
9
  * Add variable setting feature.
data/README.md CHANGED
@@ -129,9 +129,9 @@ Interactor.call(message: 'something')
129
129
  #=> something
130
130
  ```
131
131
 
132
- ### Interactions
132
+ ### Coactions
133
133
 
134
- You can call other interactors in the same context using `interact`:
134
+ You can call other interactors in the same context using `coact`:
135
135
 
136
136
  ```ruby
137
137
  class AInteractor < IIInteractor::Base
@@ -147,8 +147,8 @@ class BInteractor < IIInteractor::Base
147
147
  end
148
148
 
149
149
  class MainInteractor < IIInteractor::Base
150
- interact AInteractor
151
- interact BInteractor
150
+ coact AInteractor
151
+ coact BInteractor
152
152
  end
153
153
 
154
154
  MainInteractor.call
@@ -156,166 +156,7 @@ MainInteractor.call
156
156
  # BInteractor
157
157
  ```
158
158
 
159
- #### Named interaction
160
-
161
- You can also define named interactions.
162
- The interactors to be called are looked up from all interactors.
163
-
164
- ```ruby
165
- class AInteractor < IIInteractor::Base
166
- react :some_name
167
-
168
- def call
169
- puts self.class.name
170
- end
171
- end
172
-
173
- class BInteractor < IIInteractor::Base
174
- react :some_name
175
-
176
- def call
177
- puts self.class.name
178
- end
179
- end
180
-
181
- class MainInteractor < IIInteractor::Base
182
- interact :some_name
183
- end
184
-
185
- MainInteractor.call
186
- #=> AInteractor
187
- # BInteractor
188
- ```
189
-
190
- Note followings:
191
-
192
- * All files in `app/interactors` are loaded in development mode to lookup interactors having same name.
193
- * The called interactors are unordered.
194
-
195
- #### Object based interaction
196
-
197
- You can also define object based interactions.
198
- The interactors to be called are looked up from the namespace corresponding with caller interactor.
199
-
200
- ```ruby
201
- class A
202
- end
203
-
204
- class B
205
- end
206
-
207
- class Main::AInteractor < IIInteractor::Base
208
- def call
209
- puts self.class.name
210
- end
211
- end
212
-
213
- class Main::BInteractor < IIInteractor::Base
214
- def call
215
- puts self.class.name
216
- end
217
- end
218
-
219
- class MainInteractor < IIInteractor::Base
220
- interact A
221
- interact B
222
- end
223
-
224
- MainInteractor.call
225
- #=> Main::AInteractor
226
- # Main::BInteractor
227
- ```
228
-
229
- #### Custom interaction
230
-
231
- You can also customize lookup of interactors as follows:
232
-
233
- ```ruby
234
- class AInteractor < IIInteractor::Base
235
- def call
236
- puts self.class.name
237
- end
238
- end
239
-
240
- class BInteractor < IIInteractor::Base
241
- def call
242
- puts self.class.name
243
- end
244
- end
245
-
246
- class MainInteractor < IIInteractor::Base
247
- # set block
248
- interact do
249
- if @context.condition == 'A'
250
- AInteractor
251
- else
252
- BInteractor
253
- end
254
- end
255
-
256
- # set method name
257
- interact :conditional_interactors
258
-
259
- def conditional_interactors
260
- if @context.condition == 'A'
261
- AInteractor
262
- else
263
- BInteractor
264
- end
265
- end
266
- end
267
-
268
- MainInteractor.call(condition: 'A')
269
- #=> AInteractor
270
-
271
- MainInteractor.call(condition: 'B')
272
- #=> BInteractor
273
- ```
274
-
275
- #### Nested interaction
276
-
277
- You can define nested interactions as follows:
278
-
279
- ```ruby
280
- class NestedAInteractor < IIInteractor::Base
281
- def call
282
- puts self.class.name
283
- end
284
- end
285
-
286
- class NestedBInteractor < IIInteractor::Base
287
- def call
288
- puts self.class.name
289
- end
290
- end
291
-
292
- class AInteractor < IIInteractor::Base
293
- interact NestedAInteractor
294
-
295
- def call
296
- puts self.class.name
297
- end
298
- end
299
-
300
- class BInteractor < IIInteractor::Base
301
- interact NestedBInteractor
302
-
303
- def call
304
- puts self.class.name
305
- end
306
- end
307
-
308
- class MainInteractor < IIInteractor::Base
309
- interact AInteractor
310
- interact BInteractor
311
- end
312
-
313
- MainInteractor.call
314
- #=> NestedAInteractor
315
- # AInteractor
316
- # NestedBInteractor
317
- # BInteractor
318
- ```
159
+ See [coactive](https://github.com/kanety/coactive) for more `coact` examples:
319
160
 
320
161
  ### Stop interactions
321
162
 
@@ -336,8 +177,8 @@ class BInteractor < IIInteractor::Base
336
177
  end
337
178
 
338
179
  class MainInteractor < IIInteractor::Base
339
- interact AInteractor
340
- interact BInteractor
180
+ coact AInteractor
181
+ coact BInteractor
341
182
  end
342
183
 
343
184
  context = MainInteractor.call
@@ -379,8 +220,8 @@ class BInteractor < IIInteractor::Base
379
220
  end
380
221
 
381
222
  class MainInteractor < IIInteractor::Base
382
- interact AInteractor
383
- interact BInteractor
223
+ coact AInteractor
224
+ coact BInteractor
384
225
  end
385
226
 
386
227
  context = MainInteractor.call
@@ -413,8 +254,8 @@ class BInteractor < IIInteractor::Base
413
254
  end
414
255
 
415
256
  class MainInteractor < IIInteractor::Base
416
- interact AInteractor
417
- interact BInteractor
257
+ coact AInteractor
258
+ coact BInteractor
418
259
  end
419
260
 
420
261
  MainInteractor.call do |interactor, message|
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "activesupport", ">= 5.0"
21
+ spec.add_dependency "coactive", ">= 0.1"
21
22
 
22
23
  spec.add_development_dependency "rails", ">= 5.0"
23
24
  spec.add_development_dependency "sqlite3"
@@ -5,8 +5,7 @@ require_relative 'core'
5
5
  require_relative 'variables'
6
6
  require_relative 'callbacks'
7
7
  require_relative 'instrumentation'
8
- require_relative 'interaction'
9
- require_relative 'lookup'
8
+ require_relative 'coactors'
10
9
 
11
10
  module IIInteractor
12
11
  class Base
@@ -14,7 +13,6 @@ module IIInteractor
14
13
  include Callbacks
15
14
  include Instrumentation
16
15
  include Variables
17
- include Interaction
18
- include Lookup
16
+ include Coactors
19
17
  end
20
18
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IIInteractor
4
+ module Coactors
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ include Coactive::Base
9
+
10
+ configure_coactive do |config|
11
+ config.load_paths = ['app/interactors']
12
+ config.class_suffix = 'Interactor'
13
+ config.use_cache = true
14
+ config.lookup_superclass_until = ['ActiveRecord::Base', 'ActiveModel::Base']
15
+ end
16
+
17
+ class << self
18
+ alias_method :interact, :coact
19
+ alias_method :react, :coaction
20
+ end
21
+ end
22
+ end
23
+ end
@@ -17,7 +17,7 @@ module IIInteractor
17
17
  end
18
18
 
19
19
  def call_all
20
- planned = lookup.map { |interactor| interactor.new(@context) } + [self]
20
+ planned = coactors.map { |interactor| interactor.new(@context) } + [self]
21
21
  planned.each_with_index do |interactor, i|
22
22
  if i == planned.size - 1
23
23
  interactor.call_self
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IIInteractor
4
- VERSION = '1.2.0'
4
+ VERSION = '2.0.0'
5
5
  end
data/lib/ii_interactor.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'active_support'
2
+ require 'coactive'
2
3
 
3
4
  require 'ii_interactor/version'
4
5
  require 'ii_interactor/errors'
5
6
  require 'ii_interactor/config'
6
7
  require 'ii_interactor/base'
7
- require 'ii_interactor/loader'
8
8
  require 'ii_interactor/log_subscriber'
9
9
 
10
10
  module IIInteractor
@@ -16,9 +16,5 @@ module IIInteractor
16
16
  def config
17
17
  Config
18
18
  end
19
-
20
- def load
21
- Loader.call
22
- end
23
19
  end
24
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ii_interactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshikazu Kaneta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-22 00:00:00.000000000 Z
11
+ date: 2021-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coactive
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rails
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -120,18 +134,13 @@ files:
120
134
  - lib/ii_interactor.rb
121
135
  - lib/ii_interactor/base.rb
122
136
  - lib/ii_interactor/callbacks.rb
137
+ - lib/ii_interactor/coactors.rb
123
138
  - lib/ii_interactor/config.rb
124
139
  - lib/ii_interactor/context.rb
125
140
  - lib/ii_interactor/core.rb
126
141
  - lib/ii_interactor/errors.rb
127
142
  - lib/ii_interactor/instrumentation.rb
128
- - lib/ii_interactor/interaction.rb
129
- - lib/ii_interactor/loader.rb
130
143
  - lib/ii_interactor/log_subscriber.rb
131
- - lib/ii_interactor/lookup.rb
132
- - lib/ii_interactor/lookups/base.rb
133
- - lib/ii_interactor/lookups/name.rb
134
- - lib/ii_interactor/lookups/object.rb
135
144
  - lib/ii_interactor/variables.rb
136
145
  - lib/ii_interactor/version.rb
137
146
  homepage: https://github.com/kanety/ii_interactor
@@ -152,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
161
  - !ruby/object:Gem::Version
153
162
  version: '0'
154
163
  requirements: []
155
- rubygems_version: 3.1.2
164
+ rubygems_version: 3.0.3
156
165
  signing_key:
157
166
  specification_version: 4
158
167
  summary: A base interactor to support management of bussiness logic
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module IIInteractor
4
- module Interaction
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- class_attribute :_interactions
9
- self._interactions = []
10
- class_attribute :_reactions
11
- self._reactions = []
12
- end
13
-
14
- class_methods do
15
- def interact(*interactors, **options, &block)
16
- if block
17
- self._interactions = _interactions + [block]
18
- elsif options[:before]
19
- index = self._interactions.index { |interaction| interaction == options[:before] }
20
- self._interactions = self._interactions.insert(index, *interactors)
21
- else
22
- self._interactions = _interactions + interactors
23
- end
24
- end
25
-
26
- def interactions
27
- self._interactions
28
- end
29
-
30
- def clear_interactions
31
- self._interactions = []
32
- end
33
-
34
- def react(*reactions)
35
- self._reactions = _reactions + reactions
36
- end
37
-
38
- def reactions
39
- self._reactions
40
- end
41
- end
42
- end
43
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module IIInteractor
4
- module Loader
5
- class << self
6
- def call
7
- return unless defined?(Rails)
8
- return if Rails.application.config.eager_load
9
-
10
- engines = [Rails] + Rails::Engine.subclasses.map(&:instance)
11
- engines.each do |engine|
12
- Dir["#{engine.root}/app/interactors/**/*.rb"].each do |file|
13
- require file
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lookups/base'
4
- require_relative 'lookups/name'
5
- require_relative 'lookups/object'
6
-
7
- module IIInteractor
8
- module Lookup
9
- extend ActiveSupport::Concern
10
-
11
- def lookup_all
12
- lookup.map { |interactor| [interactor] + interactor.new(@context).lookup_all }.flatten
13
- end
14
-
15
- def lookup
16
- self.class._interactions.map do |interaction|
17
- if interaction.is_a?(Symbol) && respond_to?(interaction, true)
18
- send(interaction)
19
- elsif interaction.is_a?(Proc)
20
- instance_exec(&interaction)
21
- else
22
- interaction
23
- end
24
- end.flatten.compact.map do |interaction|
25
- if interaction.is_a?(Class) && interaction < IIInteractor::Base
26
- interaction
27
- else
28
- self.class.lookup(interaction)
29
- end
30
- end.flatten.compact
31
- end
32
-
33
- class_methods do
34
- def lookup(*interactions)
35
- interactions = _interactions unless interactions
36
- interactions.map { |interaction| Lookup.call(self, interaction) }.flatten
37
- end
38
- end
39
-
40
- class << self
41
- class_attribute :lookups
42
- self.lookups = [Lookups::Name, Lookups::Object]
43
-
44
- class_attribute :cache
45
- self.cache = {}
46
-
47
- def call(klass, interaction)
48
- with_cache(klass, interaction) do
49
- lookup = lookups.detect { |lookup| lookup.call?(interaction) }
50
- lookup.new(klass, interaction).call if lookup
51
- end
52
- end
53
-
54
- private
55
-
56
- def with_cache(klass, interaction)
57
- if Config.lookup_cache
58
- self.cache[klass] ||= {}
59
- self.cache[klass][interaction] ||= yield
60
- else
61
- yield
62
- end
63
- end
64
- end
65
- end
66
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module IIInteractor
4
- module Lookups
5
- class Base
6
- def initialize(klass, interaction)
7
- @klass = klass
8
- @interaction = interaction
9
- end
10
-
11
- def call
12
- end
13
-
14
- class << self
15
- def call?(interaction)
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module IIInteractor
4
- module Lookups
5
- class Name < Base
6
- def call
7
- IIInteractor.load
8
- IIInteractor::Base.descendants.select do |interactor|
9
- interactor._reactions.any? { |reaction| reaction == @interaction }
10
- end
11
- end
12
-
13
- class << self
14
- def call?(interaction)
15
- interaction.is_a?(Symbol)
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module IIInteractor
4
- module Lookups
5
- class Object < Base
6
- def call
7
- return if terminate?
8
-
9
- if @interaction.name.present? && (interactor = resolve)
10
- interactor
11
- elsif @interaction.superclass
12
- self.class.new(@klass, @interaction.superclass).call
13
- end
14
- end
15
-
16
- private
17
-
18
- def terminate?
19
- @interaction.name.to_s.in?(['Object', 'ActiveRecord::Base', 'ActiveModel::Base'])
20
- end
21
-
22
- def resolve
23
- name = resolve_name
24
- interactor = name.safe_constantize
25
- return interactor if interactor && name == interactor.name
26
- end
27
-
28
- def resolve_name
29
- namespace = @klass.name.to_s.sub(/Interactor$/, '').to_s
30
- [namespace, "#{@interaction.name}Interactor"].join('::')
31
- end
32
-
33
- class << self
34
- def call?(interaction)
35
- interaction.is_a?(Module)
36
- end
37
- end
38
- end
39
- end
40
- end