standard-procedure-plumbing 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/plumbing/actor/async.rb +3 -5
- data/lib/plumbing/actor/inline.rb +3 -5
- data/lib/plumbing/actor/threaded.rb +2 -2
- data/lib/plumbing/actor.rb +2 -2
- data/lib/plumbing/version.rb +1 -1
- data/spec/plumbing/actor_spec.rb +100 -24
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77cd887e8bdfc09198bcf94c65b6d52014383b6691625f41e7301b52ae223adf
|
4
|
+
data.tar.gz: 4196496eff4bbc7b277592b22855dca3c29d87115130ca08a57796cb14436aae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e8614ed73bb33446e89294b7c94da3f39786a3c82704ac1c5187d5310edb5756db00bdfd38128743496b4af2bd1fdbde3027850a83406efdf76d5bd5fb3cf74
|
7
|
+
data.tar.gz: f5b1d8f95e6a275817348a95b3761d0dcb991d2e504b87dbcf2a35f1b4a4ac0f96bc0a90a70f59113644034291dd9af83f30adcfb30965bc4c35ec3dc5996502
|
data/README.md
CHANGED
@@ -469,6 +469,8 @@ You can also use the same `@object.as type` to type-check instances against modu
|
|
469
469
|
|
470
470
|
## Installation
|
471
471
|
|
472
|
+
Note: this gem is licensed under the [LGPL](/LICENCE). This may or may not make it unsuitable for use by you or your company.
|
473
|
+
|
472
474
|
Install the gem and add to the application's Gemfile by executing:
|
473
475
|
|
474
476
|
```sh
|
data/lib/plumbing/actor/async.rb
CHANGED
@@ -14,9 +14,9 @@ module Plumbing
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Send the message to the target and wrap the result
|
17
|
-
def send_message
|
17
|
+
def send_message(message_name, *, **, &)
|
18
18
|
task = @semaphore.async do
|
19
|
-
@target.send
|
19
|
+
@target.send(message_name, *, **, &)
|
20
20
|
end
|
21
21
|
Result.new(task)
|
22
22
|
end
|
@@ -28,9 +28,7 @@ module Plumbing
|
|
28
28
|
|
29
29
|
def within_actor? = true
|
30
30
|
|
31
|
-
def stop
|
32
|
-
# do nothing
|
33
|
-
end
|
31
|
+
def stop = nil
|
34
32
|
|
35
33
|
Result = Data.define(:task) do
|
36
34
|
def value
|
@@ -6,8 +6,8 @@ module Plumbing
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# Send the message to the target and wrap the result
|
9
|
-
def send_message(message_name, *, &)
|
10
|
-
value = @target.send(message_name, *, &)
|
9
|
+
def send_message(message_name, *, **, &)
|
10
|
+
value = @target.send(message_name, *, **, &)
|
11
11
|
Result.new(value)
|
12
12
|
rescue => ex
|
13
13
|
Result.new(ex)
|
@@ -20,9 +20,7 @@ module Plumbing
|
|
20
20
|
|
21
21
|
def within_actor? = true
|
22
22
|
|
23
|
-
def stop
|
24
|
-
# do nothing
|
25
|
-
end
|
23
|
+
def stop = nil
|
26
24
|
|
27
25
|
Result = Data.define(:result) do
|
28
26
|
def value = result.is_a?(Exception) ? raise(result) : result
|
@@ -16,8 +16,8 @@ module Plumbing
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# Send the message to the target and wrap the result
|
19
|
-
def send_message
|
20
|
-
Message.new(@target, message_name, Plumbing::Actor.transporter.marshal(*args), block, Concurrent::MVar.new).tap do |message|
|
19
|
+
def send_message(message_name, *args, **params, &block)
|
20
|
+
Message.new(@target, message_name, Plumbing::Actor.transporter.marshal(*args, **params), block, Concurrent::MVar.new).tap do |message|
|
21
21
|
@mutex.synchronize do
|
22
22
|
@queue << message
|
23
23
|
send_messages if @queue.any?
|
data/lib/plumbing/actor.rb
CHANGED
@@ -64,8 +64,8 @@ module Plumbing
|
|
64
64
|
def build_proxy_class
|
65
65
|
Class.new(proxy_base_class).tap do |proxy_class|
|
66
66
|
async_messages.each do |message|
|
67
|
-
proxy_class.define_method message do |*args, &block|
|
68
|
-
send_message(message, *args, &block)
|
67
|
+
proxy_class.define_method message do |*args, **params, &block|
|
68
|
+
send_message(message, *args, **params, &block)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
data/lib/plumbing/version.rb
CHANGED
data/spec/plumbing/actor_spec.rb
CHANGED
@@ -112,39 +112,115 @@ RSpec.describe Plumbing::Actor do
|
|
112
112
|
|
113
113
|
def do_safety_check = @on_safety_check&.call
|
114
114
|
end
|
115
|
-
# standard:enable Lint/ConstantDefinitionInBlock
|
116
115
|
|
117
|
-
|
118
|
-
|
119
|
-
|
116
|
+
class ParameterHandler
|
117
|
+
include Plumbing::Actor
|
118
|
+
async :set_values, :args, :params, :block
|
119
|
+
attr_reader :args, :params, :block
|
120
|
+
|
121
|
+
def initialize
|
122
|
+
@args = nil
|
123
|
+
@params = nil
|
124
|
+
@block = nil
|
125
|
+
end
|
120
126
|
|
121
|
-
|
122
|
-
@counter = Counter.start "inline counter", initial_value: 100
|
123
|
-
@proxy_class = @counter.class
|
127
|
+
private
|
124
128
|
|
125
|
-
|
126
|
-
|
129
|
+
def set_values *args, **params, &block
|
130
|
+
@args = args
|
131
|
+
@params = params
|
132
|
+
@block = block
|
133
|
+
end
|
127
134
|
end
|
135
|
+
# standard:enable Lint/ConstantDefinitionInBlock
|
136
|
+
|
137
|
+
[:inline, :async, :threaded].each do |mode|
|
138
|
+
context "In #{mode} mode" do
|
139
|
+
it "knows which async messages are understood" do
|
140
|
+
expect(Counter.async_messages).to eq [:name, :count, :slow_query, :slowly_increment, :raises_error]
|
141
|
+
end
|
128
142
|
|
129
|
-
|
130
|
-
|
143
|
+
it "reuses existing proxy classes" do
|
144
|
+
@counter = Counter.start "inline counter", initial_value: 100
|
145
|
+
@proxy_class = @counter.class
|
131
146
|
|
132
|
-
|
147
|
+
@counter = Counter.start "another inline counter", initial_value: 200
|
148
|
+
expect(@counter.class).to eq @proxy_class
|
149
|
+
end
|
133
150
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
151
|
+
it "includes async messages from the superclass" do
|
152
|
+
expect(StepCounter.async_messages).to eq [:name, :count, :slow_query, :slowly_increment, :raises_error, :step_value]
|
153
|
+
|
154
|
+
@step_counter = StepCounter.start "step counter", initial_value: 100, step_value: 10
|
155
|
+
|
156
|
+
expect(@step_counter.count.value).to eq 100
|
157
|
+
expect(@step_counter.step_value.value).to eq 10
|
158
|
+
@step_counter.slowly_increment
|
159
|
+
expect(@step_counter.count.value).to eq 110
|
160
|
+
end
|
161
|
+
|
162
|
+
it "can access its own proxy" do
|
163
|
+
@actor = WhoAmI.start
|
139
164
|
|
140
|
-
|
141
|
-
|
165
|
+
expect(await { @actor.me_as_self }).to_not eq @actor
|
166
|
+
expect(await { @actor.me_as_actor }).to eq @actor
|
167
|
+
end
|
168
|
+
it "sends a single positional parameter" do
|
169
|
+
@parameter_handler = ParameterHandler.start
|
170
|
+
|
171
|
+
@parameter_handler.set_values "this"
|
172
|
+
expect(await { @parameter_handler.args }).to eq ["this"]
|
173
|
+
end
|
142
174
|
|
143
|
-
|
144
|
-
|
175
|
+
it "sends multiple positional parameters" do
|
176
|
+
@parameter_handler = ParameterHandler.start
|
177
|
+
|
178
|
+
@parameter_handler.set_values "this", "that"
|
179
|
+
expect(await { @parameter_handler.args }).to eq ["this", "that"]
|
180
|
+
end
|
181
|
+
|
182
|
+
it "sends keyword parameters" do
|
183
|
+
@parameter_handler = ParameterHandler.start
|
184
|
+
|
185
|
+
@parameter_handler.set_values something: "for nothing", cat: "dog", number: 123
|
186
|
+
expect(await { @parameter_handler.params }).to eq({something: "for nothing", cat: "dog", number: 123})
|
187
|
+
end
|
188
|
+
|
189
|
+
it "sends a mix of positional and keyword parameters" do
|
190
|
+
@parameter_handler = ParameterHandler.start
|
191
|
+
|
192
|
+
@parameter_handler.set_values "what do you say", 123, something: "for nothing"
|
193
|
+
expect(await { @parameter_handler.args }).to eq ["what do you say", 123]
|
194
|
+
expect(await { @parameter_handler.params }).to eq({something: "for nothing"})
|
195
|
+
end
|
196
|
+
|
197
|
+
it "sends a block parameter" do
|
198
|
+
@parameter_handler = ParameterHandler.start
|
199
|
+
|
200
|
+
@parameter_handler.set_values do
|
201
|
+
"HELLO"
|
202
|
+
end
|
203
|
+
|
204
|
+
@block = await { @parameter_handler.block }
|
205
|
+
expect(@block.call).to eq "HELLO"
|
206
|
+
end
|
207
|
+
|
208
|
+
it "sends a mix of positional and keyword parameters with a block" do
|
209
|
+
@parameter_handler = ParameterHandler.start
|
210
|
+
|
211
|
+
@parameter_handler.set_values "what do you say", 123, something: "for nothing" do
|
212
|
+
"BOOM"
|
213
|
+
end
|
214
|
+
|
215
|
+
expect(await { @parameter_handler.args }).to eq ["what do you say", 123]
|
216
|
+
expect(await { @parameter_handler.params }).to eq({something: "for nothing"})
|
217
|
+
@block = await { @parameter_handler.block }
|
218
|
+
expect(@block.call).to eq "BOOM"
|
219
|
+
end
|
220
|
+
end
|
145
221
|
end
|
146
222
|
|
147
|
-
context "
|
223
|
+
context "Inline mode only" do
|
148
224
|
around :example do |example|
|
149
225
|
Plumbing.configure mode: :inline, &example
|
150
226
|
end
|
@@ -182,7 +258,7 @@ RSpec.describe Plumbing::Actor do
|
|
182
258
|
end
|
183
259
|
|
184
260
|
[:threaded, :async].each do |mode|
|
185
|
-
context mode
|
261
|
+
context "Asynchronously (#{mode})" do
|
186
262
|
around :example do |example|
|
187
263
|
Sync do
|
188
264
|
Plumbing.configure mode: mode, &example
|
@@ -246,7 +322,7 @@ RSpec.describe Plumbing::Actor do
|
|
246
322
|
end
|
247
323
|
end
|
248
324
|
|
249
|
-
context "
|
325
|
+
context "Threaded mode only" do
|
250
326
|
around :example do |example|
|
251
327
|
Plumbing.configure mode: :threaded, &example
|
252
328
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standard-procedure-plumbing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rahoul Baruah
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: globalid
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
requirements: []
|
99
|
-
rubygems_version: 3.5.
|
99
|
+
rubygems_version: 3.5.17
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Plumbing - various pipelines for your ruby application
|