service_actor 3.4.1 → 3.5.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: 17a682280c4577e879e35e0210e31c7e22067d8d8c9e11c806d8eb6e95f515ac
4
- data.tar.gz: 24af188ea46c8650e5375b7c9bba438fc0a6d5f51d05ce7159e959671346d24e
3
+ metadata.gz: 76d96df8529ca670b0380e22ae56b4a2b7f32af6bd50e8b311fd6cef056b5f88
4
+ data.tar.gz: 7bfea37c9b431c615cccd6e60e00500372aabe3e7b0c8bb4061a2df129a99bc4
5
5
  SHA512:
6
- metadata.gz: 49e059ed1cef11316fa6f7c75c9e1baa7ede7de3545ccce499bf0d2b7a2199509e3c51c9515eca0f3e34a6f29e745ed694a691b13d16316e9102ade7c2f58c65
7
- data.tar.gz: '092ec403cb6f721eb1575a181ff426b6835fd4364ffa7378d3c533afa701c9bc0a7bfa4e46abf6c97c9c6a8a7b0b5e9c6e222275386d1837bd345fdcfc1adca1'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ServiceActor
4
- VERSION = "3.4.1"
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.1
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-24 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