moped 1.3.2 → 1.4.0
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 +39 -0
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/lib/moped/bson.rb +4 -4
- data/lib/moped/bson/binary.rb +96 -30
- data/lib/moped/bson/code.rb +81 -32
- data/lib/moped/bson/document.rb +25 -0
- data/lib/moped/bson/extensions/array.rb +14 -24
- data/lib/moped/bson/extensions/boolean.rb +3 -1
- data/lib/moped/bson/extensions/false_class.rb +2 -1
- data/lib/moped/bson/extensions/float.rb +7 -7
- data/lib/moped/bson/extensions/hash.rb +16 -25
- data/lib/moped/bson/extensions/integer.rb +8 -7
- data/lib/moped/bson/extensions/nil_class.rb +6 -6
- data/lib/moped/bson/extensions/object.rb +2 -4
- data/lib/moped/bson/extensions/regexp.rb +13 -14
- data/lib/moped/bson/extensions/string.rb +8 -9
- data/lib/moped/bson/extensions/symbol.rb +8 -8
- data/lib/moped/bson/extensions/time.rb +9 -7
- data/lib/moped/bson/extensions/true_class.rb +2 -1
- data/lib/moped/bson/max_key.rb +34 -3
- data/lib/moped/bson/min_key.rb +34 -3
- data/lib/moped/bson/object_id.rb +223 -77
- data/lib/moped/bson/timestamp.rb +27 -4
- data/lib/moped/bson/types.rb +5 -5
- data/lib/moped/cluster.rb +21 -4
- data/lib/moped/collection.rb +15 -5
- data/lib/moped/database.rb +1 -1
- data/lib/moped/errors.rb +19 -5
- data/lib/moped/node.rb +23 -31
- data/lib/moped/protocol/query.rb +15 -0
- data/lib/moped/query.rb +31 -9
- data/lib/moped/session.rb +22 -8
- data/lib/moped/sockets/connectable.rb +58 -7
- data/lib/moped/version.rb +1 -1
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,44 @@
|
|
1
1
|
# Overview
|
2
2
|
|
3
|
+
## 1.4.0
|
4
|
+
|
5
|
+
* \#144 Moped now supports $maxScan options in queries. (Jonathan Hyman)
|
6
|
+
|
7
|
+
session[:bands].find(name: "Blur").max_scan(50)
|
8
|
+
|
9
|
+
* \#143 Aggregation pipeline commands no longer force to read from
|
10
|
+
primary.
|
11
|
+
|
12
|
+
* \#141 Timeouts on sockets are now set to the timeout level provided, as
|
13
|
+
well is active checks now happen before sending both reads and writes.
|
14
|
+
|
15
|
+
* \#140 Nodes that were provided to Moped's session in intialization, that
|
16
|
+
were removed from the replica set but still alive and accepting
|
17
|
+
connections will no longer be in the list of available nodes.
|
18
|
+
|
19
|
+
* \#138 Aggregation pipeline now supports array or splat args. (Gosha Arinich)
|
20
|
+
|
21
|
+
* \#137 `IOError` exceptions during connection go through reconnect
|
22
|
+
process properly. (Peter Kieltyka)
|
23
|
+
|
24
|
+
* \#120 Return UTF-8 strings when calling `ObjectId#to_s`.
|
25
|
+
|
26
|
+
* \#41 `Moped::BSON::ObjectId.from_time` now accepts a `unique` option to
|
27
|
+
ensure the generated id is unique.
|
28
|
+
|
29
|
+
Moped::BSON::ObjectId.from_time(time, unique: true)
|
30
|
+
|
31
|
+
* mongoid/mongoid\#2738 Ensure that delete operations don't include
|
32
|
+
special selectors, like $query.
|
33
|
+
|
34
|
+
* mongoid/mongoid\#2713 Allow collections that have names that start with
|
35
|
+
"system" to be returned by `Database#collection_names`.
|
36
|
+
|
37
|
+
* mongoid/mongoid\#2452 A boolean can now be passed to count to determine
|
38
|
+
if the skip and limit options should be included in the value.
|
39
|
+
|
40
|
+
session[:bands].find(name: "Blur").skip(10).limit(5).count(true)
|
41
|
+
|
3
42
|
## 1.3.2
|
4
43
|
|
5
44
|
### Resolved Issues
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -25,7 +25,7 @@ the Moped section: [mongoid.org](http://mongoid.org/en/moped/)
|
|
25
25
|
License
|
26
26
|
-------
|
27
27
|
|
28
|
-
Copyright (c) 2011-
|
28
|
+
Copyright (c) 2011-2013 Bernerd Schaefer, Durran Jordan
|
29
29
|
|
30
30
|
Permission is hereby granted, free of charge, to any person obtaining
|
31
31
|
a copy of this software and associated documentation files (the
|
data/lib/moped/bson.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require "moped/bson/extensions"
|
2
|
-
|
3
3
|
require "moped/bson/binary"
|
4
4
|
require "moped/bson/code"
|
5
5
|
require "moped/bson/object_id"
|
6
6
|
require "moped/bson/max_key"
|
7
7
|
require "moped/bson/min_key"
|
8
8
|
require "moped/bson/timestamp"
|
9
|
-
|
10
9
|
require "moped/bson/document"
|
11
10
|
require "moped/bson/types"
|
12
11
|
|
@@ -14,6 +13,7 @@ module Moped
|
|
14
13
|
|
15
14
|
# The module for Moped's BSON implementation.
|
16
15
|
module BSON
|
16
|
+
|
17
17
|
EOD = NULL_BYTE = "\u0000".freeze
|
18
18
|
|
19
19
|
INT32_PACK = 'l'.freeze
|
@@ -22,8 +22,8 @@ module Moped
|
|
22
22
|
|
23
23
|
START_LENGTH = [0].pack(INT32_PACK).freeze
|
24
24
|
|
25
|
-
BINARY_ENCODING = Encoding.find
|
26
|
-
UTF8_ENCODING = Encoding.find
|
25
|
+
BINARY_ENCODING = Encoding.find("binary")
|
26
|
+
UTF8_ENCODING = Encoding.find("utf-8")
|
27
27
|
|
28
28
|
class << self
|
29
29
|
|
data/lib/moped/bson/binary.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Moped
|
2
2
|
module BSON
|
3
|
+
|
4
|
+
# Represents binary data in the BSON specification.
|
3
5
|
class Binary
|
4
6
|
|
5
7
|
SUBTYPE_MAP = {
|
@@ -9,39 +11,21 @@ module Moped
|
|
9
11
|
uuid: "\x03",
|
10
12
|
md5: "\x05",
|
11
13
|
user: "\x80"
|
12
|
-
}
|
13
|
-
|
14
|
-
attr_reader :data, :type
|
15
|
-
|
16
|
-
def initialize(type, data)
|
17
|
-
@type = type
|
18
|
-
@data = data
|
19
|
-
end
|
14
|
+
}.freeze
|
20
15
|
|
21
|
-
|
22
|
-
def __bson_load__(io)
|
23
|
-
length, = io.read(4).unpack(INT32_PACK)
|
24
|
-
type = SUBTYPE_MAP.invert[io.read(1)]
|
16
|
+
SUBTYPE_TYPES = SUBTYPE_MAP.invert.freeze
|
25
17
|
|
26
|
-
|
27
|
-
length -= 4
|
28
|
-
io.read(4)
|
29
|
-
end
|
30
|
-
|
31
|
-
data = io.read length
|
32
|
-
new(type, data)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def ==(other)
|
37
|
-
BSON::Binary === other && data == other.data && type == other.type
|
38
|
-
end
|
39
|
-
alias eql? ==
|
40
|
-
|
41
|
-
def hash
|
42
|
-
[data, type].hash
|
43
|
-
end
|
18
|
+
attr_reader :data, :type
|
44
19
|
|
20
|
+
# Dump the binary into it's raw bytes.
|
21
|
+
#
|
22
|
+
# @example Dump the binary to raw bytes.
|
23
|
+
# binary.__bson_dump__(string, "data")
|
24
|
+
#
|
25
|
+
# @param [ String ] io The raw bytes to write to.
|
26
|
+
# @param [ String ] key The field name.
|
27
|
+
#
|
28
|
+
# @since 1.0.0
|
45
29
|
def __bson_dump__(io, key)
|
46
30
|
io << Types::BINARY
|
47
31
|
io << key
|
@@ -59,13 +43,95 @@ module Moped
|
|
59
43
|
end
|
60
44
|
end
|
61
45
|
|
46
|
+
# Check equality on the object.
|
47
|
+
#
|
48
|
+
# @example Check equality.
|
49
|
+
# object == other
|
50
|
+
#
|
51
|
+
# @param [ Object ] other The object to check against.
|
52
|
+
#
|
53
|
+
# @return [ true, false ] If the objects are equal.
|
54
|
+
#
|
55
|
+
# @since 1.0.0
|
56
|
+
def ==(other)
|
57
|
+
BSON::Binary === other && data == other.data && type == other.type
|
58
|
+
end
|
59
|
+
alias :eql? :==
|
60
|
+
|
61
|
+
# Gets the hash code for the object.
|
62
|
+
#
|
63
|
+
# @example Get the hash code.
|
64
|
+
# object.hash
|
65
|
+
#
|
66
|
+
# @return [ Fixnum ] The hash code.
|
67
|
+
#
|
68
|
+
# @since 1.0.0
|
69
|
+
def hash
|
70
|
+
[data, type].hash
|
71
|
+
end
|
72
|
+
|
73
|
+
# Create the new binary type.
|
74
|
+
#
|
75
|
+
# @example Create the new binary.
|
76
|
+
# Moped::BSON::Binary.new(:md5, data)
|
77
|
+
#
|
78
|
+
# @param [ Symbol ] type The type of data. Should be one of :generic,
|
79
|
+
# :function, :old, :uuid, :md5, :user
|
80
|
+
# @param [ Object ] data The binary data.
|
81
|
+
#
|
82
|
+
# @since 1.0.0
|
83
|
+
def initialize(type, data)
|
84
|
+
@type = type
|
85
|
+
@data = data
|
86
|
+
end
|
87
|
+
|
88
|
+
# Gets the string inspection for the object.
|
89
|
+
#
|
90
|
+
# @example Get the string inspection.
|
91
|
+
# object.inspect
|
92
|
+
#
|
93
|
+
# @return [ String ] The inspection.
|
94
|
+
#
|
95
|
+
# @since 1.0.0
|
62
96
|
def inspect
|
63
97
|
"#<#{self.class.name} type=#{type.inspect} length=#{data.bytesize}>"
|
64
98
|
end
|
65
99
|
|
100
|
+
# Get the string representation of the object.
|
101
|
+
#
|
102
|
+
# @example Get the string representation.
|
103
|
+
# object.to_s
|
104
|
+
#
|
105
|
+
# @return [ String ] The string representation.
|
106
|
+
#
|
107
|
+
# @since 1.0.0
|
66
108
|
def to_s
|
67
109
|
data.to_s
|
68
110
|
end
|
111
|
+
|
112
|
+
class << self
|
113
|
+
|
114
|
+
# Load the BSON from the raw data to a binary.
|
115
|
+
#
|
116
|
+
# @example Load the raw data.
|
117
|
+
# Moped::BSON::Binary.__bson_load__(data)
|
118
|
+
#
|
119
|
+
# @param [ String ] io The raw bytes of data.
|
120
|
+
#
|
121
|
+
# @return [ Binary ] The binary object.
|
122
|
+
#
|
123
|
+
# @since 1.0.0
|
124
|
+
def __bson_load__(io)
|
125
|
+
length, = io.read(4).unpack(INT32_PACK)
|
126
|
+
type = SUBTYPE_TYPES[io.read(1)]
|
127
|
+
if type == :old
|
128
|
+
length -= 4
|
129
|
+
io.read(4)
|
130
|
+
end
|
131
|
+
data = io.read(length)
|
132
|
+
new(type, data)
|
133
|
+
end
|
134
|
+
end
|
69
135
|
end
|
70
136
|
end
|
71
137
|
end
|
data/lib/moped/bson/code.rb
CHANGED
@@ -1,56 +1,35 @@
|
|
1
1
|
module Moped
|
2
2
|
module BSON
|
3
|
+
|
4
|
+
# Object representation of a javascript expression.
|
3
5
|
class Code
|
4
6
|
|
5
7
|
attr_reader :code, :scope
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def ==(other)
|
17
|
-
BSON::Code === other && code == other.code && scope == other.scope
|
18
|
-
end
|
19
|
-
alias eql? ==
|
20
|
-
|
21
|
-
def hash
|
22
|
-
[code, scope].hash
|
23
|
-
end
|
24
|
-
|
25
|
-
class << self
|
26
|
-
def __bson_load__(io)
|
27
|
-
code = io.read(*io.read(4).unpack(INT32_PACK)).from_utf8_binary.chop!
|
28
|
-
new code
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
9
|
+
# Dump the code into it's raw bytes.
|
10
|
+
#
|
11
|
+
# @example Dump the code to raw bytes.
|
12
|
+
# code.__bson_dump__(string, "expression")
|
13
|
+
#
|
14
|
+
# @param [ String ] io The raw bytes to write to.
|
15
|
+
# @param [ String ] key The field name.
|
16
|
+
#
|
17
|
+
# @since 1.0.0
|
32
18
|
def __bson_dump__(io, key)
|
33
19
|
if scoped?
|
34
20
|
io << Types::CODE_WITH_SCOPE
|
35
21
|
io << key.to_bson_cstring
|
36
|
-
|
37
22
|
code_start = io.bytesize
|
38
|
-
|
39
23
|
io << START_LENGTH
|
40
|
-
|
41
24
|
data = code.to_utf8_binary
|
42
25
|
io << [data.bytesize+1].pack(INT32_PACK)
|
43
26
|
io << data
|
44
27
|
io << NULL_BYTE
|
45
|
-
|
46
28
|
scope.__bson_dump__(io)
|
47
|
-
|
48
29
|
io[code_start, 4] = [io.bytesize - code_start].pack(INT32_PACK)
|
49
|
-
|
50
30
|
else
|
51
31
|
io << Types::CODE
|
52
32
|
io << key.to_bson_cstring
|
53
|
-
|
54
33
|
data = code.to_utf8_binary
|
55
34
|
io << [data.bytesize+1].pack(INT32_PACK)
|
56
35
|
io << data
|
@@ -58,6 +37,76 @@ module Moped
|
|
58
37
|
end
|
59
38
|
end
|
60
39
|
|
40
|
+
# Check equality on the object.
|
41
|
+
#
|
42
|
+
# @example Check equality.
|
43
|
+
# object == other
|
44
|
+
#
|
45
|
+
# @param [ Object ] other The object to check against.
|
46
|
+
#
|
47
|
+
# @return [ true, false ] If the objects are equal.
|
48
|
+
#
|
49
|
+
# @since 1.0.0
|
50
|
+
def ==(other)
|
51
|
+
BSON::Code === other && code == other.code && scope == other.scope
|
52
|
+
end
|
53
|
+
alias :eql? :==
|
54
|
+
|
55
|
+
# Gets the hash code for the object.
|
56
|
+
#
|
57
|
+
# @example Get the hash code.
|
58
|
+
# object.hash
|
59
|
+
#
|
60
|
+
# @return [ Fixnum ] The hash code.
|
61
|
+
#
|
62
|
+
# @since 1.0.0
|
63
|
+
def hash
|
64
|
+
[code, scope].hash
|
65
|
+
end
|
66
|
+
|
67
|
+
# Create the new code type.
|
68
|
+
#
|
69
|
+
# @example Create the new code.
|
70
|
+
# Moped::BSON::Code.new("this.value = param", param: "test")
|
71
|
+
#
|
72
|
+
# @param [ String ] code The javascript code.
|
73
|
+
# @param [ Object ] scope The scoped variables and values.
|
74
|
+
#
|
75
|
+
# @since 1.0.0
|
76
|
+
def initialize(code, scope = nil)
|
77
|
+
@code = code
|
78
|
+
@scope = scope
|
79
|
+
end
|
80
|
+
|
81
|
+
# Is the code scoped?
|
82
|
+
#
|
83
|
+
# @example Is the code scoped?
|
84
|
+
# code.scoped?
|
85
|
+
#
|
86
|
+
# @return [ true, false ] If the code is scoped.
|
87
|
+
#
|
88
|
+
# @since 1.0.0
|
89
|
+
def scoped?
|
90
|
+
!!scope
|
91
|
+
end
|
92
|
+
|
93
|
+
class << self
|
94
|
+
|
95
|
+
# Load the BSON from the raw data to a code.
|
96
|
+
#
|
97
|
+
# @example Load the raw data.
|
98
|
+
# Moped::BSON::Code.__bson_load__(data)
|
99
|
+
#
|
100
|
+
# @param [ String ] io The raw bytes of data.
|
101
|
+
#
|
102
|
+
# @return [ Code ] The code object.
|
103
|
+
#
|
104
|
+
# @since 1.0.0
|
105
|
+
def __bson_load__(io)
|
106
|
+
code = io.read(*io.read(4).unpack(INT32_PACK)).from_utf8_binary.chop!
|
107
|
+
new(code)
|
108
|
+
end
|
109
|
+
end
|
61
110
|
end
|
62
111
|
end
|
63
112
|
end
|
data/lib/moped/bson/document.rb
CHANGED
@@ -1,12 +1,37 @@
|
|
1
1
|
module Moped
|
2
2
|
module BSON
|
3
|
+
|
4
|
+
# Represents an entire BSON document.
|
3
5
|
class Document < Hash
|
6
|
+
|
4
7
|
class << self
|
5
8
|
|
9
|
+
# Deserialize the raw bytes into a BSON document object.
|
10
|
+
#
|
11
|
+
# @example Deserialize the raw bytes.
|
12
|
+
# Moped::BSON::Document.deserialize("")
|
13
|
+
#
|
14
|
+
# @param [ String ] io The raw bytes.
|
15
|
+
# @param [ Document ] document The document to load to.
|
16
|
+
#
|
17
|
+
# @return [ Document ] The document from the raw bytes.
|
18
|
+
#
|
19
|
+
# @since 1.0.0
|
6
20
|
def deserialize(io, document = new)
|
7
21
|
__bson_load__(io, document)
|
8
22
|
end
|
9
23
|
|
24
|
+
# Serialize a document into raw bytes.
|
25
|
+
#
|
26
|
+
# @example Serialize the document.
|
27
|
+
# Moped::BSON::Document.serialize(doc, "")
|
28
|
+
#
|
29
|
+
# @param [ Document ] document The document to serialize.
|
30
|
+
# @param [ String ] io The raw bytes to write to.
|
31
|
+
#
|
32
|
+
# @return [ String ] The raw serialized bytes.
|
33
|
+
#
|
34
|
+
# @since 1.0.0
|
10
35
|
def serialize(document, io = "")
|
11
36
|
document.__bson_dump__(io)
|
12
37
|
end
|
@@ -1,46 +1,36 @@
|
|
1
1
|
module Moped
|
2
2
|
module BSON
|
3
|
-
# @private
|
4
3
|
module Extensions
|
5
|
-
module Array
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
def __bson_load__(io, array = new)
|
9
|
-
# Swallow the first four (length) bytes
|
10
|
-
io.read 4
|
11
|
-
|
12
|
-
while (buf = io.readbyte) != 0
|
13
|
-
io.gets(NULL_BYTE)
|
14
|
-
array << Types::MAP[buf].__bson_load__(io)
|
15
|
-
end
|
16
4
|
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
5
|
+
module Array
|
20
6
|
|
21
7
|
def __bson_dump__(io, key)
|
22
8
|
io << Types::ARRAY
|
23
9
|
io << key.to_bson_cstring
|
24
|
-
|
25
10
|
start = io.bytesize
|
26
|
-
|
27
|
-
# write dummy length
|
28
|
-
io << START_LENGTH
|
29
|
-
|
11
|
+
io << START_LENGTH # write dummy length
|
30
12
|
index, length = 0, self.length
|
31
|
-
|
32
13
|
while index < length
|
33
14
|
slice(index).__bson_dump__(io, index.to_s)
|
34
15
|
index += 1
|
35
16
|
end
|
36
|
-
|
37
17
|
io << EOD
|
38
|
-
|
39
18
|
stop = io.bytesize
|
40
19
|
io[start, 4] = [stop - start].pack(INT32_PACK)
|
41
|
-
|
42
20
|
io
|
43
21
|
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
|
25
|
+
def __bson_load__(io, array = new)
|
26
|
+
io.read(4) # Swallow the first four (length) bytes
|
27
|
+
while (buf = io.readbyte) != 0
|
28
|
+
io.gets(NULL_BYTE)
|
29
|
+
array << Types::MAP[buf].__bson_load__(io)
|
30
|
+
end
|
31
|
+
array
|
32
|
+
end
|
33
|
+
end
|
44
34
|
end
|
45
35
|
end
|
46
36
|
end
|