mongodb-mongo 0.2.6 → 0.2.7
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.
- data/lib/mongo/util/bson.rb +11 -6
- data/lib/mongo/util/ordered_hash.rb +1 -1
- data/mongo-ruby-driver.gemspec +1 -1
- data/tests/test_bson.rb +12 -0
- metadata +1 -1
data/lib/mongo/util/bson.rb
CHANGED
@@ -287,12 +287,17 @@ class BSON
|
|
287
287
|
buf.put(BINARY)
|
288
288
|
self.class.serialize_cstr(buf, key)
|
289
289
|
|
290
|
-
bytes =
|
291
|
-
|
290
|
+
bytes = case val
|
291
|
+
when ByteBuffer
|
292
|
+
val.to_a
|
292
293
|
else
|
293
|
-
|
294
|
-
|
295
|
-
|
294
|
+
if RUBY_VERSION >= '1.9'
|
295
|
+
val.bytes.to_a
|
296
|
+
else
|
297
|
+
a = []
|
298
|
+
val.each_byte { |byte| a << byte }
|
299
|
+
a
|
300
|
+
end
|
296
301
|
end
|
297
302
|
|
298
303
|
num_bytes = bytes.length
|
@@ -422,7 +427,7 @@ class BSON
|
|
422
427
|
NUMBER_INT
|
423
428
|
when Numeric
|
424
429
|
NUMBER
|
425
|
-
when XGen::Mongo::Driver::Binary # must be before String
|
430
|
+
when XGen::Mongo::Driver::Binary, ByteBuffer # must be before String
|
426
431
|
BINARY
|
427
432
|
when String
|
428
433
|
# magic awful stuff - the DB requires that a where clause is sent as CODE
|
data/mongo-ruby-driver.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'mongo'
|
3
|
-
s.version = '0.2.
|
3
|
+
s.version = '0.2.7'
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = 'Simple pure-Ruby driver for the 10gen Mongo DB'
|
6
6
|
s.description = 'A pure-Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
|
data/tests/test_bson.rb
CHANGED
@@ -125,6 +125,18 @@ class BSONTest < Test::Unit::TestCase
|
|
125
125
|
assert_equal 'binstring', doc2['bin']
|
126
126
|
end
|
127
127
|
|
128
|
+
# def test_binary_byte_buffer
|
129
|
+
# bb = ByteBuffer.new
|
130
|
+
# 10.times { |i| bb.put(i) }
|
131
|
+
# doc = {'bin' => bb}
|
132
|
+
# @b.serialize(doc)
|
133
|
+
# doc2 = @b.deserialize
|
134
|
+
|
135
|
+
# doc2_bytes = []
|
136
|
+
# doc2['bin'].each_byte { |b| doc2_bytes << b }
|
137
|
+
# assert_equal bb.to_a, doc2_bytes
|
138
|
+
# end
|
139
|
+
|
128
140
|
def test_undefined
|
129
141
|
doc = {'undef' => Undefined.new}
|
130
142
|
@b.serialize(doc)
|