service_actor 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccd0af6d1704b2efc805ce3bfa5cdfd1e74797c9b0a015511daf351e692ab6e8
4
- data.tar.gz: 6fa64250a89f505bfc0b9b2e300faf5c3ae222740317263fe4947a383e1b64c8
3
+ metadata.gz: 76d96df8529ca670b0380e22ae56b4a2b7f32af6bd50e8b311fd6cef056b5f88
4
+ data.tar.gz: 7bfea37c9b431c615cccd6e60e00500372aabe3e7b0c8bb4061a2df129a99bc4
5
5
  SHA512:
6
- metadata.gz: a3041c28efd75c40e793e299432b743274803b7a237a22525a05de3b916b17f899c6de85a0eeeb98594de47f8d742d595c7582ecb505700a3ec9712f842d1c87
7
- data.tar.gz: 2f6e0ece1cc4964311a25035dba7011844b1d3992d7ec14f9a36a497b6b62f361ba5826ee364e1871411dd3ce5fff144354a104c846f98f0bcfe971cd8b53030
6
+ metadata.gz: 03bae9c5a662507d5170eaa133ac344469fef28c956d49f9ef0d2d619146a365221bb8705e43224bb54c3328262e5fca8adc718760cc536564563058f4eb35e9
7
+ data.tar.gz: 7e477e327a244f1fa3fe9e90fbff8f18e1d53f208bac2ea62ec7701c9c82abddc1a8d712a20719f31a6e8c866de697aa8a2ac05e3615f5f62c81f16604ee995a
data/README.md CHANGED
@@ -24,6 +24,7 @@ and controllers thin.
24
24
  - [Rollback](#rollback)
25
25
  - [Inline actors](#inline-actors)
26
26
  - [Play conditions](#play-conditions)
27
+ - [Input aliases](#input-aliases)
27
28
  - [Testing](#testing)
28
29
  - [FAQ](#faq)
29
30
  - [Thanks](#thanks)
@@ -475,6 +476,20 @@ class PlaceOrder < Actor
475
476
  end
476
477
  ```
477
478
 
479
+ ### Input aliases
480
+
481
+ You can use `alias_input` to transform the output of an actor into the input of
482
+ the next actors.
483
+
484
+ ```rb
485
+ class PlaceComment < Actor
486
+ play CreateComment,
487
+ NotifyCommentFollowers,
488
+ alias_input(commenter: :user),
489
+ UpdateUserStats
490
+ end
491
+ ```
492
+
478
493
  ## Testing
479
494
 
480
495
  In your application, add automated testing to your actors as you would do to any
@@ -19,6 +19,14 @@ module ServiceActor::Playable
19
19
  play_actors.push(actors: actors, **options)
20
20
  end
21
21
 
22
+ def alias_input(**options)
23
+ lambda do |actor|
24
+ options.each do |new, original|
25
+ define_alias_input(actor, new, original)
26
+ end
27
+ end
28
+ end
29
+
22
30
  def play_actors
23
31
  @play_actors ||= []
24
32
  end
@@ -28,6 +36,21 @@ module ServiceActor::Playable
28
36
 
29
37
  child.play_actors.concat(play_actors)
30
38
  end
39
+
40
+ private
41
+
42
+ def define_alias_input(actor, new, original)
43
+ actor[new] = actor[original]
44
+ actor.instance_exec do
45
+ [original, new].each do |method|
46
+ singleton_class.send(:undef_method, "#{method}=")
47
+ define_singleton_method("#{method}=") do |v|
48
+ actor[original] = v
49
+ actor[new] = v
50
+ end
51
+ end
52
+ end
53
+ end
31
54
  end
32
55
 
33
56
  module PrependedMethods
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "zeitwerk"
4
4
 
5
+ module ServiceActor; end
6
+
5
7
  lib = File.expand_path("../..", __dir__)
6
8
 
7
9
  loader = Zeitwerk::Loader.new
@@ -12,5 +14,3 @@ loader.inflector = Zeitwerk::GemInflector.new(
12
14
  loader.push_dir(lib)
13
15
  loader.ignore(__dir__)
14
16
  loader.setup
15
-
16
- module ServiceActor; end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ServiceActor
4
- VERSION = "3.4.0"
4
+ VERSION = "3.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_actor
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunny Ripert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-22 00:00:00.000000000 Z
11
+ date: 2022-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk