mojombo-bertrpc 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.2
data/bertrpc.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{bertrpc}
5
- s.version = "0.3.0"
5
+ s.version = "0.3.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Tom Preston-Werner"]
9
- s.date = %q{2009-09-05}
9
+ s.date = %q{2009-09-07}
10
10
  s.email = %q{tom@mojombo.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -36,12 +36,14 @@ module BERTRPC
36
36
 
37
37
  write(sock, bert_request)
38
38
  lenheader = sock.read(4)
39
- raise ProtocolError.new("Unable to read length header from server.") unless lenheader
39
+ raise ProtocolError.new(ProtocolError::NO_HEADER) unless lenheader
40
40
  len = lenheader.unpack('N').first
41
41
  bert_response = sock.read(len)
42
- raise ProtocolError.new("Unable to read data from server.") unless bert_response
42
+ raise ProtocolError.new(ProtocolError::NO_DATA) unless bert_response
43
43
  sock.close
44
44
  bert_response
45
+ rescue Errno::ECONNREFUSED
46
+ raise ConnectionError.new("Unable to connect to #{@svc.host}:#{@svc.port}")
45
47
  end
46
48
  end
47
49
  end
@@ -1,10 +1,27 @@
1
1
  module BERTRPC
2
2
  class BERTRPCError < StandardError
3
+ attr_accessor :code
4
+ def initialize(msg = nil)
5
+ case msg
6
+ when Array
7
+ self.code = msg[0]
8
+ super(msg[1])
9
+ when String
10
+ self.code = nil
11
+ super(msg)
12
+ else
13
+ super(msg)
14
+ end
15
+ end
16
+ end
17
+
18
+ class ConnectionError < BERTRPCError
3
19
 
4
20
  end
5
21
 
6
22
  class ProtocolError < BERTRPCError
7
-
23
+ NO_HEADER = [0, "Unable to read length header from server."]
24
+ NO_DATA = [1, "Unable to read data from server."]
8
25
  end
9
26
 
10
27
  class ServerError < BERTRPCError
data/test/action_test.rb CHANGED
@@ -67,8 +67,11 @@ class ActionTest < Test::Unit::TestCase
67
67
  io.expects(:write).with("foo")
68
68
  io.expects(:read).with(4).returns(nil)
69
69
  TCPSocket.expects(:new).returns(io)
70
- assert_raises(BERTRPC::ProtocolError) do
70
+ begin
71
71
  @call.transaction("foo")
72
+ fail "Should have thrown an error"
73
+ rescue BERTRPC::ProtocolError => e
74
+ assert_equal 0, e.code
72
75
  end
73
76
  end
74
77
 
@@ -79,8 +82,11 @@ class ActionTest < Test::Unit::TestCase
79
82
  io.expects(:read).with(4).returns("\000\000\000\003")
80
83
  io.expects(:read).with(3).returns(nil)
81
84
  TCPSocket.expects(:new).returns(io)
82
- assert_raises(BERTRPC::ProtocolError) do
85
+ begin
83
86
  @call.transaction("foo")
87
+ fail "Should have thrown an error"
88
+ rescue BERTRPC::ProtocolError => e
89
+ assert_equal 1, e.code
84
90
  end
85
91
  end
86
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mojombo-bertrpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-05 00:00:00 -07:00
12
+ date: 2009-09-07 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -54,7 +54,6 @@ files:
54
54
  - test/test_helper.rb
55
55
  has_rdoc: false
56
56
  homepage: http://github.com/mojombo/bertrpc
57
- licenses:
58
57
  post_install_message:
59
58
  rdoc_options:
60
59
  - --charset=UTF-8
@@ -75,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
74
  requirements: []
76
75
 
77
76
  rubyforge_project:
78
- rubygems_version: 1.3.5
77
+ rubygems_version: 1.2.0
79
78
  signing_key:
80
79
  specification_version: 3
81
80
  summary: BERTRPC is a Ruby BERT-RPC client library.