pipe_rpc 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/lib/pipe_rpc/basic_interface.rb +1 -1
- data/lib/pipe_rpc/client.rb +0 -4
- data/lib/pipe_rpc/client_request.rb +1 -22
- data/lib/pipe_rpc/client_request_result.rb +1 -3
- data/lib/pipe_rpc/deep_mapper.rb +36 -0
- data/lib/pipe_rpc/error.rb +1 -0
- data/lib/pipe_rpc/hub_request.rb +5 -2
- data/lib/pipe_rpc/hub_request_result.rb +2 -2
- data/lib/pipe_rpc/hub_server.rb +4 -2
- data/lib/pipe_rpc/hub_servers.rb +10 -4
- data/lib/pipe_rpc/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 133a22837afd6032e1de590b632c2715f4e4913c
|
4
|
+
data.tar.gz: aa8338e1c9f4d3fad11f5a1ca2b3923c1704b023
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 924584159e80cf3e6dfec8ccf288ba122985e0f9a29f6e3f8734b74cca608436e0b15f34aeeb409bd53990d5957f2b7688d84687eb06bd02e17ded15a13575d9
|
7
|
+
data.tar.gz: 997155d89f123a5da38e7190a9e6d1de9d1e46e479c84834c1a810b5f5279da6d757b71b4f49d7612780716e5a84544bcade5c942287837d2482659a4fbad9be
|
data/.rspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module PipeRpc
|
2
2
|
class BasicInterface < BasicObject
|
3
|
-
wanted_methods = [:initialize, :__id__, :__send__, :respond_to?, :method_missing]
|
3
|
+
wanted_methods = [:initialize, :__id__, :object_id, :__send__, :respond_to?, :method_missing]
|
4
4
|
|
5
5
|
existing_methods = if ::Object.const_defined?(:MRUBY_VERSION)
|
6
6
|
[:initialize, :method_missing]
|
data/lib/pipe_rpc/client.rb
CHANGED
@@ -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] = DeepMapper.to_transport(request[:arguments], hub)
|
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
|
@@ -22,26 +22,5 @@ module PipeRpc
|
|
22
22
|
def id
|
23
23
|
@id or raise 'id not set'
|
24
24
|
end
|
25
|
-
|
26
|
-
def arguments_to_server_ids(arguments)
|
27
|
-
deep_map(arguments) do |value|
|
28
|
-
if value.respond_to? :__rpc_server_id__ # is a client
|
29
|
-
value.__rpc_server_id__
|
30
|
-
elsif value.respond_to? :to_rpc_server_id # is a servable
|
31
|
-
@hub.servers.add(value)
|
32
|
-
value.to_rpc_server_id
|
33
|
-
else
|
34
|
-
value
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def deep_map(object, &mapper)
|
40
|
-
case object
|
41
|
-
when Hash then object.map{ |k, v| [k, deep_map(v, &mapper)] }.to_h
|
42
|
-
when Array then object.map{ |item| deep_map(item, &mapper) }
|
43
|
-
else yield object
|
44
|
-
end
|
45
|
-
end
|
46
25
|
end
|
47
26
|
end
|
@@ -18,9 +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
|
-
|
22
|
-
(@request.hub.servers.registered? value) ? @request.hub.servers[value] : value
|
23
|
-
end
|
21
|
+
DeepMapper.from_transport(@value, @request.hub)
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module PipeRpc
|
2
|
+
class DeepMapper
|
3
|
+
def self.map(object, &mapper)
|
4
|
+
case object
|
5
|
+
when Hash then object.map{ |k, v| [k, map(v, &mapper)] }.to_h
|
6
|
+
when Array then object.map{ |item| map(item, &mapper) }
|
7
|
+
else yield object
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.to_transport(object, hub)
|
12
|
+
map(object) do |value|
|
13
|
+
if value.respond_to? :__rpc_server_id__
|
14
|
+
"__rpc_client__#{value.__rpc_server_id__}"
|
15
|
+
elsif value.respond_to? :to_rpc_server_id
|
16
|
+
hub.servers.add(value) unless hub.servers.registered? value.to_rpc_server_id
|
17
|
+
"__rpc_server__#{value.to_rpc_server_id}"
|
18
|
+
else
|
19
|
+
value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.from_transport(object, hub)
|
25
|
+
map(object) do |value|
|
26
|
+
if value.is_a?(String) and value.start_with?('__rpc_client__')
|
27
|
+
hub.servers[value.sub('__rpc_client__', '')]
|
28
|
+
elsif value.is_a?(String) and value.start_with?('__rpc_server__')
|
29
|
+
Client.new(value.sub('__rpc_server__', ''), hub)
|
30
|
+
else
|
31
|
+
value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/pipe_rpc/error.rb
CHANGED
data/lib/pipe_rpc/hub_request.rb
CHANGED
@@ -7,13 +7,16 @@ module PipeRpc
|
|
7
7
|
super body
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
attr_reader :hub
|
11
|
+
|
11
12
|
def handle
|
12
13
|
evaluate_result do
|
13
14
|
# the block is passed for asynchronous evaluation
|
14
|
-
|
15
|
+
mapped_arguments = DeepMapper.from_transport(arguments, @hub)
|
16
|
+
@hub.servers[server].__send__(method, *mapped_arguments, &evaluate_result_proc)
|
15
17
|
end
|
16
18
|
end
|
19
|
+
CALL_FILE, CALL_LINENO = __FILE__, __LINE__-3
|
17
20
|
|
18
21
|
def evaluate_result(result = nil, &block)
|
19
22
|
result = Result.new(self, block_given? ? yield : result)
|
@@ -5,11 +5,11 @@ module PipeRpc
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def value
|
8
|
-
@result
|
8
|
+
DeepMapper.to_transport(@result, @request.hub)
|
9
9
|
end
|
10
10
|
|
11
11
|
def to_response
|
12
|
-
ResultResponse.new(id: @request.id, result:
|
12
|
+
ResultResponse.new(id: @request.id, result: value)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/pipe_rpc/hub_server.rb
CHANGED
@@ -3,17 +3,19 @@ module PipeRpc
|
|
3
3
|
kernel = ::Kernel.dup
|
4
4
|
kernel.class_eval do
|
5
5
|
alias_method :__rpc_server_class__, :class
|
6
|
-
(instance_methods - [:__rpc_server_class__]).each{ |m| remove_method m }
|
6
|
+
(instance_methods - [:__rpc_server_class__, :object_id]).each{ |m| remove_method m }
|
7
7
|
private_instance_methods.each{ |m| remove_method m } if respond_to? :private_instance_methods
|
8
8
|
end
|
9
9
|
include kernel
|
10
10
|
|
11
|
+
SERVER_ID_GETTER = :__id__
|
12
|
+
|
11
13
|
def self.const_missing(name)
|
12
14
|
::Object.const_get(name)
|
13
15
|
end
|
14
16
|
|
15
17
|
def to_rpc_server_id
|
16
|
-
"#{
|
18
|
+
"#{__rpc_server_class__.to_s}##{__send__(__rpc_server_class__::SERVER_ID_GETTER)}".to_sym
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
data/lib/pipe_rpc/hub_servers.rb
CHANGED
@@ -4,11 +4,17 @@ module PipeRpc
|
|
4
4
|
@servers = Hash.new{ |hash, key| raise NoServerError.new("no server #{key}") }
|
5
5
|
end
|
6
6
|
|
7
|
-
def add(
|
8
|
-
if
|
9
|
-
|
7
|
+
def add(server)
|
8
|
+
id, server = if server.respond_to? :to_rpc_server_id
|
9
|
+
[server.to_rpc_server_id, server]
|
10
10
|
else
|
11
|
-
|
11
|
+
server.first
|
12
|
+
end
|
13
|
+
|
14
|
+
if registered? id
|
15
|
+
raise ServerRegistrationError.new("server id #{id.inspect} already used for another server")
|
16
|
+
else
|
17
|
+
@servers[id] = server
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|
data/lib/pipe_rpc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipe_rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Aue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/pipe_rpc/client_request_response.rb
|
106
106
|
- lib/pipe_rpc/client_request_result.rb
|
107
107
|
- lib/pipe_rpc/client_request_result_response.rb
|
108
|
+
- lib/pipe_rpc/deep_mapper.rb
|
108
109
|
- lib/pipe_rpc/error.rb
|
109
110
|
- lib/pipe_rpc/error_response.rb
|
110
111
|
- lib/pipe_rpc/gateway.rb
|