bson 2.1.2-java → 2.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bson might be problematic. Click here for more details.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +6 -0
- data/README.md +2 -2
- data/lib/bson-ruby.jar +0 -0
- data/lib/bson/date_time.rb +0 -21
- data/lib/bson/document.rb +0 -493
- data/lib/bson/environment.rb +0 -75
- data/lib/bson/int32.rb +1 -1
- data/lib/bson/int64.rb +1 -1
- data/lib/bson/version.rb +1 -1
- data/spec/bson/document_spec.rb +11 -14
- data/spec/bson/object_id_spec.rb +2 -5
- data/spec/bson/registry_spec.rb +4 -14
- data/spec/bson/string_spec.rb +16 -22
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ada22ee89296a96c88b38de4f4dc595f21687565
|
4
|
+
data.tar.gz: dad26ece03f57a45993feab6c409742d2ef81741
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 744c86749ad6f9479c9a0d83b6b9025d170c3ecf79bc17daf2743a9b8080bd01ec27cb192fb7270df8a5f5c4eaebedadf744a32b013e1859a940be146d198ae6
|
7
|
+
data.tar.gz: 0f22b1d3c37109dc5d5d92d7af4cf8787b08916d1da037566248b2b52b128b6eeb8bc70e6a82837c388794529cddd3f1d1dd20d7ecca52581d3565cb68c302e3
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ An implementation of the BSON specification in Ruby.
|
|
6
6
|
Compatibility
|
7
7
|
-------------
|
8
8
|
|
9
|
-
BSON is tested against MRI (1.
|
9
|
+
BSON is tested against MRI (1.9.2+), JRuby (1.7.0+) and Rubinius (2.0.0+).
|
10
10
|
|
11
11
|
Installation
|
12
12
|
------------
|
@@ -15,7 +15,7 @@ With bundler, add the `bson` gem to your `Gemfile`. As of 2.0.0 native extension
|
|
15
15
|
are bundled with the `bson` gem and `bson_ext` is no longer needed.
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
gem "bson", "~> 2.
|
18
|
+
gem "bson", "~> 2.2"
|
19
19
|
```
|
20
20
|
|
21
21
|
Require the `bson` gem in your application.
|
data/lib/bson-ruby.jar
CHANGED
Binary file
|
data/lib/bson/date_time.rb
CHANGED
@@ -37,27 +37,6 @@ module BSON
|
|
37
37
|
def to_bson(encoded = ''.force_encoding(BINARY))
|
38
38
|
to_time.to_bson(encoded)
|
39
39
|
end
|
40
|
-
|
41
|
-
if Environment.ruby_18?
|
42
|
-
|
43
|
-
# Constant to multiple the seconds fraction my for millis in REE.
|
44
|
-
#
|
45
|
-
# @since 2.1.0
|
46
|
-
FACTOR = 86400000000
|
47
|
-
|
48
|
-
# REE does not define a to_time on DateTime, so if we are using REE we
|
49
|
-
# define it ourselves.
|
50
|
-
#
|
51
|
-
# @example Conver the DateTime to a time.
|
52
|
-
# date_time.to_time
|
53
|
-
#
|
54
|
-
# @return [ Time ] The converted time.
|
55
|
-
#
|
56
|
-
# @since 2.1.0
|
57
|
-
def to_time
|
58
|
-
::Time.utc(year, mon, mday, hour, min, sec, (sec_fraction * FACTOR).to_i).getlocal
|
59
|
-
end
|
60
|
-
end
|
61
40
|
end
|
62
41
|
|
63
42
|
# Enrich the core DateTime class with this module.
|
data/lib/bson/document.rb
CHANGED
@@ -52,498 +52,5 @@ module BSON
|
|
52
52
|
def [](key)
|
53
53
|
super(key) || super(key.to_s)
|
54
54
|
end
|
55
|
-
|
56
|
-
# If we have ordered hashes, the a BSON::Document is simply a hash. If we do
|
57
|
-
# not, then we need to import our custom BSON::Document implementation.
|
58
|
-
#
|
59
|
-
# @since 2.0.0
|
60
|
-
unless Environment.retaining_hash_order?
|
61
|
-
|
62
|
-
# Message for argument error when providing bad arguments to [].
|
63
|
-
#
|
64
|
-
# @since 2.0.0
|
65
|
-
ARG_ERROR = "An even number of arguments must be passed to BSON::Document[]."
|
66
|
-
|
67
|
-
# Sets a value for the provided key.
|
68
|
-
#
|
69
|
-
# @example Set the value in the document.
|
70
|
-
# document[:name] = "Sid"
|
71
|
-
#
|
72
|
-
# @param [ Object ] key The name of the key.
|
73
|
-
# @param [ Object ] value The value for the key.
|
74
|
-
#
|
75
|
-
# @return [ Object ] The passed in value.
|
76
|
-
#
|
77
|
-
# @since 2.0.0
|
78
|
-
def []=(key, value)
|
79
|
-
order.push(key) unless has_key?(key)
|
80
|
-
super
|
81
|
-
end
|
82
|
-
|
83
|
-
# Clear out all elements in the document.
|
84
|
-
#
|
85
|
-
# @example Clear out all elements.
|
86
|
-
# document.clear
|
87
|
-
#
|
88
|
-
# @return [ BSON::Document ] The empty document.
|
89
|
-
#
|
90
|
-
# @since 2.0.0
|
91
|
-
def clear
|
92
|
-
super
|
93
|
-
order.clear
|
94
|
-
self
|
95
|
-
end
|
96
|
-
|
97
|
-
# Delete a value from the document for the provided key.
|
98
|
-
#
|
99
|
-
# @example Delete a value from the document.
|
100
|
-
# document.delete(:name)
|
101
|
-
#
|
102
|
-
# @param [ Object ] key The key to delete for.
|
103
|
-
#
|
104
|
-
# @return [ Object ] The deleted value.
|
105
|
-
#
|
106
|
-
# @since 2.0.0
|
107
|
-
def delete(key)
|
108
|
-
if has_key?(key)
|
109
|
-
order.delete_at(order.index(key))
|
110
|
-
end
|
111
|
-
super
|
112
|
-
end
|
113
|
-
|
114
|
-
# Delete each key/value pair in the document for which the provided block
|
115
|
-
# returns true.
|
116
|
-
#
|
117
|
-
# @example Delete each for when the block is true.
|
118
|
-
# document.delete_if do |key, value|
|
119
|
-
# value == 1
|
120
|
-
# end
|
121
|
-
#
|
122
|
-
# @return [ BSON::Document ] The document.
|
123
|
-
#
|
124
|
-
# @since 2.0.0
|
125
|
-
def delete_if
|
126
|
-
super
|
127
|
-
synchronize!
|
128
|
-
self
|
129
|
-
end
|
130
|
-
alias :reject! :delete_if
|
131
|
-
|
132
|
-
# Iterate over each element of the document in insertion order and yield
|
133
|
-
# the key and value.
|
134
|
-
#
|
135
|
-
# @example Iterate over the document.
|
136
|
-
# document.each do |key, value|
|
137
|
-
# #...
|
138
|
-
# end
|
139
|
-
#
|
140
|
-
# @return [ BSON::Document ] The document if a block was given, otherwise
|
141
|
-
# an enumerator.
|
142
|
-
#
|
143
|
-
# @since 2.0.0
|
144
|
-
def each
|
145
|
-
if block_given?
|
146
|
-
order.each{ |key| yield([ key, self[key]]) }
|
147
|
-
self
|
148
|
-
else
|
149
|
-
to_enum(:each)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
# Iterate over each key in the document in insertion order and yield the
|
154
|
-
# key.
|
155
|
-
#
|
156
|
-
# @example Iterate over the keys.
|
157
|
-
# document.each_key do |key|
|
158
|
-
# #...
|
159
|
-
# end
|
160
|
-
#
|
161
|
-
# @return [ BSON::Document ] The document if a block was given, otherwise
|
162
|
-
# an enumerator.
|
163
|
-
#
|
164
|
-
# @since 2.0.0
|
165
|
-
def each_key
|
166
|
-
if block_given?
|
167
|
-
order.each{ |key| yield(key) }
|
168
|
-
self
|
169
|
-
else
|
170
|
-
to_enum(:each_key)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
# Iterate over each value in the document in insertion order and yield the
|
175
|
-
# value.
|
176
|
-
#
|
177
|
-
# @example Iterate over the values.
|
178
|
-
# document.each_value do |value|
|
179
|
-
# #...
|
180
|
-
# end
|
181
|
-
#
|
182
|
-
# @return [ BSON::Document ] The document if a block was given, otherwise
|
183
|
-
# an enumerator.
|
184
|
-
#
|
185
|
-
# @since 2.0.0
|
186
|
-
def each_value
|
187
|
-
if block_given?
|
188
|
-
order.each{ |key| yield(self[key]) }
|
189
|
-
self
|
190
|
-
else
|
191
|
-
to_enum(:each_value)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
# Iterate over each element of the document in insertion order and yield
|
196
|
-
# the key and value.
|
197
|
-
#
|
198
|
-
# @example Iterate over the document.
|
199
|
-
# document.each_pair do |key, value|
|
200
|
-
# #...
|
201
|
-
# end
|
202
|
-
#
|
203
|
-
# @return [ BSON::Document ] The document if a block was given, otherwise
|
204
|
-
# an enumerator.
|
205
|
-
#
|
206
|
-
# @since 2.0.0
|
207
|
-
def each_pair
|
208
|
-
if block_given?
|
209
|
-
order.each{ |key| yield([ key, self[key]]) }
|
210
|
-
self
|
211
|
-
else
|
212
|
-
to_enum(:each_pair)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
# Encode the document with the provided coder.
|
217
|
-
#
|
218
|
-
# @example Encode the document with the coder.
|
219
|
-
# document.encode_with(coder)
|
220
|
-
#
|
221
|
-
# @param [ Object ] coder The coder.
|
222
|
-
#
|
223
|
-
# @return [ String ] The encoded document.
|
224
|
-
#
|
225
|
-
# @since 2.0.0
|
226
|
-
def encode_with(coder)
|
227
|
-
coder.represent_seq("!bsondoc", map{ |key, value| { key => value }})
|
228
|
-
end
|
229
|
-
|
230
|
-
# Get all the keys in the document, in order.
|
231
|
-
#
|
232
|
-
# @example Get all the keys in the document.
|
233
|
-
# document.keys
|
234
|
-
#
|
235
|
-
# @return [ Array<Object> ] The ordered keys.
|
236
|
-
#
|
237
|
-
# @since 2.0.0
|
238
|
-
def keys
|
239
|
-
order.dup
|
240
|
-
end
|
241
|
-
|
242
|
-
# Instantiate a new Document.
|
243
|
-
#
|
244
|
-
# @example Instantiate an empty new document.
|
245
|
-
# BSON::Document.new
|
246
|
-
#
|
247
|
-
# @since 2.0.0
|
248
|
-
def initialize(*args, &block)
|
249
|
-
super
|
250
|
-
@order = []
|
251
|
-
end
|
252
|
-
|
253
|
-
# Inspect the contents of the document.
|
254
|
-
#
|
255
|
-
# @example Inspect the document.
|
256
|
-
# document.inspect
|
257
|
-
#
|
258
|
-
# @return [ String ] The inspection string.
|
259
|
-
#
|
260
|
-
# @since 2.0.0
|
261
|
-
def inspect
|
262
|
-
"#<BSON::Document #{super}>"
|
263
|
-
end
|
264
|
-
|
265
|
-
# Invert the document - reverses the order of all key/value pairs and
|
266
|
-
# returns a new document.
|
267
|
-
#
|
268
|
-
# @example Invert the document.
|
269
|
-
# document.invert
|
270
|
-
#
|
271
|
-
# @return [ BSON::Document ] The inverted document.
|
272
|
-
#
|
273
|
-
# @since 2.0.0
|
274
|
-
def invert
|
275
|
-
Document[to_a.map!{ |pair| pair.reverse }]
|
276
|
-
end
|
277
|
-
|
278
|
-
# Merge a document into this document. Will overwrite any existing keys and
|
279
|
-
# add potential new ones. This returns a new document instead of merging in
|
280
|
-
# place.
|
281
|
-
#
|
282
|
-
# @example Merge the document into this document.
|
283
|
-
# document.merge(other_document)
|
284
|
-
#
|
285
|
-
# @param [ BSON::Document ] other The document to merge in.
|
286
|
-
#
|
287
|
-
# @return [ BSON::Document ] A newly merged document.
|
288
|
-
#
|
289
|
-
# @since 2.0.0
|
290
|
-
def merge(other, &block)
|
291
|
-
dup.merge!(other, &block)
|
292
|
-
end
|
293
|
-
|
294
|
-
# Merge a document into this document. Will overwrite any existing keys and
|
295
|
-
# add potential new ones.
|
296
|
-
#
|
297
|
-
# @example Merge the document into this document.
|
298
|
-
# document.merge!(other_document)
|
299
|
-
#
|
300
|
-
# @param [ BSON::Document ] other The document to merge in.
|
301
|
-
#
|
302
|
-
# @return [ BSON::Document ] The document.
|
303
|
-
#
|
304
|
-
# @since 2.0.0
|
305
|
-
def merge!(other)
|
306
|
-
if block_given?
|
307
|
-
other.each do |key, value|
|
308
|
-
self[key] = key?(key) ? yield(key, self[key], value) : value
|
309
|
-
end
|
310
|
-
else
|
311
|
-
other.each{ |key, value| self[key] = value }
|
312
|
-
end
|
313
|
-
self
|
314
|
-
end
|
315
|
-
alias :update :merge!
|
316
|
-
|
317
|
-
# Delete each key/value pair in the document for which the provided block
|
318
|
-
# returns true. This returns a new document instead of modifying in place.
|
319
|
-
#
|
320
|
-
# @example Delete each for when the block is true.
|
321
|
-
# document.reject do |key, value|
|
322
|
-
# value == 1
|
323
|
-
# end
|
324
|
-
#
|
325
|
-
# @return [ BSON::Document ] The new document.
|
326
|
-
#
|
327
|
-
# @since 2.0.0
|
328
|
-
def reject(&block)
|
329
|
-
dup.reject!(&block)
|
330
|
-
end
|
331
|
-
|
332
|
-
# Replace this document with the other document.
|
333
|
-
#
|
334
|
-
# @example Replace the contents of this document with the other.
|
335
|
-
# document.replace(other_document)
|
336
|
-
#
|
337
|
-
# @param [ BSON::Document ] other The other document.
|
338
|
-
#
|
339
|
-
# @return [ BSON::Document ] The document replaced.
|
340
|
-
#
|
341
|
-
# @since 2.0.0
|
342
|
-
def replace(other)
|
343
|
-
super
|
344
|
-
@order = other.keys
|
345
|
-
self
|
346
|
-
end
|
347
|
-
|
348
|
-
# Shift the document by popping off the first key/value pair in the
|
349
|
-
# document.
|
350
|
-
#
|
351
|
-
# @example Shift the document.
|
352
|
-
# document.shift
|
353
|
-
#
|
354
|
-
# @return [ Array<Object, Object> ] The first key/value pair.
|
355
|
-
#
|
356
|
-
# @since 2.0.0
|
357
|
-
def shift
|
358
|
-
key = order.first
|
359
|
-
value = delete(key)
|
360
|
-
[ key, value ]
|
361
|
-
end
|
362
|
-
|
363
|
-
alias :select :find_all
|
364
|
-
|
365
|
-
# Get the document as an array. This returns a multi-dimensional array
|
366
|
-
# where each element is a [ key, value ] pair in the insertion order.
|
367
|
-
#
|
368
|
-
# @example Get the document as an array.
|
369
|
-
# document.to_a
|
370
|
-
#
|
371
|
-
# @return [ Array<Array<Object, Object>> ] The pairs in insertion order.
|
372
|
-
#
|
373
|
-
# @since 2.0.0
|
374
|
-
def to_a
|
375
|
-
order.map{ |key| [ key, self[key] ]}
|
376
|
-
end
|
377
|
-
|
378
|
-
# Convert this document to a hash. Since a document is simply an ordered
|
379
|
-
# hash we return self.
|
380
|
-
#
|
381
|
-
# @example Get the document as a hash.
|
382
|
-
# document.to_hash
|
383
|
-
#
|
384
|
-
# @return [ BSON::Document ] The document.
|
385
|
-
#
|
386
|
-
# @since 2.0.0
|
387
|
-
def to_hash
|
388
|
-
self
|
389
|
-
end
|
390
|
-
|
391
|
-
# Convert the document to yaml.
|
392
|
-
#
|
393
|
-
# @example Convert the document to yaml.
|
394
|
-
# document.to_yaml
|
395
|
-
#
|
396
|
-
# @param [ Hash ] options The yaml options.
|
397
|
-
#
|
398
|
-
# @return [ String ] The document as yaml.
|
399
|
-
#
|
400
|
-
# @since 2.0.0
|
401
|
-
def to_yaml(options = {})
|
402
|
-
if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
|
403
|
-
return super
|
404
|
-
end
|
405
|
-
YAML.quick_emit(self, options) do |out|
|
406
|
-
out.seq(taguri) do |seq|
|
407
|
-
each{ |key, value| seq.add(key => value) }
|
408
|
-
end
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
# Get the custom yaml type for the document.
|
413
|
-
#
|
414
|
-
# @example Get the yaml type.
|
415
|
-
# document.to_yaml_type
|
416
|
-
#
|
417
|
-
# @return [ String ] "!bsondoc".
|
418
|
-
#
|
419
|
-
# @since 2.0.0
|
420
|
-
def to_yaml_type
|
421
|
-
"!bsondoc"
|
422
|
-
end
|
423
|
-
|
424
|
-
# Get all the values in the document, by order of insertion.
|
425
|
-
#
|
426
|
-
# @example Get all the values in the document.
|
427
|
-
# document.values
|
428
|
-
#
|
429
|
-
# @return [ Array<Object> ] The ordered values.
|
430
|
-
#
|
431
|
-
# @since 2.0.0
|
432
|
-
def values
|
433
|
-
order.map{ |key| self[key] }
|
434
|
-
end
|
435
|
-
|
436
|
-
class << self
|
437
|
-
|
438
|
-
# Create a new document given the provided arguments. The args can either
|
439
|
-
# be empty in order to instantiate an empty document, or an array of
|
440
|
-
# key/value pairs in the order that they should remain in.
|
441
|
-
#
|
442
|
-
# @example Create a new empty document.
|
443
|
-
# BSON::Document[]
|
444
|
-
#
|
445
|
-
# @example Create a new document with the provided elements.
|
446
|
-
# BSON::Document[1, 2, 3, 4]
|
447
|
-
#
|
448
|
-
# @example Create a new document with key/value array pairs.
|
449
|
-
# BSON::Document[[ 1, 2 ], [ 3, 4 ]]
|
450
|
-
#
|
451
|
-
# @param [ Array<Object> ] args The key/value pairs.
|
452
|
-
#
|
453
|
-
# @return [ BSON::Document ] The new document.
|
454
|
-
#
|
455
|
-
# @since 2.0.0
|
456
|
-
def [](*args)
|
457
|
-
if (args.length == 1 && args.first.is_a?(Array))
|
458
|
-
return document_from_pairs(args)
|
459
|
-
end
|
460
|
-
raise ArgumentError.new(ARG_ERROR) unless (args.size % 2 == 0)
|
461
|
-
document_from_args(args)
|
462
|
-
end
|
463
|
-
|
464
|
-
private
|
465
|
-
|
466
|
-
# Returns a document that will be generated from an array of [ key, value ]
|
467
|
-
# array pairs.
|
468
|
-
#
|
469
|
-
# @api private
|
470
|
-
#
|
471
|
-
# @example Initialize a document from array pairs.
|
472
|
-
# BSON::Document[[ 1, 2 ], [ 3, 4 ]]
|
473
|
-
#
|
474
|
-
# @param [ Array ] pairs The key/value pairs.
|
475
|
-
#
|
476
|
-
# @since 2.0.0
|
477
|
-
#
|
478
|
-
# @return [ BSON::Document ] The document.
|
479
|
-
def document_from_pairs(pairs)
|
480
|
-
document = new
|
481
|
-
pairs.first.each do |pair|
|
482
|
-
next unless (pair.is_a?(Array))
|
483
|
-
document[pair[0]] = pair[1]
|
484
|
-
end
|
485
|
-
return document
|
486
|
-
end
|
487
|
-
|
488
|
-
# Returns a document that will be generated from an even number of
|
489
|
-
# individual arguments.
|
490
|
-
#
|
491
|
-
# @api private
|
492
|
-
#
|
493
|
-
# @example Initialize a document from args.
|
494
|
-
# BSON::Document[1, 2, 3, 4]
|
495
|
-
#
|
496
|
-
# @param [ Array ] args The arguments.
|
497
|
-
#
|
498
|
-
# @return [ BSON::Document ] The document.
|
499
|
-
#
|
500
|
-
# @since 2.0.0
|
501
|
-
def document_from_args(args)
|
502
|
-
document = new
|
503
|
-
args.each_with_index do |val, ind|
|
504
|
-
next if (ind % 2 != 0)
|
505
|
-
document[val] = args[ind + 1]
|
506
|
-
end
|
507
|
-
document
|
508
|
-
end
|
509
|
-
end
|
510
|
-
|
511
|
-
private
|
512
|
-
|
513
|
-
# @!attribute order
|
514
|
-
# @api private
|
515
|
-
# @return [ Array<String> ] The document keys in order.
|
516
|
-
# @since 2.0.0
|
517
|
-
attr_reader :order
|
518
|
-
|
519
|
-
# Initialize a copy of the document for use with clone or dup.
|
520
|
-
#
|
521
|
-
# @api private
|
522
|
-
#
|
523
|
-
# @example Clone the document.
|
524
|
-
# document.clone
|
525
|
-
#
|
526
|
-
# @param [ Object ] other The original copy.
|
527
|
-
#
|
528
|
-
# @since 2.0.0
|
529
|
-
def initialize_copy(other)
|
530
|
-
super
|
531
|
-
@order = other.keys
|
532
|
-
end
|
533
|
-
|
534
|
-
# Ensure that the ordered keys are the same entries as the internal keys.
|
535
|
-
#
|
536
|
-
# @api private
|
537
|
-
#
|
538
|
-
# @example Synchronize the keys.
|
539
|
-
# document.synchronize!
|
540
|
-
#
|
541
|
-
# @return [ Array<Object> ] The keys.
|
542
|
-
#
|
543
|
-
# @since 2.0.0
|
544
|
-
def synchronize!
|
545
|
-
order.reject!{ |key| !has_key?(key) }
|
546
|
-
end
|
547
|
-
end
|
548
55
|
end
|
549
56
|
end
|
data/lib/bson/environment.rb
CHANGED
@@ -32,80 +32,5 @@ module BSON
|
|
32
32
|
def jruby?
|
33
33
|
defined?(JRUBY_VERSION)
|
34
34
|
end
|
35
|
-
|
36
|
-
# Determine if we are using REE or not.
|
37
|
-
#
|
38
|
-
# @example Are we running with REE?
|
39
|
-
# Environment.ree?
|
40
|
-
#
|
41
|
-
# @return [ true, false ] If our vm is REE.
|
42
|
-
#
|
43
|
-
# @since 2.1.0
|
44
|
-
def ree?
|
45
|
-
return false unless defined?(RUBY_ENGINE)
|
46
|
-
RUBY_ENGINE == "ruby" && RUBY_DESCRIPTION =~ /Enterprise/
|
47
|
-
end
|
48
|
-
|
49
|
-
# Does the Ruby runtime we are using support ordered hashes?
|
50
|
-
#
|
51
|
-
# @example Does the runtime support ordered hashes?
|
52
|
-
# Environment.retaining_hash_order?
|
53
|
-
#
|
54
|
-
# @return [ true, false ] If the runtime has ordered hashes.
|
55
|
-
#
|
56
|
-
# @since 2.0.0
|
57
|
-
def retaining_hash_order?
|
58
|
-
jruby? || RUBY_VERSION > "1.9.1"
|
59
|
-
end
|
60
|
-
|
61
|
-
# Are we running in a ruby runtime that is version 1.8.x?
|
62
|
-
#
|
63
|
-
# @example Is the ruby runtime in 1.8 mode?
|
64
|
-
# Environment.ruby_18?
|
65
|
-
#
|
66
|
-
# @return [ true, false ] If we are running in 1.8.
|
67
|
-
#
|
68
|
-
# @since 2.0.0
|
69
|
-
def ruby_18?
|
70
|
-
RUBY_VERSION < "1.9"
|
71
|
-
end
|
72
35
|
end
|
73
36
|
end
|
74
|
-
|
75
|
-
# In the case where we don't have encoding, we need to monkey
|
76
|
-
# patch string to ignore the encoding directives.
|
77
|
-
#
|
78
|
-
# @since 2.0.0
|
79
|
-
if BSON::Environment.ruby_18?
|
80
|
-
|
81
|
-
# Making string in 1.8 respond like a 1.9 string, without any modifications.
|
82
|
-
#
|
83
|
-
# @since 2.0.0
|
84
|
-
class String
|
85
|
-
|
86
|
-
# Simply return the string when asking for it's character.
|
87
|
-
#
|
88
|
-
# @since 2.0.0
|
89
|
-
def chr; self; end
|
90
|
-
|
91
|
-
# Force the string to the provided encoding. NOOP.
|
92
|
-
#
|
93
|
-
# @since 2.0.0
|
94
|
-
def force_encoding(*); self; end
|
95
|
-
|
96
|
-
# Encode the string as the provided type. NOOP.
|
97
|
-
#
|
98
|
-
# @since 2.0.0
|
99
|
-
def encode(*); self; end
|
100
|
-
|
101
|
-
# Encode the string in place. NOOP.
|
102
|
-
#
|
103
|
-
# @since 2.0.0
|
104
|
-
def encode!(*); self; end
|
105
|
-
end
|
106
|
-
|
107
|
-
# No encoding error is defined in 1.8.
|
108
|
-
#
|
109
|
-
# @since 2.0.0
|
110
|
-
class EncodingError < RuntimeError; end
|
111
|
-
end
|
data/lib/bson/int32.rb
CHANGED
data/lib/bson/int64.rb
CHANGED
data/lib/bson/version.rb
CHANGED
data/spec/bson/document_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe BSON::Document do
|
|
25
25
|
{}
|
26
26
|
end
|
27
27
|
let(:enum_class) do
|
28
|
-
|
28
|
+
Enumerator
|
29
29
|
end
|
30
30
|
|
31
31
|
before do
|
@@ -559,21 +559,18 @@ describe BSON::Document do
|
|
559
559
|
end
|
560
560
|
end
|
561
561
|
|
562
|
-
|
562
|
+
context "when provided hashes" do
|
563
563
|
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
described_class[1 => 2, 3 => 4]
|
568
|
-
end
|
564
|
+
let(:alternate) do
|
565
|
+
described_class[1 => 2, 3 => 4]
|
566
|
+
end
|
569
567
|
|
570
|
-
|
571
|
-
|
572
|
-
|
568
|
+
it "sets the keys" do
|
569
|
+
expect(alternate.keys).to eq([ 1, 3 ])
|
570
|
+
end
|
573
571
|
|
574
|
-
|
575
|
-
|
576
|
-
end
|
572
|
+
it "sets the values" do
|
573
|
+
expect(alternate.values).to eq([ 2, 4 ])
|
577
574
|
end
|
578
575
|
end
|
579
576
|
end
|
@@ -738,7 +735,7 @@ describe BSON::Document do
|
|
738
735
|
it_behaves_like "a document able to handle utf-8"
|
739
736
|
end
|
740
737
|
|
741
|
-
|
738
|
+
context "when utf-8 code with scope values are present" do
|
742
739
|
|
743
740
|
let(:document) do
|
744
741
|
described_class["code", BSON::CodeWithScope.new("// gültig", {})]
|
data/spec/bson/object_id_spec.rb
CHANGED
@@ -502,11 +502,8 @@ describe BSON::ObjectId do
|
|
502
502
|
expect(object_id.to_s).to eq(expected)
|
503
503
|
end
|
504
504
|
|
505
|
-
|
506
|
-
|
507
|
-
it "returns the string in UTF-8" do
|
508
|
-
expect(object_id.to_s.encoding).to eq(Encoding.find(BSON::UTF8))
|
509
|
-
end
|
505
|
+
it "returns the string in UTF-8" do
|
506
|
+
expect(object_id.to_s.encoding).to eq(Encoding.find(BSON::UTF8))
|
510
507
|
end
|
511
508
|
|
512
509
|
it "converts to a readable yaml string" do
|
data/spec/bson/registry_spec.rb
CHANGED
@@ -35,20 +35,10 @@ describe BSON::Registry do
|
|
35
35
|
|
36
36
|
context "when the type has no corresponding class" do
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
described_class.get("test")
|
43
|
-
}.to raise_error(KeyError)
|
44
|
-
end
|
45
|
-
else
|
46
|
-
|
47
|
-
it "raises an error" do
|
48
|
-
expect {
|
49
|
-
described_class.get("test")
|
50
|
-
}.to raise_error(IndexError)
|
51
|
-
end
|
38
|
+
it "raises an error" do
|
39
|
+
expect {
|
40
|
+
described_class.get("test")
|
41
|
+
}.to raise_error(KeyError)
|
52
42
|
end
|
53
43
|
end
|
54
44
|
end
|
data/spec/bson/string_spec.rb
CHANGED
@@ -111,19 +111,16 @@ describe String do
|
|
111
111
|
it_behaves_like "a binary encoded string"
|
112
112
|
end
|
113
113
|
|
114
|
-
|
114
|
+
context "when the string contains non utf-8 characters" do
|
115
115
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
255.chr
|
120
|
-
end
|
116
|
+
let(:string) do
|
117
|
+
255.chr
|
118
|
+
end
|
121
119
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
120
|
+
it "raises an error" do
|
121
|
+
expect {
|
122
|
+
string.to_bson_cstring
|
123
|
+
}.to raise_error(EncodingError)
|
127
124
|
end
|
128
125
|
end
|
129
126
|
end
|
@@ -242,19 +239,16 @@ describe String do
|
|
242
239
|
it_behaves_like "a binary encoded string"
|
243
240
|
end
|
244
241
|
|
245
|
-
|
242
|
+
context "when the string contains non utf-8 characters" do
|
246
243
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
255.chr
|
251
|
-
end
|
244
|
+
let(:string) do
|
245
|
+
255.chr
|
246
|
+
end
|
252
247
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
end
|
248
|
+
it "raises an error" do
|
249
|
+
expect {
|
250
|
+
string.to_bson_string
|
251
|
+
}.to raise_error(EncodingError)
|
258
252
|
end
|
259
253
|
end
|
260
254
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Tyler Brock
|
@@ -33,7 +33,7 @@ cert_chain:
|
|
33
33
|
8v7zLF2XliYbfurYIwkcXs8yPn8ggApBIy9bX6VJxRs/l2+UvqzaHIFaFy/F8/GP
|
34
34
|
RNTuXsVG5NDACo7Q
|
35
35
|
-----END CERTIFICATE-----
|
36
|
-
date: 2014-01-
|
36
|
+
date: 2014-01-24 00:00:00.000000000 Z
|
37
37
|
dependencies: []
|
38
38
|
description: A full featured BSON specification implementation, in Ruby
|
39
39
|
email:
|
metadata.gz.sig
CHANGED
Binary file
|