moped 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of moped might be problematic. Click here for more details.
- data/CHANGELOG.md +25 -0
- data/lib/moped/collection.rb +1 -1
- data/lib/moped/connection.rb +61 -31
- data/lib/moped/database.rb +1 -1
- data/lib/moped/node.rb +2 -2
- data/lib/moped/session/context.rb +3 -3
- data/lib/moped/version.rb +1 -1
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
# Overview
|
2
2
|
|
3
|
+
## 1.3.0 (branch: master)
|
4
|
+
|
5
|
+
### New Features
|
6
|
+
|
7
|
+
## 1.2.2 (branch: 1.2.0-stable)
|
8
|
+
|
9
|
+
### Resolved Issues
|
10
|
+
|
11
|
+
## 1.2.1
|
12
|
+
|
13
|
+
### Resolved Issues
|
14
|
+
|
15
|
+
* \#63 `Database#collection_names` now returns collections with "system" in
|
16
|
+
the name that aren't core MongoDB system collections. (Hans Hasselberg)
|
17
|
+
|
18
|
+
* \#62 Ensure `Connection#alive?` returns false if I/O errors occur. (lowang)
|
19
|
+
|
20
|
+
* \#59 Use the current database, not admin, for `getLastError` commands.
|
21
|
+
(Christopher Winslett)
|
22
|
+
|
23
|
+
* \#57 Ensure collection name is a string for all operations.
|
24
|
+
|
25
|
+
* \#50 Fixed connection issues when connection is disconnected mid call.
|
26
|
+
(Jonathan Hyman)
|
27
|
+
|
3
28
|
## 1.2.0
|
4
29
|
|
5
30
|
### New Features
|
data/lib/moped/collection.rb
CHANGED
data/lib/moped/connection.rb
CHANGED
@@ -6,7 +6,6 @@ module Moped
|
|
6
6
|
#
|
7
7
|
# @api private
|
8
8
|
class Connection
|
9
|
-
|
10
9
|
# Is the connection alive?
|
11
10
|
#
|
12
11
|
# @example Is the connection alive?
|
@@ -19,20 +18,16 @@ module Moped
|
|
19
18
|
connected? ? @sock.alive? : false
|
20
19
|
end
|
21
20
|
|
22
|
-
# Connect to the server.
|
23
|
-
#
|
24
|
-
# @example Connect to the server.
|
25
|
-
# connection.connect("127.0.0.1", 27017, 30)
|
21
|
+
# Connect to the server defined by @host, @port without timeout @timeout.
|
26
22
|
#
|
27
|
-
# @
|
28
|
-
#
|
29
|
-
# @param [ Integer ] timeout The connection timeout.
|
23
|
+
# @example Open the connection
|
24
|
+
# connection.connect
|
30
25
|
#
|
31
26
|
# @return [ TCPSocket ] The socket.
|
32
27
|
#
|
33
28
|
# @since 1.0.0
|
34
|
-
def connect
|
35
|
-
|
29
|
+
def connect
|
30
|
+
create_connection
|
36
31
|
end
|
37
32
|
|
38
33
|
# Is the connection connected?
|
@@ -65,12 +60,18 @@ module Moped
|
|
65
60
|
# Initialize the connection.
|
66
61
|
#
|
67
62
|
# @example Initialize the connection.
|
68
|
-
# Connection.new
|
63
|
+
# Connection.new("localhost", 27017, 5)
|
69
64
|
#
|
65
|
+
# @param [ String ] host The host to connect to.
|
66
|
+
# @param [ Integer ] post The server port.
|
67
|
+
# @param [ Integer ] timeout The connection timeout.
|
70
68
|
# @since 1.0.0
|
71
|
-
def initialize
|
69
|
+
def initialize(host, port, timeout)
|
72
70
|
@sock = nil
|
73
71
|
@request_id = 0
|
72
|
+
@host = host
|
73
|
+
@port = port
|
74
|
+
@timeout = timeout
|
74
75
|
end
|
75
76
|
|
76
77
|
# Read from the connection.
|
@@ -82,26 +83,31 @@ module Moped
|
|
82
83
|
#
|
83
84
|
# @since 1.0.0
|
84
85
|
def read
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
reply.
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
86
|
+
with_connection do |socket|
|
87
|
+
reply = Protocol::Reply.allocate
|
88
|
+
response = socket.read(36).unpack('l<5q<l<2')
|
89
|
+
reply.length,
|
90
|
+
reply.request_id,
|
91
|
+
reply.response_to,
|
92
|
+
reply.op_code,
|
93
|
+
reply.flags,
|
94
|
+
reply.cursor_id,
|
95
|
+
reply.offset,
|
96
|
+
reply.count = response
|
97
|
+
|
98
|
+
if reply.count == 0
|
99
|
+
reply.documents = []
|
100
|
+
else
|
101
|
+
sock_read = socket.read(reply.length - 36)
|
102
|
+
|
103
|
+
buffer = StringIO.new(sock_read)
|
104
|
+
|
105
|
+
reply.documents = reply.count.times.map do
|
106
|
+
BSON::Document.deserialize(buffer)
|
107
|
+
end
|
102
108
|
end
|
109
|
+
reply
|
103
110
|
end
|
104
|
-
reply
|
105
111
|
end
|
106
112
|
|
107
113
|
# Get the replies to the database operation.
|
@@ -136,7 +142,31 @@ module Moped
|
|
136
142
|
operation.request_id = (@request_id += 1)
|
137
143
|
operation.serialize(buf)
|
138
144
|
end
|
139
|
-
|
145
|
+
with_connection do |socket|
|
146
|
+
socket.write(buf)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
def create_connection
|
153
|
+
@sock = TCPSocket.connect @host, @port, @timeout
|
154
|
+
end
|
155
|
+
|
156
|
+
# Yields a connected socket to the calling back. It will attempt to reconnect
|
157
|
+
# the socket if it is not connected.
|
158
|
+
#
|
159
|
+
# @example Write to the connection.
|
160
|
+
# with_connection do |socket|
|
161
|
+
# socket.write(buf)
|
162
|
+
# end
|
163
|
+
#
|
164
|
+
# @return The yielded block
|
165
|
+
#
|
166
|
+
# @since 1.3.0
|
167
|
+
def with_connection
|
168
|
+
create_connection if @sock.nil? || !@sock.alive?
|
169
|
+
yield @sock
|
140
170
|
end
|
141
171
|
|
142
172
|
# This is a wrapper around a tcp socket.
|
data/lib/moped/database.rb
CHANGED
@@ -54,7 +54,7 @@ module Moped
|
|
54
54
|
#
|
55
55
|
# @since 1.0.0
|
56
56
|
def collection_names
|
57
|
-
namespaces = Collection.new(self, "system.namespaces").find(name: { "$not" =>
|
57
|
+
namespaces = Collection.new(self, "system.namespaces").find(name: { "$not" => /#{name}\.system|\$/ })
|
58
58
|
namespaces.map do |doc|
|
59
59
|
_name = doc["name"]
|
60
60
|
_name[name.length + 1, _name.length]
|
data/lib/moped/node.rb
CHANGED
@@ -471,7 +471,7 @@ module Moped
|
|
471
471
|
end
|
472
472
|
|
473
473
|
def connection
|
474
|
-
@connection ||= Connection.new
|
474
|
+
@connection ||= Connection.new(ip_address, port, timeout)
|
475
475
|
end
|
476
476
|
|
477
477
|
def connected?
|
@@ -493,7 +493,7 @@ module Moped
|
|
493
493
|
# Raises Moped::ConnectionError if the connection times out.
|
494
494
|
# Raises Moped::ConnectionError if the server is unavailable.
|
495
495
|
def connect
|
496
|
-
connection.connect
|
496
|
+
connection.connect
|
497
497
|
@down_at = nil
|
498
498
|
end
|
499
499
|
|
@@ -57,7 +57,7 @@ module Moped
|
|
57
57
|
if safe?
|
58
58
|
node.pipeline do
|
59
59
|
node.insert(database, collection, documents, options)
|
60
|
-
node.command(
|
60
|
+
node.command(database, { getlasterror: 1 }.merge(safety))
|
61
61
|
end
|
62
62
|
else
|
63
63
|
node.insert(database, collection, documents, options)
|
@@ -70,7 +70,7 @@ module Moped
|
|
70
70
|
if safe?
|
71
71
|
node.pipeline do
|
72
72
|
node.update(database, collection, selector, change, options)
|
73
|
-
node.command(
|
73
|
+
node.command(database, { getlasterror: 1 }.merge(safety))
|
74
74
|
end
|
75
75
|
else
|
76
76
|
node.update(database, collection, selector, change, options)
|
@@ -83,7 +83,7 @@ module Moped
|
|
83
83
|
if safe?
|
84
84
|
node.pipeline do
|
85
85
|
node.remove(database, collection, selector, options)
|
86
|
-
node.command(
|
86
|
+
node.command(database, { getlasterror: 1 }.merge(safety))
|
87
87
|
end
|
88
88
|
else
|
89
89
|
node.remove(database, collection, selector, options)
|
data/lib/moped/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moped
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A MongoDB driver for Ruby.
|
15
15
|
email:
|
@@ -85,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
segments:
|
87
87
|
- 0
|
88
|
-
hash:
|
88
|
+
hash: -3114748466186243780
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
90
|
none: false
|
91
91
|
requirements:
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
segments:
|
96
96
|
- 0
|
97
|
-
hash:
|
97
|
+
hash: -3114748466186243780
|
98
98
|
requirements: []
|
99
99
|
rubyforge_project:
|
100
100
|
rubygems_version: 1.8.24
|