onedrb 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/onedrb.rb +3 -196
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3829bafa21b51494d1bc147e668427dddc6998da520a60e14eefcd6b9c99c8e5
|
4
|
+
data.tar.gz: 26afcc85a10fb500e8f4e8d9c69ff2d1c23def83b0feed1b6279e7df958742f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d41f05105f22e8be82720dd89d0199c643ac76817ca04ae43c40132bb2d07004a9311be375bb296775834fb0e9591ce113d927fb410d1dab109601e076b73aa
|
7
|
+
data.tar.gz: 725672d9bf14d981f1df49be58699194bea4f722379d319a8bd84af5c89be26c8760c3c5e1d0990d6459cb29aa9462ee8b7d7974e816d936460b150ac2022eff
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/onedrb.rb
CHANGED
@@ -47,18 +47,6 @@ class ServiceMgr < AppMgr
|
|
47
47
|
end.compact
|
48
48
|
end
|
49
49
|
|
50
|
-
def stop(service)
|
51
|
-
super(service).sub('app', 'service')
|
52
|
-
end
|
53
|
-
|
54
|
-
def unload(service)
|
55
|
-
super(service).sub('app', 'service')
|
56
|
-
end
|
57
|
-
|
58
|
-
def method_missing(sym, *args)
|
59
|
-
#puts 'servicemgr sym: ' + sym.inspect
|
60
|
-
#puts 'args: ' + args.inspect
|
61
|
-
end
|
62
50
|
end
|
63
51
|
|
64
52
|
|
@@ -116,7 +104,7 @@ module OneDrb
|
|
116
104
|
parent = self
|
117
105
|
@obj&.services.each do |name, methods|
|
118
106
|
|
119
|
-
make_class(name, methods)
|
107
|
+
make_class(name, methods, parent)
|
120
108
|
|
121
109
|
end
|
122
110
|
|
@@ -176,7 +164,7 @@ module OneDrb
|
|
176
164
|
|
177
165
|
@obj.restart(service)
|
178
166
|
found = @obj.services.assoc(service)
|
179
|
-
make_class(*found) if found.any?
|
167
|
+
make_class(*found, self) if found.any?
|
180
168
|
end
|
181
169
|
|
182
170
|
def method_missing(sym, *args)
|
@@ -191,7 +179,7 @@ module OneDrb
|
|
191
179
|
|
192
180
|
private
|
193
181
|
|
194
|
-
def make_class(name, methods)
|
182
|
+
def make_class(name, methods, parent)
|
195
183
|
|
196
184
|
class_name = name.capitalize
|
197
185
|
klass = Object.const_set(class_name,Class.new)
|
@@ -213,184 +201,3 @@ module OneDrb
|
|
213
201
|
end
|
214
202
|
|
215
203
|
end
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
# Note: The Server object can also use a default ServiceMgr object.
|
220
|
-
# Which allows multiple services (user-defined objects) to be
|
221
|
-
# hosted dynamically.
|
222
|
-
|
223
|
-
|
224
|
-
class ServiceMgr
|
225
|
-
|
226
|
-
def initialize()
|
227
|
-
@services = {}
|
228
|
-
end
|
229
|
-
|
230
|
-
|
231
|
-
def call(service, methodname, *a)
|
232
|
-
|
233
|
-
proc1 = @services[service.to_sym].method(methodname.to_sym)
|
234
|
-
a.last.is_a?(Hash) ? proc1.call(*a[0..-2], **a.last) : proc1.call(*a)
|
235
|
-
|
236
|
-
end
|
237
|
-
|
238
|
-
def [](key)
|
239
|
-
@services[key]
|
240
|
-
end
|
241
|
-
|
242
|
-
def []=(key, value)
|
243
|
-
@services[key] = value
|
244
|
-
|
245
|
-
define_singleton_method key do
|
246
|
-
@services[key]
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
def services()
|
251
|
-
@services.map do |key, object|
|
252
|
-
[key, object.public_methods - Object.public_methods]
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
def method_missing(sym, *args)
|
257
|
-
puts 'servicemgr sym: ' + sym.inspect
|
258
|
-
puts 'args: ' + args.inspect
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
|
263
|
-
class OneDrbError < Exception
|
264
|
-
end
|
265
|
-
|
266
|
-
|
267
|
-
module OneDrb
|
268
|
-
|
269
|
-
class Server
|
270
|
-
using ColouredText
|
271
|
-
|
272
|
-
def initialize(host: '127.0.0.1', port: (49152..65535).to_a.sample.to_s,
|
273
|
-
obj: ServiceMgr.new, log: nil)
|
274
|
-
|
275
|
-
log.info self.class.to_s + '/initialize: active' if log
|
276
|
-
|
277
|
-
@host, @port, @log = host, port, log
|
278
|
-
|
279
|
-
if obj then
|
280
|
-
@obj = obj
|
281
|
-
else
|
282
|
-
msg = "No object supplied!".error
|
283
|
-
puts msg
|
284
|
-
raise OneDrbError, msg
|
285
|
-
end
|
286
|
-
|
287
|
-
log.info self.class.to_s +'/initialize: completed' if log
|
288
|
-
|
289
|
-
end
|
290
|
-
|
291
|
-
def start()
|
292
|
-
|
293
|
-
@log.info self.class.to_s +'/start: active' if @log
|
294
|
-
puts (self.class.to_s + " running on port " + @port).info
|
295
|
-
DRb.start_service "druby://#{@host}:#{@port}", @obj
|
296
|
-
DRb.thread.join
|
297
|
-
|
298
|
-
end
|
299
|
-
|
300
|
-
end
|
301
|
-
|
302
|
-
|
303
|
-
class Client
|
304
|
-
using ColouredText
|
305
|
-
|
306
|
-
def initialize(host: '127.0.0.1', port: nil)
|
307
|
-
|
308
|
-
DRb.start_service
|
309
|
-
|
310
|
-
puts 'no port supplied'.error unless port
|
311
|
-
|
312
|
-
puts ('client connecting to port ' + port).info
|
313
|
-
@obj = DRbObject.new_with_uri("druby://#{host}:#{port}")
|
314
|
-
parent = self
|
315
|
-
@obj&.services.each do |name, methods|
|
316
|
-
|
317
|
-
class_name = name.capitalize
|
318
|
-
klass = Object.const_set(class_name,Class.new)
|
319
|
-
|
320
|
-
klass.class_eval do
|
321
|
-
methods.each do |method_name|
|
322
|
-
define_method method_name do |*args|
|
323
|
-
parent.call name, method_name, *args
|
324
|
-
end
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
define_singleton_method name do
|
329
|
-
klass.new
|
330
|
-
end
|
331
|
-
|
332
|
-
end
|
333
|
-
|
334
|
-
end
|
335
|
-
|
336
|
-
# Makes a remote call in 1 line of code using a URI
|
337
|
-
# e.g. OneDrb::Client.call 'odrb://clara.home/fun/go?arg=James&age=49'
|
338
|
-
#
|
339
|
-
def self.call(s, port: nil)
|
340
|
-
|
341
|
-
r = s.match(/^odrb:\/\/([^\/]+)\/([^\/]+)\/([^\?]+)\??(.*)/).captures
|
342
|
-
|
343
|
-
rawhostname, service, methodname, rawargs = r
|
344
|
-
hostname, rawport = rawhostname.split(':',2)
|
345
|
-
port ||= rawport
|
346
|
-
|
347
|
-
rawargs2 = rawargs&.split('&').map {|x| x.split('=')}
|
348
|
-
|
349
|
-
a1, a2 = rawargs2.partition do |field, value|
|
350
|
-
field.downcase.to_sym == :arg
|
351
|
-
end
|
352
|
-
|
353
|
-
h = a2.map {|k,v| [k.to_sym, v]}.to_h
|
354
|
-
a = a1.map(&:last)
|
355
|
-
|
356
|
-
client = OneDrb::Client.new host: hostname, port: port
|
357
|
-
|
358
|
-
if h.any? then
|
359
|
-
|
360
|
-
if a.any? then
|
361
|
-
client.call service.to_sym, methodname.to_sym, *a, **h
|
362
|
-
else
|
363
|
-
client.call service.to_sym, methodname.to_sym, **h
|
364
|
-
end
|
365
|
-
|
366
|
-
elsif a.any?
|
367
|
-
|
368
|
-
client.call service.to_sym, methodname.to_sym, *a
|
369
|
-
|
370
|
-
else
|
371
|
-
|
372
|
-
client.call service.to_sym, methodname.to_sym
|
373
|
-
|
374
|
-
end
|
375
|
-
|
376
|
-
end
|
377
|
-
|
378
|
-
def remote()
|
379
|
-
@obj
|
380
|
-
end
|
381
|
-
|
382
|
-
def method_missing(sym, *args)
|
383
|
-
|
384
|
-
puts '@obj.class: ' + @obj.class.inspect
|
385
|
-
|
386
|
-
if args.last.is_a?(Hash) then
|
387
|
-
@obj.send(sym, *args[0..-2], **args.last)
|
388
|
-
else
|
389
|
-
@obj.send(sym, *args)
|
390
|
-
end
|
391
|
-
|
392
|
-
end
|
393
|
-
|
394
|
-
end
|
395
|
-
|
396
|
-
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onedrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
lK7OtCGPauDHVuIWDW0EnHb+MMBt6F5SqC+PSy9iOzs4zAWkJMFp86MOEK2yrfnO
|
36
36
|
/ghrVtneK08DqmYOaive8I6P
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2022-04-
|
38
|
+
date: 2022-04-25 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: c32
|
metadata.gz.sig
CHANGED
Binary file
|