fastbeans 0.1.3 → 0.2.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/fastbeans/client.rb +4 -6
- data/lib/fastbeans/errors.rb +2 -1
- data/lib/fastbeans/response.rb +29 -0
- data/lib/fastbeans/version.rb +1 -1
- data/lib/fastbeans.rb +12 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04cdb54378919592072c8368e3c26d62366dfde5
|
4
|
+
data.tar.gz: e80257667320c6b26b58134008f6c24417fb6770
|
5
5
|
!binary "U0hBNTEy":
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 278316a00225048129fb1094eb3716368000d0ca6ee98ca9fe1bfc63341d214fc5fd630359fec2cb085161bb951acc272d11d1eb0e1097e349c6d7c182e8f45e
|
7
|
+
data.tar.gz: 1da6d91ff9374c9b11b1f4ddfb41bf58bb4368b3f33b40e29dfe26b397515527d8127c53db3ed4100a8b6f9715ae4e9e66f1cf5ca6b768c05b1a885a41b0694e
|
data/lib/fastbeans/client.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'msgpack'
|
2
2
|
require 'thread'
|
3
3
|
require 'rufus-lru'
|
4
|
+
require 'fastbeans/response'
|
4
5
|
|
5
6
|
module Fastbeans
|
6
7
|
|
@@ -62,17 +63,14 @@ module Fastbeans
|
|
62
63
|
end
|
63
64
|
|
64
65
|
def call_without_retries(*data)
|
65
|
-
|
66
|
+
raw_resp = @mutex.synchronize do
|
66
67
|
payload = MessagePack.pack(data).force_encoding("BINARY")
|
67
68
|
@sock.write([payload.bytesize].pack("N"))
|
68
69
|
@sock.write(payload)
|
69
70
|
MessagePack.load(@sock)
|
70
71
|
end
|
71
|
-
|
72
|
-
|
73
|
-
else
|
74
|
-
resp
|
75
|
-
end
|
72
|
+
resp = Response.new(data, raw_resp)
|
73
|
+
resp.payload
|
76
74
|
rescue IOError, Errno::EPIPE, MessagePack::MalformedFormatError => e
|
77
75
|
ne = RemoteConnectionFailed.new(e.message)
|
78
76
|
ne.orig_exc = e
|
data/lib/fastbeans/errors.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Fastbeans
|
2
|
+
|
3
|
+
|
4
|
+
class Response
|
5
|
+
|
6
|
+
def initialize(call_data, raw_response)
|
7
|
+
@call_data = call_data
|
8
|
+
@raw_response = raw_response
|
9
|
+
end
|
10
|
+
|
11
|
+
def error?
|
12
|
+
@raw_response.is_a?(Hash) and @raw_response.has_key?("fastbeans-error")
|
13
|
+
end
|
14
|
+
|
15
|
+
def payload
|
16
|
+
unless error?
|
17
|
+
@raw_response
|
18
|
+
else
|
19
|
+
raise to_exception
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_exception
|
24
|
+
name = @raw_response["fastbeans-error"].underscore.classify
|
25
|
+
Fastbeans.exception(name).new(@raw_response["error-information"])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/lib/fastbeans/version.rb
CHANGED
data/lib/fastbeans.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'fastbeans/version'
|
2
|
+
require 'fastbeans/errors'
|
3
|
+
require 'fastbeans/client'
|
4
4
|
|
5
5
|
module Fastbeans
|
6
6
|
class << self
|
@@ -10,7 +10,7 @@ module Fastbeans
|
|
10
10
|
def debug(str_or_exc)
|
11
11
|
case str_or_exc
|
12
12
|
when String
|
13
|
-
STDERR.puts("[#{Time.now}] #{
|
13
|
+
STDERR.puts("[#{Time.now}] #{str_or_exc}") if self.debug_mode
|
14
14
|
when Exception
|
15
15
|
debug("Exception: #{str_or_exc.message}\n#{str_or_exc.backtrace.join("\n")}")
|
16
16
|
end
|
@@ -24,5 +24,13 @@ module Fastbeans
|
|
24
24
|
t2 = Time.now
|
25
25
|
debug("Time spent: #{t2-t1}s")
|
26
26
|
end
|
27
|
+
|
28
|
+
def exception(classname)
|
29
|
+
begin
|
30
|
+
Fastbeans.const_get(classname)
|
31
|
+
rescue NameError
|
32
|
+
Fastbeans.const_set(classname, Class.new(Fastbeans::AutogeneratedException))
|
33
|
+
end
|
34
|
+
end
|
27
35
|
end
|
28
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastbeans
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dima Sabanin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/fastbeans.rb
|
83
83
|
- lib/fastbeans/client.rb
|
84
84
|
- lib/fastbeans/errors.rb
|
85
|
+
- lib/fastbeans/response.rb
|
85
86
|
- lib/fastbeans/version.rb
|
86
87
|
homepage: https://github.com/dsabanin/fastbeans-rb
|
87
88
|
licenses:
|