bson 2.0.0.rc-java → 2.1.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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE +1 -1
- data/NOTICE +1 -1
- data/README.md +7 -1
- data/Rakefile +25 -8
- data/lib/bson-ruby.jar +0 -0
- data/lib/bson.rb +3 -1
- data/lib/bson/array.rb +18 -1
- data/lib/bson/binary.rb +56 -1
- data/lib/bson/boolean.rb +1 -1
- data/lib/bson/code.rb +1 -1
- data/lib/bson/code_with_scope.rb +7 -5
- data/lib/bson/date.rb +44 -0
- data/lib/bson/date_time.rb +65 -0
- data/lib/bson/document.rb +1 -1
- data/lib/bson/encodable.rb +1 -1
- data/lib/bson/environment.rb +13 -1
- data/lib/bson/false_class.rb +1 -1
- data/lib/bson/float.rb +1 -1
- data/lib/bson/hash.rb +3 -3
- data/lib/bson/int32.rb +1 -1
- data/lib/bson/int64.rb +1 -1
- data/lib/bson/integer.rb +1 -1
- data/lib/bson/json.rb +1 -3
- data/lib/bson/max_key.rb +1 -1
- data/lib/bson/min_key.rb +1 -1
- data/lib/bson/nil_class.rb +1 -1
- data/lib/bson/object_id.rb +79 -6
- data/lib/bson/regexp.rb +1 -1
- data/lib/bson/registry.rb +1 -1
- data/lib/bson/specialized.rb +1 -1
- data/lib/bson/string.rb +20 -3
- data/lib/bson/symbol.rb +2 -2
- data/lib/bson/time.rb +1 -1
- data/lib/bson/timestamp.rb +1 -1
- data/lib/bson/true_class.rb +1 -1
- data/lib/bson/undefined.rb +1 -1
- data/lib/bson/version.rb +2 -2
- data/spec/bson/array_spec.rb +28 -1
- data/spec/bson/binary_spec.rb +16 -1
- data/spec/bson/boolean_spec.rb +1 -1
- data/spec/bson/code_spec.rb +1 -1
- data/spec/bson/code_with_scope_spec.rb +34 -7
- data/spec/bson/date_spec.rb +39 -0
- data/spec/bson/date_time_spec.rb +37 -0
- data/spec/bson/document_spec.rb +1 -1
- data/spec/bson/false_class_spec.rb +1 -1
- data/spec/bson/float_spec.rb +1 -1
- data/spec/bson/hash_spec.rb +1 -1
- data/spec/bson/int32_spec.rb +1 -1
- data/spec/bson/int64_spec.rb +1 -1
- data/spec/bson/integer_spec.rb +1 -1
- data/spec/bson/json_spec.rb +1 -1
- data/spec/bson/max_key_spec.rb +1 -1
- data/spec/bson/min_key_spec.rb +1 -1
- data/spec/bson/nil_class_spec.rb +1 -1
- data/spec/bson/object_id_spec.rb +110 -1
- data/spec/bson/regexp_spec.rb +1 -1
- data/spec/bson/registry_spec.rb +1 -1
- data/spec/bson/string_spec.rb +29 -2
- data/spec/bson/symbol_spec.rb +11 -1
- data/spec/bson/time_spec.rb +1 -1
- data/spec/bson/timestamp_spec.rb +1 -1
- data/spec/bson/true_class_spec.rb +1 -1
- data/spec/bson/undefined_spec.rb +1 -1
- data/spec/bson_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -2
- data/spec/support/shared_examples.rb +1 -1
- metadata +16 -12
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 307335e37546cd82f6e667451cc88adfe922f35a
|
4
|
+
data.tar.gz: baa7ca7c5d40dc61e37a1f0fbc32f337eadfee76
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fabf976f05db48b58ed77e28bb5e3b7b34a3997b567314311644a68819cbcb3c24453dc761e855acab17a941c9a4145ebd77de79d231a0ce9d068895ce6775c0
|
7
|
+
data.tar.gz: 4aa797cefb195fa4e0046a2dc79a20b3fd0c5cf4691ecd1330681c9f5184834c39f432915ab368c09b1f60c6ee672c652642e9df644babefdb663742acbb7583
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
BSON Changelog
|
2
2
|
==============
|
3
3
|
|
4
|
+
## 2.1.0
|
5
|
+
|
6
|
+
### New Features
|
7
|
+
|
8
|
+
* `Date` and `DateTime` objects in Ruby can now be serialized into BSON. `Date` is
|
9
|
+
converted to a UTC `Time` at midnight and serialized, while `DateTime` is simply
|
10
|
+
converted to the identical `Time` before serialization. Note that these objects
|
11
|
+
will be deserialized into `Time` objects.
|
12
|
+
|
4
13
|
## 2.0.0
|
5
14
|
|
6
15
|
### Backwards Incompatible Changes
|
data/LICENSE
CHANGED
@@ -175,7 +175,7 @@
|
|
175
175
|
|
176
176
|
END OF TERMS AND CONDITIONS
|
177
177
|
|
178
|
-
Copyright (C) 2008-2013
|
178
|
+
Copyright (C) 2008-2013 MongoDB, Inc.
|
179
179
|
|
180
180
|
Licensed under the Apache License, Version 2.0 (the "License");
|
181
181
|
you may not use this file except in compliance with the License.
|
data/NOTICE
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
Ruby BSON
|
2
|
-
Copyright (C) 2009-2013
|
2
|
+
Copyright (C) 2009-2013 MongoDB, Inc.
|
data/README.md
CHANGED
@@ -156,6 +156,12 @@ them.
|
|
156
156
|
- `BSON::Timestamp`: `{ "t" : 5, "i" : 30 }`
|
157
157
|
- `Regexp`: `{ "$regex" : "[abc]", "$options" : "i" }`
|
158
158
|
|
159
|
+
### Notes on Special Ruby Date Classes
|
160
|
+
|
161
|
+
As of 2.1.0, Ruby's `Date` and `DateTime` are able to be serialized, but when
|
162
|
+
they are deserialized they will always be returned as a `Time` since the BSON
|
163
|
+
specification only has a `Time` type and knows nothing about Ruby.
|
164
|
+
|
159
165
|
API Documentation
|
160
166
|
-----------------
|
161
167
|
|
@@ -175,7 +181,7 @@ As of 2.0.0, this project adheres to the [Semantic Versioning Specification](htt
|
|
175
181
|
License
|
176
182
|
-------
|
177
183
|
|
178
|
-
Copyright (C) 2013
|
184
|
+
Copyright (C) 2009-2013 MongoDB Inc.
|
179
185
|
|
180
186
|
Licensed under the Apache License, Version 2.0 (the "License");
|
181
187
|
you may not use this file except in compliance with the License.
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -56,27 +56,44 @@ end
|
|
56
56
|
RSpec::Core::RakeTask.new(:spec)
|
57
57
|
RSpec::Core::RakeTask.new(:rspec)
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
if jruby?
|
60
|
+
task :build => [ :clean_all, :compile ] do
|
61
|
+
system "gem build bson.gemspec"
|
62
|
+
end
|
63
|
+
else
|
64
|
+
task :build => :clean_all do
|
65
|
+
system "gem build bson.gemspec"
|
66
|
+
end
|
61
67
|
end
|
62
68
|
|
63
69
|
task :clean_all => :clean do
|
64
70
|
begin
|
65
|
-
Dir.chdir(Pathname(__FILE__).dirname + "lib
|
71
|
+
Dir.chdir(Pathname(__FILE__).dirname + "lib") do
|
66
72
|
`rm native.#{extension}`
|
67
73
|
`rm native.o`
|
68
|
-
`rm
|
74
|
+
`rm bson-ruby.jar`
|
69
75
|
end
|
70
76
|
rescue Exception => e
|
71
77
|
puts e.message
|
72
78
|
end
|
73
79
|
end
|
74
80
|
|
81
|
+
task :ext_spec => :compile do
|
82
|
+
ENV["WITH_EXT"] = "C"
|
83
|
+
Rake::Task["rspec"].invoke
|
84
|
+
end
|
85
|
+
|
86
|
+
# Run bundle exec rake release with mri and jruby.
|
75
87
|
task :release => :build do
|
76
88
|
system "git tag -a v#{BSON::VERSION} -m 'Tagging release: #{BSON::VERSION}'"
|
77
89
|
system "git push --tags"
|
78
|
-
|
79
|
-
|
90
|
+
if jruby?
|
91
|
+
system "gem push bson-#{BSON::VERSION}-java.gem"
|
92
|
+
system "rm bson-#{BSON::VERSION}-java.gem"
|
93
|
+
else
|
94
|
+
system "gem push bson-#{BSON::VERSION}.gem"
|
95
|
+
system "rm bson-#{BSON::VERSION}.gem"
|
96
|
+
end
|
80
97
|
end
|
81
98
|
|
82
99
|
namespace :benchmark do
|
@@ -94,4 +111,4 @@ namespace :benchmark do
|
|
94
111
|
end
|
95
112
|
end
|
96
113
|
|
97
|
-
task :default => [ :clean_all, :spec, :
|
114
|
+
task :default => [ :clean_all, :spec, :ext_spec ]
|
data/lib/bson-ruby.jar
CHANGED
Binary file
|
data/lib/bson.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -52,6 +52,8 @@ require "bson/binary"
|
|
52
52
|
require "bson/boolean"
|
53
53
|
require "bson/code"
|
54
54
|
require "bson/code_with_scope"
|
55
|
+
require "bson/date"
|
56
|
+
require "bson/date_time"
|
55
57
|
require "bson/document"
|
56
58
|
require "bson/false_class"
|
57
59
|
require "bson/float"
|
data/lib/bson/array.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -51,6 +51,23 @@ module BSON
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
# Convert the array to an object id. This will only work for arrays of size
|
55
|
+
# 12 where the elements are all strings.
|
56
|
+
#
|
57
|
+
# @example Convert the array to an object id.
|
58
|
+
# array.to_bson_object_id
|
59
|
+
#
|
60
|
+
# @note This is used for repairing legacy bson data.
|
61
|
+
#
|
62
|
+
# @raise [ InvalidObjectId ] If the array is not 12 elements.
|
63
|
+
#
|
64
|
+
# @return [ String ] The raw object id bytes.
|
65
|
+
#
|
66
|
+
# @since 2.0.0
|
67
|
+
def to_bson_object_id
|
68
|
+
ObjectId.repair(self) { pack("C*") }
|
69
|
+
end
|
70
|
+
|
54
71
|
module ClassMethods
|
55
72
|
|
56
73
|
# Deserialize the array from BSON.
|
data/lib/bson/binary.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -91,6 +91,7 @@ module BSON
|
|
91
91
|
#
|
92
92
|
# @since 2.0.0
|
93
93
|
def initialize(data = "", type = :generic)
|
94
|
+
validate_type!(type)
|
94
95
|
@data = data
|
95
96
|
@type = type
|
96
97
|
end
|
@@ -130,6 +131,60 @@ module BSON
|
|
130
131
|
new(data, type)
|
131
132
|
end
|
132
133
|
|
134
|
+
# Raised when providing an invalid type to the Binary.
|
135
|
+
#
|
136
|
+
# @since 2.0.0
|
137
|
+
class InvalidType < RuntimeError
|
138
|
+
|
139
|
+
# @!attribute type
|
140
|
+
# @return [ Object ] The invalid type.
|
141
|
+
# @since 2.0.0
|
142
|
+
attr_reader :type
|
143
|
+
|
144
|
+
# Instantiate the new error.
|
145
|
+
#
|
146
|
+
# @example Instantiate the error.
|
147
|
+
# InvalidType.new(:error)
|
148
|
+
#
|
149
|
+
# @param [ Object ] type The invalid type.
|
150
|
+
#
|
151
|
+
# @since 2.0.0
|
152
|
+
def initialize(type)
|
153
|
+
@type = type
|
154
|
+
end
|
155
|
+
|
156
|
+
# Get the custom error message for the exception.
|
157
|
+
#
|
158
|
+
# @example Get the message.
|
159
|
+
# error.message
|
160
|
+
#
|
161
|
+
# @return [ String ] The error message.
|
162
|
+
#
|
163
|
+
# @since 2.0.0
|
164
|
+
def message
|
165
|
+
"#{type.inspect} is not a valid binary type. " +
|
166
|
+
"Please use one of #{SUBTYPES.keys.map(&:inspect).join(", ")}."
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
private
|
171
|
+
|
172
|
+
# Validate the provided type is a valid type.
|
173
|
+
#
|
174
|
+
# @api private
|
175
|
+
#
|
176
|
+
# @example Validate the type.
|
177
|
+
# binary.validate_type!(:user)
|
178
|
+
#
|
179
|
+
# @param [ Object ] type The provided type.
|
180
|
+
#
|
181
|
+
# @raise [ InvalidType ] The the type is invalid.
|
182
|
+
#
|
183
|
+
# @since 2.0.0
|
184
|
+
def validate_type!(type)
|
185
|
+
raise InvalidType.new(type) unless SUBTYPES.has_key?(type)
|
186
|
+
end
|
187
|
+
|
133
188
|
# Register this type when the module is loaded.
|
134
189
|
#
|
135
190
|
# @since 2.0.0
|
data/lib/bson/boolean.rb
CHANGED
data/lib/bson/code.rb
CHANGED
data/lib/bson/code_with_scope.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -89,10 +89,13 @@ module BSON
|
|
89
89
|
#
|
90
90
|
# @since 2.0.0
|
91
91
|
def to_bson(encoded = ''.force_encoding(BINARY))
|
92
|
-
|
92
|
+
# -1 because we are removing an extra byte
|
93
|
+
out = encode_with_placeholder_and_null(BSON_ADJUST - 1, encoded) do |encoded|
|
93
94
|
javascript.to_bson(encoded)
|
94
95
|
scope.to_bson(encoded)
|
95
96
|
end
|
97
|
+
# an extra null byte has been added; we must remove it
|
98
|
+
out.chop!
|
96
99
|
end
|
97
100
|
|
98
101
|
# Deserialize a code with scope from BSON.
|
@@ -105,9 +108,8 @@ module BSON
|
|
105
108
|
#
|
106
109
|
# @since 2.0.0
|
107
110
|
def self.from_bson(bson)
|
108
|
-
|
109
|
-
|
110
|
-
new(code_with_scope.read(length).from_bson_string.chop!)
|
111
|
+
bson.read(4) # Throw away the total length.
|
112
|
+
new(bson.read(Int32.from_bson(bson)).from_bson_string.chop!, ::Hash.from_bson(bson))
|
111
113
|
end
|
112
114
|
|
113
115
|
# Register this type when the module is loaded.
|
data/lib/bson/date.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module BSON
|
16
|
+
|
17
|
+
# Injects behaviour for encoding date values to raw bytes as specified by
|
18
|
+
# the BSON spec for time.
|
19
|
+
#
|
20
|
+
# @see http://bsonspec.org/#/specification
|
21
|
+
#
|
22
|
+
# @since 2.1.0
|
23
|
+
module Date
|
24
|
+
|
25
|
+
# Get the date as encoded BSON.
|
26
|
+
#
|
27
|
+
# @example Get the date as encoded BSON.
|
28
|
+
# Date.new(2012, 1, 1).to_bson
|
29
|
+
#
|
30
|
+
# @return [ String ] The encoded string.
|
31
|
+
#
|
32
|
+
# @see http://bsonspec.org/#/specification
|
33
|
+
#
|
34
|
+
# @since 2.1.0
|
35
|
+
def to_bson(encoded = ''.force_encoding(BINARY))
|
36
|
+
::Time.utc(year, month, day).to_bson(encoded)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Enrich the core Date class with this module.
|
41
|
+
#
|
42
|
+
# @since 2.1.0
|
43
|
+
::Date.send(:include, Date)
|
44
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module BSON
|
16
|
+
|
17
|
+
# Injects behaviour for encoding date time values to raw bytes as specified by
|
18
|
+
# the BSON spec for time.
|
19
|
+
#
|
20
|
+
# @see http://bsonspec.org/#/specification
|
21
|
+
#
|
22
|
+
# @since 2.1.0
|
23
|
+
module DateTime
|
24
|
+
|
25
|
+
# Get the date time as encoded BSON.
|
26
|
+
#
|
27
|
+
# @example Get the date time as encoded BSON.
|
28
|
+
# DateTime.new(2012, 1, 1, 0, 0, 0).to_bson
|
29
|
+
#
|
30
|
+
# @return [ String ] The encoded string.
|
31
|
+
#
|
32
|
+
# @see http://bsonspec.org/#/specification
|
33
|
+
#
|
34
|
+
# @since 2.1.0
|
35
|
+
def to_bson(encoded = ''.force_encoding(BINARY))
|
36
|
+
to_time.to_bson(encoded)
|
37
|
+
end
|
38
|
+
|
39
|
+
if Environment.ree?
|
40
|
+
|
41
|
+
# Constant to multiple the seconds fraction my for millis in REE.
|
42
|
+
#
|
43
|
+
# @since 2.1.0
|
44
|
+
FACTOR = 86400000000
|
45
|
+
|
46
|
+
# REE does not define a to_time on DateTime, so if we are using REE we
|
47
|
+
# define it ourselves.
|
48
|
+
#
|
49
|
+
# @example Conver the DateTime to a time.
|
50
|
+
# date_time.to_time
|
51
|
+
#
|
52
|
+
# @return [ Time ] The converted time.
|
53
|
+
#
|
54
|
+
# @since 2.1.0
|
55
|
+
def to_time
|
56
|
+
::Time.utc(year, mon, mday, hour, min, sec, (sec_fraction * FACTOR).to_i).getlocal
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Enrich the core DateTime class with this module.
|
62
|
+
#
|
63
|
+
# @since 2.1.0
|
64
|
+
::DateTime.send(:include, DateTime)
|
65
|
+
end
|
data/lib/bson/document.rb
CHANGED
data/lib/bson/encodable.rb
CHANGED
data/lib/bson/environment.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -33,6 +33,18 @@ module BSON
|
|
33
33
|
defined?(JRUBY_VERSION)
|
34
34
|
end
|
35
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
|
+
RUBY_ENGINE == "ruby" && RUBY_DESCRIPTION =~ /Enterprise/
|
46
|
+
end
|
47
|
+
|
36
48
|
# Does the Ruby runtime we are using support ordered hashes?
|
37
49
|
#
|
38
50
|
# @example Does the runtime support ordered hashes?
|