pipe_rpc 1.0.0 → 1.1.0

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
  SHA1:
3
- metadata.gz: db3929008eaf1ac0b4d3d3d2f54ca17ea82ffa9c
4
- data.tar.gz: 7737ad82b6cc89bb348179659b64617f28a5b1a1
3
+ metadata.gz: d754a16c8369ffd2cfbeda827a6ec49028326c21
4
+ data.tar.gz: 20c0a704f6f64b13f2a2a661bec384c3f8d117d6
5
5
  SHA512:
6
- metadata.gz: 5a70e27fe8b73c7630c1101f4234d78d991254965c598839622763bd5f37197294bbef0dbdaad93f0f3b35c5659f36f88157fbba6a9d8f5b0a809b8b96f0f70d
7
- data.tar.gz: a4ebe6276e87fb6d8613c4f8f721c59c001e6f8635a029848ef0c3be912aaafe44c5f6015c7691af1400557c2d275b0fc2af09d1d7615f0f90c0c317947ff545
6
+ metadata.gz: 340cdcba3e23c86ecaba149671f948e27a73e27f97737c3e03507ac9ff8b49b678341270b5e0f2f2529257bcc2cf1f3bcf16b62a02a9708bd13c05f2db99695e
7
+ data.tar.gz: 526a134f5533eda00100d4459ef8885688a3a581cb518515ceb7d5e7e0608f3f1888ca1aadd08738718ff935d830c375561d8a5eb2745f6b17a4e6ee65b5b35e
@@ -21,9 +21,7 @@ module PipeRpc
21
21
  private
22
22
 
23
23
  def no_method_error
24
- method = @data.fetch(:method)
25
- args = @data.fetch(:args)
26
- NoMethodError.new("undefined method `#{method}' for <Client:#{@request.server}>", method, args)
24
+ NoMethodError.new("undefined method `#{@data.fetch(:method)}' for <Client:#{@request.server}>")
27
25
  end
28
26
 
29
27
  def argument_error
@@ -1,5 +1,5 @@
1
1
  module PipeRpc
2
- class Error < RuntimeError; end
2
+ class Error < StandardError; end
3
3
  class ClosedError < Error; end
4
4
  class UnknownError < Error; end
5
5
 
@@ -7,8 +7,10 @@ module PipeRpc
7
7
  class MessageParseError < MessageError; end
8
8
  class InvalidMessageError < MessageError; end
9
9
 
10
- class NoRequestForResponseError < Error; end
11
- class NoServerError < Error; end
12
- class InternalError < Error; end
13
- class ReflectedError < Error; end
10
+ class EvaluationError < Error; end
11
+ class NoMethodError < EvaluationError; end
12
+ class ArgumentError < EvaluationError; end
13
+ class InternalError < EvaluationError; end
14
+ class NoServerError < EvaluationError; end
15
+ class ReflectedError < EvaluationError; end
14
16
  end
@@ -18,6 +18,16 @@ module PipeRpc
18
18
  @body.has_key? :error and @body[:id].nil?
19
19
  end
20
20
 
21
+ def handle
22
+ if response?
23
+ guarded{ handler.handle if handler }
24
+ else
25
+ handler.handle if handler
26
+ end
27
+ end
28
+
29
+ private
30
+
21
31
  def handler_type
22
32
  if request?
23
33
  Hub::Request
@@ -31,18 +41,16 @@ module PipeRpc
31
41
  end
32
42
 
33
43
  def handler
34
- handler_type.new(@hub, @body)
44
+ @handler ||= guarded{ handler_type.new(@hub, @body) }
45
+ end
46
+
47
+ def guarded
48
+ yield
35
49
  rescue => e
36
- @hub.socket.write ErrorResponse.new(id: @body[:id], error: { code: -32600,
50
+ @hub.socket.write PipeRpc::ErrorResponse.new(id: @body[:id], error: { code: -32600,
37
51
  data: { message: e.message } })
38
52
  nil
39
53
  end
40
-
41
- def handle
42
- handler.tap do |handler|
43
- handler.handle if handler
44
- end
45
- end
46
54
  end
47
55
  end
48
56
  end
@@ -23,9 +23,11 @@ module PipeRpc
23
23
  end
24
24
 
25
25
  def inject_result_for(id, result)
26
- request = @requests.delete(id)
27
- raise NoRequestForResponseError.new("no request with id '#{id.inspect}'") unless request
28
- request.result.value = result
26
+ if request = @requests.delete(id)
27
+ request.result.value = result
28
+ else
29
+ raise "no request with id '#{id.inspect}'"
30
+ end
29
31
  end
30
32
 
31
33
  def wait_for_results_through(iteration)
@@ -1,3 +1,3 @@
1
1
  module PipeRpc
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
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: 1.0.0
4
+ version: 1.1.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-04-14 00:00:00.000000000 Z
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json