rethinkdb 1.11.0.0 → 1.11.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/func.rb +3 -2
- data/lib/net.rb +28 -6
- data/lib/shim.rb +42 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d589a0dca4408818f9436f1de68c0b308f3d5e90
|
4
|
+
data.tar.gz: da8263048750b9f9849dd603423a749f64f011ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e6cdf08230b8c639fe7b27b85c99e511cec21dd8d20646ab148dac3dbb70380c2226b5c97a346f25a5ce06a880c01334db89221bbb81379e1e9a7c4dfe83390
|
7
|
+
data.tar.gz: 13e9754e90e8c7dabb4831265bb9a2ad72c10ee534cff87bc711f2bd02fb8810048a5d64bb29ba794106526b183bb60fbbc5afe3d8288d3301f00cbbd19539ec
|
data/lib/func.rb
CHANGED
@@ -99,9 +99,10 @@ module RethinkDB
|
|
99
99
|
end
|
100
100
|
def groupby(*a, &b); group_by(*a, &b); end
|
101
101
|
|
102
|
-
def connect(*args)
|
102
|
+
def connect(*args, &b)
|
103
103
|
unbound_if @body
|
104
|
-
Connection.new(*args)
|
104
|
+
c = Connection.new(*args)
|
105
|
+
b ? begin b.call(c) ensure c.close end : c
|
105
106
|
end
|
106
107
|
|
107
108
|
def avg(attr)
|
data/lib/net.rb
CHANGED
@@ -22,7 +22,7 @@ module RethinkDB
|
|
22
22
|
class RQL
|
23
23
|
@@default_conn = nil
|
24
24
|
def self.set_default_conn c; @@default_conn = c; end
|
25
|
-
def run(c=@@default_conn, opts=nil)
|
25
|
+
def run(c=@@default_conn, opts=nil, &b)
|
26
26
|
# $f.puts "("+RPP::pp(@body)+"),"
|
27
27
|
unbound_if !@body
|
28
28
|
c, opts = @@default_conn, c if opts.nil? && !c.kind_of?(RethinkDB::Connection)
|
@@ -38,7 +38,7 @@ module RethinkDB
|
|
38
38
|
raise ArgumentError, "No connection specified!\n" \
|
39
39
|
"Use `query.run(conn)` or `conn.repl(); query.run`."
|
40
40
|
end
|
41
|
-
c.run(@body, opts)
|
41
|
+
c.run(@body, opts, &b)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -86,6 +86,18 @@ module RethinkDB
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
89
|
+
|
90
|
+
def close
|
91
|
+
if @more
|
92
|
+
@more = false
|
93
|
+
q = RethinkDB::new_query(Query::QueryType::STOP, @token)
|
94
|
+
res = @conn.run_internal q
|
95
|
+
if res.type != Response::ResponseType::SUCCESS_SEQUENCE || res.response != []
|
96
|
+
raise RqlRuntimeError, "Server sent malformed STOP response #{PP.pp(res, "")}"
|
97
|
+
end
|
98
|
+
return true
|
99
|
+
end
|
100
|
+
end
|
89
101
|
end
|
90
102
|
|
91
103
|
class Connection
|
@@ -120,7 +132,7 @@ module RethinkDB
|
|
120
132
|
dispatch q
|
121
133
|
noreply ? nil : wait(q.token)
|
122
134
|
end
|
123
|
-
def run(msg, opts)
|
135
|
+
def run(msg, opts, &b)
|
124
136
|
reconnect(:noreply_wait => false) if @auto_reconnect && (!@socket || !@listener)
|
125
137
|
raise RqlRuntimeError, "Error: Connection Closed." if !@socket || !@listener
|
126
138
|
q = RethinkDB::new_query(Query::QueryType::START, @@token_cnt += 1)
|
@@ -154,10 +166,20 @@ module RethinkDB
|
|
154
166
|
end
|
155
167
|
|
156
168
|
if res.respond_to? :has_profile? and res.has_profile?
|
157
|
-
{"profile" => Shim.datum_to_native(res.profile(), opts),
|
158
|
-
|
169
|
+
real_val = {"profile" => Shim.datum_to_native(res.profile(), opts),
|
170
|
+
"value" => value}
|
171
|
+
else
|
172
|
+
real_val = value
|
173
|
+
end
|
174
|
+
|
175
|
+
if b
|
176
|
+
begin
|
177
|
+
b.call(real_val)
|
178
|
+
ensure
|
179
|
+
value.close if value.class == Cursor
|
180
|
+
end
|
159
181
|
else
|
160
|
-
|
182
|
+
real_val
|
161
183
|
end
|
162
184
|
end
|
163
185
|
|
data/lib/shim.rb
CHANGED
@@ -2,7 +2,41 @@ require 'json'
|
|
2
2
|
require 'time'
|
3
3
|
|
4
4
|
module RethinkDB
|
5
|
+
|
5
6
|
module Shim
|
7
|
+
|
8
|
+
def self.is_reql_time(obj)
|
9
|
+
obj.is_a? Hash and obj["$reql_type$"] == "TIME"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.convert_time(obj)
|
13
|
+
t = Time.at(obj['epoch_time'])
|
14
|
+
tz = obj['timezone']
|
15
|
+
(tz && tz != "" && tz != "Z") ? t.getlocal(tz) : t.utc
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.convert_times!(result)
|
19
|
+
case result
|
20
|
+
when Hash
|
21
|
+
result.each { |k, v|
|
22
|
+
if is_reql_time v
|
23
|
+
result[k] = convert_time v
|
24
|
+
else
|
25
|
+
convert_times! v
|
26
|
+
end
|
27
|
+
}
|
28
|
+
when Array
|
29
|
+
result.each_index { |i|
|
30
|
+
if is_reql_time result[i]
|
31
|
+
result[i] = convert_time result[i]
|
32
|
+
else
|
33
|
+
convert_times! result[i]
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
37
|
+
result
|
38
|
+
end
|
39
|
+
|
6
40
|
def self.datum_to_native(d, opts)
|
7
41
|
raise RqlRuntimeError, "SHENANIGANS" if d.class != Datum
|
8
42
|
dt = Datum::DatumType
|
@@ -14,15 +48,18 @@ module RethinkDB
|
|
14
48
|
when dt::R_ARRAY then d.r_array.map{|d2| datum_to_native(d2, opts)}
|
15
49
|
when dt::R_OBJECT then
|
16
50
|
obj = Hash[d.r_object.map{|x| [x.key, datum_to_native(x.val, opts)]}]
|
17
|
-
if
|
18
|
-
|
19
|
-
tz = obj['timezone']
|
20
|
-
(tz && tz != "" && tz != "Z") ? t.getlocal(tz) : t.utc
|
51
|
+
if opts[:time_format] != 'raw'
|
52
|
+
is_reql_time(obj) ? convert_time(obj) : obj
|
21
53
|
else
|
22
54
|
obj
|
23
55
|
end
|
24
56
|
when dt::R_JSON then
|
25
|
-
JSON.parse("[" + d.r_str + "]")[0]
|
57
|
+
result = JSON.parse("[" + d.r_str + "]")[0]
|
58
|
+
if opts[:time_format] != 'raw'
|
59
|
+
is_reql_time(result) ? convert_time(result) : convert_times!(result)
|
60
|
+
else
|
61
|
+
result
|
62
|
+
end
|
26
63
|
else raise RqlRuntimeError, "#{dt} Unimplemented."
|
27
64
|
end
|
28
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rethinkdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.11.0.
|
4
|
+
version: 1.11.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RethinkDB Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|