bson 2.0.0 → 2.1.0
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 +9 -0
- data/README.md +6 -0
- data/Rakefile +6 -1
- data/lib/bson.rb +2 -0
- data/lib/bson/date.rb +44 -0
- data/lib/bson/date_time.rb +65 -0
- data/lib/bson/environment.rb +12 -0
- data/lib/bson/version.rb +1 -1
- data/spec/bson/binary_spec.rb +4 -1
- data/spec/bson/code_with_scope_spec.rb +23 -0
- data/spec/bson/date_spec.rb +39 -0
- data/spec/bson/date_time_spec.rb +37 -0
- data/spec/spec_helper.rb +1 -1
- metadata +15 -9
- 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: 8be09f9cb1bd6762863501239ee0323d4ee1f11f
|
4
|
+
data.tar.gz: b73d08e67f59e63f2b4584cba967ce15f35d2f61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad29967f35277e6f4774c98eb4067129c6485fffaf1720259c7b1f2067bd1fef4a4e59078fe690ea15b696350dfdb5fd247e2fc36ffdcabb1d45c628da8fb356
|
7
|
+
data.tar.gz: 4c2404caac6a17e1f329f6f82b6837c312d5c6522c5e357e07a6f8bf7bd1f332ddbe5c6695db421374fbb1e4b7d2eb1ace89da41a8747661f8c41e4d7a16a8af
|
checksums.yaml.gz.sig
CHANGED
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/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
|
|
data/Rakefile
CHANGED
@@ -78,6 +78,11 @@ task :clean_all => :clean do
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
task :ext_spec => :compile do
|
82
|
+
ENV["WITH_EXT"] = "C"
|
83
|
+
Rake::Task["rspec"].invoke
|
84
|
+
end
|
85
|
+
|
81
86
|
# Run bundle exec rake release with mri and jruby.
|
82
87
|
task :release => :build do
|
83
88
|
system "git tag -a v#{BSON::VERSION} -m 'Tagging release: #{BSON::VERSION}'"
|
@@ -106,4 +111,4 @@ namespace :benchmark do
|
|
106
111
|
end
|
107
112
|
end
|
108
113
|
|
109
|
-
task :default => [ :clean_all, :spec, :
|
114
|
+
task :default => [ :clean_all, :spec, :ext_spec ]
|
data/lib/bson.rb
CHANGED
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/environment.rb
CHANGED
@@ -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?
|
data/lib/bson/version.rb
CHANGED
data/spec/bson/binary_spec.rb
CHANGED
@@ -38,7 +38,10 @@ describe BSON::Binary do
|
|
38
38
|
it "raises an error" do
|
39
39
|
expect {
|
40
40
|
described_class.new("testing", :error)
|
41
|
-
}.to raise_error
|
41
|
+
}.to raise_error { |error|
|
42
|
+
error.should be_a(BSON::Binary::InvalidType)
|
43
|
+
error.message.should match /is not a valid binary type/
|
44
|
+
}
|
42
45
|
end
|
43
46
|
end
|
44
47
|
end
|
@@ -16,6 +16,29 @@ require "spec_helper"
|
|
16
16
|
|
17
17
|
describe BSON::CodeWithScope do
|
18
18
|
|
19
|
+
describe "#==" do
|
20
|
+
|
21
|
+
let(:object) do
|
22
|
+
BSON::CodeWithScope.new("this.value = val", "test")
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when the objects are equal" do
|
26
|
+
let(:other) { described_class.new("this.value = val", "test") }
|
27
|
+
|
28
|
+
it "returns true" do
|
29
|
+
expect(object).to eq(other)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the other object is not equal" do
|
34
|
+
let(:other) { described_class.new("this.value = otherVal", "test") }
|
35
|
+
|
36
|
+
it "returns false" do
|
37
|
+
expect(object).to_not eq(other)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
19
42
|
describe "#as_json" do
|
20
43
|
|
21
44
|
let(:object) do
|
@@ -0,0 +1,39 @@
|
|
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
|
+
require "spec_helper"
|
16
|
+
|
17
|
+
describe Date do
|
18
|
+
|
19
|
+
describe "#to_bson" do
|
20
|
+
|
21
|
+
context "when the date is post epoch" do
|
22
|
+
|
23
|
+
let(:obj) { Date.new(2012, 1, 1) }
|
24
|
+
let(:time) { Time.utc(2012, 1, 1) }
|
25
|
+
let(:bson) { [ (time.to_f * 1000).to_i ].pack(BSON::Int64::PACK) }
|
26
|
+
|
27
|
+
it_behaves_like "a serializable bson element"
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when the date is pre epoch" do
|
31
|
+
|
32
|
+
let(:obj) { Date.new(1969, 1, 1) }
|
33
|
+
let(:time) { Time.utc(1969, 1, 1) }
|
34
|
+
let(:bson) { [ (time.to_f * 1000).to_i ].pack(BSON::Int64::PACK) }
|
35
|
+
|
36
|
+
it_behaves_like "a serializable bson element"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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
|
+
require "spec_helper"
|
16
|
+
|
17
|
+
describe DateTime do
|
18
|
+
|
19
|
+
describe "#to_bson" do
|
20
|
+
|
21
|
+
context "when the date time is post epoch" do
|
22
|
+
|
23
|
+
let(:obj) { DateTime.new(2012, 1, 1, 0, 0, 0) }
|
24
|
+
let(:bson) { [ (obj.to_time.to_f * 1000).to_i ].pack(BSON::Int64::PACK) }
|
25
|
+
|
26
|
+
it_behaves_like "a serializable bson element"
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when the date time is pre epoch" do
|
30
|
+
|
31
|
+
let(:obj) { DateTime.new(1969, 1, 1, 0, 0, 0) }
|
32
|
+
let(:bson) { [ (obj.to_time.to_f * 1000).to_i ].pack(BSON::Int64::PACK) }
|
33
|
+
|
34
|
+
it_behaves_like "a serializable bson element"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
16
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
17
17
|
|
18
|
-
if ENV["CI"]
|
18
|
+
if ENV["CI"] && !ENV["WITH_EXT"]
|
19
19
|
require "simplecov"
|
20
20
|
require "coveralls"
|
21
21
|
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
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.1.0
|
5
5
|
platform: ruby
|
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:
|
36
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
37
37
|
dependencies: []
|
38
38
|
description: A full featured BSON specification implementation, in Ruby
|
39
39
|
email:
|
@@ -43,17 +43,22 @@ extensions:
|
|
43
43
|
- ext/bson/extconf.rb
|
44
44
|
extra_rdoc_files: []
|
45
45
|
files:
|
46
|
-
- CONTRIBUTING.md
|
47
46
|
- CHANGELOG.md
|
47
|
+
- CONTRIBUTING.md
|
48
48
|
- LICENSE
|
49
49
|
- NOTICE
|
50
50
|
- README.md
|
51
51
|
- Rakefile
|
52
|
+
- ext/bson/extconf.rb
|
53
|
+
- ext/bson/native.c
|
54
|
+
- lib/bson.rb
|
52
55
|
- lib/bson/array.rb
|
53
56
|
- lib/bson/binary.rb
|
54
57
|
- lib/bson/boolean.rb
|
55
58
|
- lib/bson/code.rb
|
56
59
|
- lib/bson/code_with_scope.rb
|
60
|
+
- lib/bson/date.rb
|
61
|
+
- lib/bson/date_time.rb
|
57
62
|
- lib/bson/document.rb
|
58
63
|
- lib/bson/encodable.rb
|
59
64
|
- lib/bson/environment.rb
|
@@ -78,14 +83,13 @@ files:
|
|
78
83
|
- lib/bson/true_class.rb
|
79
84
|
- lib/bson/undefined.rb
|
80
85
|
- lib/bson/version.rb
|
81
|
-
- lib/bson.rb
|
82
|
-
- ext/bson/native.c
|
83
|
-
- ext/bson/extconf.rb
|
84
86
|
- spec/bson/array_spec.rb
|
85
87
|
- spec/bson/binary_spec.rb
|
86
88
|
- spec/bson/boolean_spec.rb
|
87
89
|
- spec/bson/code_spec.rb
|
88
90
|
- spec/bson/code_with_scope_spec.rb
|
91
|
+
- spec/bson/date_spec.rb
|
92
|
+
- spec/bson/date_time_spec.rb
|
89
93
|
- spec/bson/document_spec.rb
|
90
94
|
- spec/bson/false_class_spec.rb
|
91
95
|
- spec/bson/float_spec.rb
|
@@ -119,17 +123,17 @@ require_paths:
|
|
119
123
|
- lib
|
120
124
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
125
|
requirements:
|
122
|
-
- -
|
126
|
+
- - ">="
|
123
127
|
- !ruby/object:Gem::Version
|
124
128
|
version: 1.8.7
|
125
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
130
|
requirements:
|
127
|
-
- -
|
131
|
+
- - ">="
|
128
132
|
- !ruby/object:Gem::Version
|
129
133
|
version: 1.3.6
|
130
134
|
requirements: []
|
131
135
|
rubyforge_project: bson
|
132
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.2.0
|
133
137
|
signing_key:
|
134
138
|
specification_version: 4
|
135
139
|
summary: Ruby Implementation of the BSON specification
|
@@ -139,6 +143,8 @@ test_files:
|
|
139
143
|
- spec/bson/boolean_spec.rb
|
140
144
|
- spec/bson/code_spec.rb
|
141
145
|
- spec/bson/code_with_scope_spec.rb
|
146
|
+
- spec/bson/date_spec.rb
|
147
|
+
- spec/bson/date_time_spec.rb
|
142
148
|
- spec/bson/document_spec.rb
|
143
149
|
- spec/bson/false_class_spec.rb
|
144
150
|
- spec/bson/float_spec.rb
|
metadata.gz.sig
CHANGED
Binary file
|