pipe_rpc 2.3.0 → 2.4.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 +4 -4
- data/lib/pipe_rpc/_pipe_rpc.rb +18 -0
- data/lib/pipe_rpc/basic_interface.rb +7 -13
- data/lib/pipe_rpc/client.rb +3 -14
- data/lib/pipe_rpc/client_request.rb +1 -1
- data/lib/pipe_rpc/client_request_result.rb +1 -1
- data/lib/pipe_rpc/hub.rb +2 -1
- data/lib/pipe_rpc/hub_request.rb +1 -1
- data/lib/pipe_rpc/hub_request_result.rb +1 -1
- data/lib/pipe_rpc/hub_servers.rb +2 -2
- data/lib/pipe_rpc/hub_transport_mapper.rb +30 -0
- data/lib/pipe_rpc/mapper.rb +17 -0
- data/lib/pipe_rpc/server.rb +27 -0
- data/lib/pipe_rpc/version.rb +1 -1
- metadata +5 -3
- data/lib/pipe_rpc/hub_server.rb +0 -40
- data/lib/pipe_rpc/transport_mapper.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 404b904e9d7fdd27b2fd405391e5436fef8209ff
|
4
|
+
data.tar.gz: ffff7dbe2b497f70071cb1cb1af302f59cc50f2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 862dd2c6bb48569342693dfeec30f0844698bb4440cb0c11d29b5740de180b8c7c6ede268976a7f1d6ac5d2d2e27d82d1dfcbea4918e1802dd357e198eb5ada1
|
7
|
+
data.tar.gz: 937143f71bca5bfc7c50676e0d68ad6c3bae864915273c0fbf7c8dc00e6393d7b6bdb1ae0b963909f44616a8c7ef1f8e2bfcd201337ff53d374a5fc1ccd7a662
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Module.class_eval do
|
2
|
+
def dup_including(*methods)
|
3
|
+
dup.class_eval do
|
4
|
+
aliased = (methods.last.is_a? Hash) ? methods.last : {}
|
5
|
+
aliased.each{ |from, to| alias_method to, from }
|
6
|
+
|
7
|
+
to_be_kept_methods = methods + aliased.values
|
8
|
+
(all_instance_methods - to_be_kept_methods).each{ |m| remove_method m }
|
9
|
+
|
10
|
+
self
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def all_instance_methods
|
15
|
+
private_methods = (respond_to? :private_instance_methods) ? private_instance_methods : []
|
16
|
+
instance_methods + private_methods
|
17
|
+
end
|
18
|
+
end
|
@@ -1,26 +1,20 @@
|
|
1
1
|
module PipeRpc
|
2
2
|
class BasicInterface < BasicObject
|
3
|
+
def self.const_missing(name)
|
4
|
+
::Object.const_get(name)
|
5
|
+
end
|
6
|
+
|
3
7
|
wanted_methods = [:initialize, :__id__, :object_id, :__send__, :respond_to?, :method_missing]
|
8
|
+
wanted_methods += (Object.const_defined? :MRUBY_VERSION) ? [:!] : [:!, :==, :!=, :equal?]
|
4
9
|
|
5
|
-
existing_methods =
|
6
|
-
[:initialize, :method_missing]
|
7
|
-
else
|
8
|
-
[:initialize, :__id__, :__send__, :instance_eval, :instance_exec, :method_missing,
|
9
|
-
:singleton_method_added, :singleton_method_removed, :singleton_method_undefined]
|
10
|
-
end
|
10
|
+
existing_methods = BasicObject.all_instance_methods
|
11
11
|
|
12
12
|
# Remove unwanted methods
|
13
13
|
unwanted_methods = existing_methods - wanted_methods
|
14
14
|
unwanted_methods.each { |m| undef_method m }
|
15
15
|
|
16
16
|
# Add non-existing methods by including sorted out Kernel module
|
17
|
-
|
18
|
-
kernel = ::Kernel.dup
|
19
|
-
kernel.class_eval do
|
20
|
-
(instance_methods - to_be_added_methods).each{ |m| remove_method m }
|
21
|
-
private_instance_methods.each{ |m| remove_method m } if respond_to? :private_instance_methods
|
22
|
-
end
|
23
|
-
include kernel
|
17
|
+
include Kernel.dup_including *(wanted_methods - existing_methods)
|
24
18
|
|
25
19
|
alias send __send__
|
26
20
|
end
|
data/lib/pipe_rpc/client.rb
CHANGED
@@ -5,9 +5,12 @@ module PipeRpc
|
|
5
5
|
def initialize(server_id = :default, hub)
|
6
6
|
Kernel.raise ClientInitializationError.new("server id #{server_id.inspect} no symbol") unless server_id.is_a? Symbol
|
7
7
|
@__rpc_server_id__ = server_id
|
8
|
+
@__rpc_server_class_name__ = server_id.to_s.split('#').first
|
8
9
|
@hub = hub
|
9
10
|
end
|
10
11
|
|
12
|
+
attr_reader :__rpc_server_class_name__, :__rpc_server_id__
|
13
|
+
|
11
14
|
def respond_to?(method)
|
12
15
|
super or method_missing(:respond_to?, method)
|
13
16
|
end
|
@@ -21,18 +24,4 @@ module PipeRpc
|
|
21
24
|
"#{TRANSPORT_PREFIX}#{@__rpc_server_id__}"
|
22
25
|
end
|
23
26
|
end
|
24
|
-
|
25
|
-
class << Client
|
26
|
-
def const_missing(name)
|
27
|
-
::Object.const_get(name)
|
28
|
-
end
|
29
|
-
|
30
|
-
def from_rpc_transport?(transport)
|
31
|
-
(transport.is_a? String) and (transport.start_with? Hub::Server::TRANSPORT_PREFIX)
|
32
|
-
end
|
33
|
-
|
34
|
-
def from_rpc_transport(hub, transport)
|
35
|
-
hub.clients[transport.sub(Hub::Server::TRANSPORT_PREFIX, '').to_sym]
|
36
|
-
end
|
37
|
-
end
|
38
27
|
end
|
@@ -4,7 +4,7 @@ module PipeRpc
|
|
4
4
|
class Client::Request < Request
|
5
5
|
def initialize(hub, request)
|
6
6
|
@hub = hub
|
7
|
-
request[:arguments] =
|
7
|
+
request[:arguments] = hub.transport_mapper.to_transport request[:arguments]
|
8
8
|
super request
|
9
9
|
# discard first three entries mentioning Client::Request#initialize,
|
10
10
|
# Client::Request.new and Client#method_missing in stacktrace
|
@@ -18,7 +18,7 @@ module PipeRpc
|
|
18
18
|
@value.set_backtrace(@value.backtrace.to_a + @request.stacktrace) if @value.respond_to? :set_backtrace
|
19
19
|
raise @value
|
20
20
|
else
|
21
|
-
|
21
|
+
@request.hub.transport_mapper.from_transport @value
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/lib/pipe_rpc/hub.rb
CHANGED
@@ -6,9 +6,10 @@ module PipeRpc
|
|
6
6
|
@requests = Requests.new(self)
|
7
7
|
@servers = Servers.new
|
8
8
|
@clients = Clients.new(self)
|
9
|
+
@transport_mapper = TransportMapper.new(self)
|
9
10
|
end
|
10
11
|
|
11
|
-
attr_reader :channel, :servers, :clients, :requests, :socket
|
12
|
+
attr_reader :channel, :servers, :clients, :requests, :socket, :transport_mapper
|
12
13
|
|
13
14
|
def handle_message
|
14
15
|
Message.new(self, @socket.read).handle
|
data/lib/pipe_rpc/hub_request.rb
CHANGED
@@ -12,7 +12,7 @@ module PipeRpc
|
|
12
12
|
def handle
|
13
13
|
evaluate_result do
|
14
14
|
# the block is passed for asynchronous evaluation
|
15
|
-
mapped_arguments =
|
15
|
+
mapped_arguments = @hub.transport_mapper.from_transport arguments
|
16
16
|
@hub.servers[server].__send__(method, *mapped_arguments, &evaluate_result_proc)
|
17
17
|
end
|
18
18
|
end
|
data/lib/pipe_rpc/hub_servers.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module PipeRpc
|
2
|
+
class Mapper; end
|
3
|
+
class Hub::TransportMapper < Mapper
|
4
|
+
def initialize(hub)
|
5
|
+
@hub = hub
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_transport(object)
|
9
|
+
map(object) do |value|
|
10
|
+
if value.respond_to? :to_rpc_transport
|
11
|
+
value.to_rpc_transport(@hub)
|
12
|
+
else
|
13
|
+
value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def from_transport(object)
|
19
|
+
map(object) do |value|
|
20
|
+
if (value.is_a? String) and (value.start_with? Client::TRANSPORT_PREFIX)
|
21
|
+
@hub.servers[value.sub(Client::TRANSPORT_PREFIX, '').to_sym]
|
22
|
+
elsif (value.is_a? String) and (value.start_with? Server::TRANSPORT_PREFIX)
|
23
|
+
@hub.clients[value.sub(Server::TRANSPORT_PREFIX, '').to_sym]
|
24
|
+
else
|
25
|
+
value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PipeRpc
|
2
|
+
class Mapper
|
3
|
+
def map(object, &mapper)
|
4
|
+
if Client === object
|
5
|
+
# first filter out clients so for them subsequent checks are not sent
|
6
|
+
# through the pipe
|
7
|
+
yield object
|
8
|
+
elsif Hash === object
|
9
|
+
object.map{ |k, v| [k, map(v, &mapper)] }.to_h
|
10
|
+
elsif object.respond_to? :map
|
11
|
+
object.map{ |item| map(item, &mapper) }
|
12
|
+
else
|
13
|
+
yield object
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module PipeRpc
|
2
|
+
class Server < BasicInterface
|
3
|
+
TRANSPORT_PREFIX = "__rpc_server__"
|
4
|
+
|
5
|
+
include Kernel.dup_including :object_id, class: :__class__
|
6
|
+
private :__class__
|
7
|
+
|
8
|
+
def __rpc_server_class_name__
|
9
|
+
__class__.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def __rpc_server_id__
|
13
|
+
"#{__rpc_server_class_name__}##{__id__}".to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_rpc_transport(hub)
|
17
|
+
hub.servers.add(self) unless hub.servers.registered? __rpc_server_id__
|
18
|
+
"#{TRANSPORT_PREFIX}#{__rpc_server_id__}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class << Server
|
23
|
+
def instance_eval_for(server, *args, &block)
|
24
|
+
Object.instance_method(:instance_eval).bind(server).call(*args, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/pipe_rpc/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipe_rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Aue
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- Rakefile
|
99
99
|
- lib/msgpack_config.rb
|
100
100
|
- lib/pipe_rpc.rb
|
101
|
+
- lib/pipe_rpc/_pipe_rpc.rb
|
101
102
|
- lib/pipe_rpc/basic_interface.rb
|
102
103
|
- lib/pipe_rpc/client.rb
|
103
104
|
- lib/pipe_rpc/client_request.rb
|
@@ -117,12 +118,13 @@ files:
|
|
117
118
|
- lib/pipe_rpc/hub_request_error_result.rb
|
118
119
|
- lib/pipe_rpc/hub_request_result.rb
|
119
120
|
- lib/pipe_rpc/hub_requests.rb
|
120
|
-
- lib/pipe_rpc/hub_server.rb
|
121
121
|
- lib/pipe_rpc/hub_servers.rb
|
122
122
|
- lib/pipe_rpc/hub_socket.rb
|
123
|
+
- lib/pipe_rpc/hub_transport_mapper.rb
|
124
|
+
- lib/pipe_rpc/mapper.rb
|
123
125
|
- lib/pipe_rpc/request.rb
|
124
126
|
- lib/pipe_rpc/result_response.rb
|
125
|
-
- lib/pipe_rpc/
|
127
|
+
- lib/pipe_rpc/server.rb
|
126
128
|
- lib/pipe_rpc/version.rb
|
127
129
|
- pipe_rpc.gemspec
|
128
130
|
homepage: https://github.com/christopheraue/ruby-pipe_rpc
|
data/lib/pipe_rpc/hub_server.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module PipeRpc
|
2
|
-
class Hub::Server < BasicInterface
|
3
|
-
TRANSPORT_PREFIX = "__rpc_server__"
|
4
|
-
|
5
|
-
kernel = ::Kernel.dup
|
6
|
-
kernel.class_eval do
|
7
|
-
alias_method :__rpc_server_class__, :class
|
8
|
-
(instance_methods - [:__rpc_server_class__, :object_id]).each{ |m| remove_method m }
|
9
|
-
private_instance_methods.each{ |m| remove_method m } if respond_to? :private_instance_methods
|
10
|
-
end
|
11
|
-
include kernel
|
12
|
-
|
13
|
-
def to_rpc_server_id
|
14
|
-
"#{__rpc_server_class__}##{__id__}".to_sym
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_rpc_transport(hub)
|
18
|
-
hub.servers.add(self) unless hub.servers.registered? to_rpc_server_id
|
19
|
-
"#{TRANSPORT_PREFIX}#{to_rpc_server_id}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class << Hub::Server
|
24
|
-
def const_missing(name)
|
25
|
-
::Object.const_get(name)
|
26
|
-
end
|
27
|
-
|
28
|
-
def instance_eval_for(server, *args, &block)
|
29
|
-
Object.instance_method(:instance_eval).bind(server).call(*args, &block)
|
30
|
-
end
|
31
|
-
|
32
|
-
def from_rpc_transport?(transport)
|
33
|
-
(transport.is_a? String) and (transport.start_with? Client::TRANSPORT_PREFIX)
|
34
|
-
end
|
35
|
-
|
36
|
-
def from_rpc_transport(hub, transport)
|
37
|
-
hub.servers[transport.sub(Client::TRANSPORT_PREFIX, '').to_sym]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module PipeRpc
|
2
|
-
class TransportMapper
|
3
|
-
def self.map(object, &mapper)
|
4
|
-
if Client === object
|
5
|
-
# first filter out clients so for them subsequent checks are not sent
|
6
|
-
# through the pipe
|
7
|
-
yield object
|
8
|
-
elsif Hash === object
|
9
|
-
object.map{ |k, v| [k, map(v, &mapper)] }.to_h
|
10
|
-
elsif object.respond_to? :map
|
11
|
-
object.map{ |item| map(item, &mapper) }
|
12
|
-
else
|
13
|
-
yield object
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.to_transport(object, hub)
|
18
|
-
map(object) do |value|
|
19
|
-
if value.respond_to? :to_rpc_transport
|
20
|
-
value.to_rpc_transport(hub)
|
21
|
-
else
|
22
|
-
value
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.from_transport(object, hub)
|
28
|
-
map(object) do |value|
|
29
|
-
if Hub::Server.from_rpc_transport? value
|
30
|
-
Hub::Server.from_rpc_transport(hub, value)
|
31
|
-
elsif Client.from_rpc_transport? value
|
32
|
-
Client.from_rpc_transport(hub, value)
|
33
|
-
else
|
34
|
-
value
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|