onedrb 0.2.0 → 0.4.1

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: 0e1dea351f77a02d587369c3d60ee375e608c1e10c42598012403c101c54cff6
4
- data.tar.gz: 31e34ab07655ab42669955f8a02dcf68c0afa3989797e6b8cd6765f0b9bff61d
3
+ metadata.gz: 3829bafa21b51494d1bc147e668427dddc6998da520a60e14eefcd6b9c99c8e5
4
+ data.tar.gz: 26afcc85a10fb500e8f4e8d9c69ff2d1c23def83b0feed1b6279e7df958742f0
5
5
  SHA512:
6
- metadata.gz: 2abc2da0df0795521dd76c3e610ccdfa7e6f7b3bbac546e4c167364e7b1797786749326b235bbe9487f54c19087ac2033cab8b89a287d6e4efe1093e74c6db8b
7
- data.tar.gz: fc4a215efd2142d0852ef91b2f6fa8749599a20fe8cb923430c1e04aace1177139293613d7f3a4cfb5996d536800140d95ff77e5dc989a5156de1e5586e689d1
6
+ metadata.gz: 4d41f05105f22e8be82720dd89d0199c643ac76817ca04ae43c40132bb2d07004a9311be375bb296775834fb0e9591ce113d927fb410d1dab109601e076b73aa
7
+ data.tar.gz: 725672d9bf14d981f1df49be58699194bea4f722379d319a8bd84af5c89be26c8760c3c5e1d0990d6459cb29aa9462ee8b7d7974e816d936460b150ac2022eff
checksums.yaml.gz.sig CHANGED
@@ -1,4 +1,4 @@
1
- ��;���ad��2̀���Z5$�G-w��'�Y��w��L �����6��uu e�`P|�!8���w'�@�^��R.�׶���Zd�{PG}�>ը-�W��;�ќ���v�x׽��1�X9R�ӱ?�*��VT4s��]�𰣇1�A�s�[K䄔���7+��8Ǝ
2
- �Xx��S1�@�Rf
3
- Fg�Pu���{K��L $bIe����B���KA\���U��'���;#_;5k��L�kk�%��
4
- X�?�_BtR����\\�P)����BnR7��캥:�X��.���Oy��&6}c0��B�]c���[0TM��)uE.W��{�ٳsZUE!��9ѻ�OEu� ��c����+�NƼ)vS�xU���&d
1
+ k��r
2
+ z:��!���+�z괆dv%wF�l���%C�`�R
3
+ 2kހ�dh�F�q+T ʟ���08�<(y/���JE7�bv�w�#�TrS�KUI;�9=F�I ��q��@��Y����w{�zȇ��܃�?��U���=_t�>�[B��ҍ�K��j X$2H�����-2��7P���'%�,�a���J��S�I
4
+ ���������Ƨ��1Uq1�>z&��U��fSXQ���饊@r1ݩ�M�P���80\��D�GYE��S>�
data/lib/onedrb.rb CHANGED
@@ -6,10 +6,48 @@
6
6
 
7
7
  require 'drb'
8
8
  require 'c32'
9
+ require 'app-mgr'
9
10
 
10
- # Note: The Server object can also use a default Hash object.
11
- # Which allows the Client object to define what user-defined objects the server
12
- # should host dynamically.
11
+
12
+ # Note: The Server object can also use a default ServiceMgr object.
13
+ # Which allows multiple services (user-defined objects) to be
14
+ # hosted dynamically.
15
+ # OneDrb recommended port: 57844 (as this port is recognised by the RSC gem)
16
+ #
17
+ class ServiceMgr < AppMgr
18
+
19
+ def initialize(rsf: nil, debug: false)
20
+ super(rsf: rsf, type: 'service', debug: debug)
21
+ @services = @app
22
+ end
23
+
24
+
25
+ def call(service, methodname, *a)
26
+
27
+ return @services[service.to_sym][:running] unless methodname
28
+ proc1 = @services[service.to_sym][:running].method(methodname.to_sym)
29
+ a.last.is_a?(Hash) ? proc1.call(*a[0..-2], **a.last) : proc1.call(*a)
30
+
31
+ end
32
+
33
+
34
+ # OneDRb version 2; Allows multiple user-defined objects to be
35
+ # served from 1 DRb service
36
+ #
37
+ # not used by any client, but may be in future
38
+ #
39
+ #def odrb2?()
40
+ # true
41
+ #end
42
+
43
+ def services()
44
+ @services.map do |key, object|
45
+ next unless object[:running]
46
+ [key, object[:running].public_methods - Object.public_methods]
47
+ end.compact
48
+ end
49
+
50
+ end
13
51
 
14
52
 
15
53
  class OneDrbError < Exception
@@ -22,7 +60,7 @@ module OneDrb
22
60
  using ColouredText
23
61
 
24
62
  def initialize(host: '127.0.0.1', port: (49152..65535).to_a.sample.to_s,
25
- obj: Hash.new, log: nil)
63
+ obj: nil, log: nil)
26
64
 
27
65
  log.info self.class.to_s + '/initialize: active' if log
28
66
 
@@ -63,10 +101,18 @@ module OneDrb
63
101
 
64
102
  puts ('client connecting to port ' + port).info
65
103
  @obj = DRbObject.new_with_uri("druby://#{host}:#{port}")
104
+ parent = self
105
+ @obj&.services.each do |name, methods|
106
+
107
+ make_class(name, methods, parent)
108
+
109
+ end
66
110
 
67
111
  end
68
112
 
69
113
  # Makes a remote call in 1 line of code using a URI
114
+ # Only available when using the ServiceMgr as the server object;
115
+ #
70
116
  # e.g. OneDrb::Client.call 'odrb://clara.home/fun/go?arg=James&age=49'
71
117
  #
72
118
  def self.call(s, port: nil)
@@ -87,9 +133,24 @@ module OneDrb
87
133
  a = a1.map(&:last)
88
134
 
89
135
  client = OneDrb::Client.new host: hostname, port: port
90
- proc1 = client[service].method(methodname.to_sym)
91
136
 
92
- h.any? ? proc1.call(*a, **h) : proc1.call(*a)
137
+ if h.any? then
138
+
139
+ if a.any? then
140
+ client.call service.to_sym, methodname.to_sym, *a, **h
141
+ else
142
+ client.call service.to_sym, methodname.to_sym, **h
143
+ end
144
+
145
+ elsif a.any?
146
+
147
+ client.call service.to_sym, methodname.to_sym, *a
148
+
149
+ else
150
+
151
+ client.call service.to_sym, methodname.to_sym
152
+
153
+ end
93
154
 
94
155
  end
95
156
 
@@ -97,6 +158,15 @@ module OneDrb
97
158
  @obj
98
159
  end
99
160
 
161
+ def restart(service)
162
+
163
+ return unless @obj.respond_to? :services
164
+
165
+ @obj.restart(service)
166
+ found = @obj.services.assoc(service)
167
+ make_class(*found, self) if found.any?
168
+ end
169
+
100
170
  def method_missing(sym, *args)
101
171
 
102
172
  if args.last.is_a?(Hash) then
@@ -107,6 +177,27 @@ module OneDrb
107
177
 
108
178
  end
109
179
 
180
+ private
181
+
182
+ def make_class(name, methods, parent)
183
+
184
+ class_name = name.capitalize
185
+ klass = Object.const_set(class_name,Class.new)
186
+
187
+ klass.class_eval do
188
+ methods.each do |method_name|
189
+ define_method method_name do |*args|
190
+ parent.call name, method_name, *args
191
+ end
192
+ end
193
+ end
194
+
195
+ define_singleton_method name do
196
+ klass.new
197
+ end
198
+
199
+ end
200
+
110
201
  end
111
202
 
112
203
  end
data.tar.gz.sig CHANGED
@@ -1,2 +1,4 @@
1
- ��y��JEZ��k��Ax8f~���3WQ��ݦ`o���K={
2
- �NŽAс��WǵD�h4‰21���߂>b�N�f�dA"_�IS����x��s����ZP0��fL�sU�
1
+ ��ʟ�r՛�{Xұd����wU�"%qC+ S��sߊ>~�Ҕ�gOF�Ұ��!�Qُ�NWdǨxm���މ���*~辱
2
+ �\n&rF? a+?�4�MC�@�UrŞ=w7 >z��Y~bȝS�R)d0�=��CP�@�E
3
+ @�R�DB�(N�R�Ɍ�܃�r��`�:���x���Z*�x5�P�i�� R�r6�
4
+ ������[�
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.2.0
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-22 00:00:00.000000000 Z
38
+ date: 2022-04-25 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: c32
@@ -57,6 +57,26 @@ dependencies:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: 0.3.0
60
+ - !ruby/object:Gem::Dependency
61
+ name: app-mgr
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.4'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 0.4.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.4'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 0.4.0
60
80
  description:
61
81
  email: digital.robertson@gmail.com
62
82
  executables: []
metadata.gz.sig CHANGED
@@ -1,3 +1,4 @@
1
- ��:r�\�y���}�h�r^4����i�Z�=�%�G�1��Dy�JI�`۲ �|��Ǔ��@��F�Su����7mԝ�_}����Q���BZ2��T� L�;����5l��� php�ڱ���t��ҹ���])F�.VB�?= }��\� #��F)�}M
2
- ��p��A��B5�[R(�?�g���
3
- ��X�� N��Q~��� �ն�_��/d����Kτh�-��2�# 50xBY�<��\�X$�V(�\A!B&�ڇ�.�@�*$Z��aX��쑣�n��HZ����EAI����N�lDg���3�X�/���(��� ��ԩ������ƭ�[w]0p�D���t��2c�� �}W��Į�R�
1
+ ����6��
2
+ ��'d~��
3
+ ɍP�X��"u *B�Tm��SYkHU5���aNUT���
4
+ �G'z�Q�U8~ĥ�an�!KaWكO�Mɽ[���^��������"<<�i62<aŷ��,��h����8�+x��E�6�wW;[:mUdp�Qk:'jB��=�ZWo�l'A�B�&��dGy��&