bson 4.3.0 → 4.4.1
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.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Rakefile +16 -9
- data/ext/bson/bson_native.c +102 -28
- data/lib/bson.rb +1 -1
- data/lib/bson/active_support.rb +17 -0
- data/lib/bson/array.rb +1 -1
- data/lib/bson/binary.rb +1 -1
- data/lib/bson/boolean.rb +1 -1
- data/lib/bson/code.rb +1 -1
- data/lib/bson/code_with_scope.rb +1 -1
- data/lib/bson/config.rb +1 -1
- data/lib/bson/date.rb +1 -1
- data/lib/bson/date_time.rb +1 -1
- data/lib/bson/decimal128.rb +1 -1
- data/lib/bson/decimal128/builder.rb +1 -1
- data/lib/bson/document.rb +42 -4
- data/lib/bson/environment.rb +1 -1
- data/lib/bson/false_class.rb +1 -1
- data/lib/bson/float.rb +1 -1
- data/lib/bson/hash.rb +1 -1
- data/lib/bson/int32.rb +17 -4
- data/lib/bson/int64.rb +17 -4
- data/lib/bson/integer.rb +2 -2
- data/lib/bson/json.rb +1 -1
- 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.rb +1 -1
- data/lib/bson/object_id.rb +1 -1
- data/lib/bson/open_struct.rb +1 -1
- 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 +1 -1
- data/lib/bson/symbol.rb +6 -3
- data/lib/bson/time.rb +1 -1
- data/lib/bson/time_with_zone.rb +54 -0
- 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 +1 -1
- data/spec/bson/binary_spec.rb +1 -1
- data/spec/bson/boolean_spec.rb +1 -1
- data/spec/bson/byte_buffer_spec.rb +40 -0
- data/spec/bson/code_spec.rb +1 -1
- data/spec/bson/code_with_scope_spec.rb +1 -1
- data/spec/bson/date_spec.rb +1 -1
- data/spec/bson/date_time_spec.rb +1 -1
- data/spec/bson/decimal128_spec.rb +1 -1
- data/spec/bson/document_spec.rb +60 -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 +139 -3
- data/spec/bson/int64_spec.rb +139 -3
- data/spec/bson/integer_spec.rb +3 -3
- 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 +1 -1
- data/spec/bson/object_spec.rb +1 -1
- data/spec/bson/open_struct_spec.rb +1 -1
- data/spec/bson/regexp_spec.rb +1 -1
- data/spec/bson/registry_spec.rb +1 -1
- data/spec/bson/string_spec.rb +1 -1
- data/spec/bson/symbol_spec.rb +3 -3
- data/spec/bson/time_spec.rb +1 -1
- data/spec/bson/time_with_zone_spec.rb +68 -0
- 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 +15 -1
- data/spec/support/shared_examples.rb +1 -1
- data/spec/support/spec_config.rb +9 -0
- metadata +73 -68
- metadata.gz.sig +0 -0
data/lib/bson/environment.rb
CHANGED
data/lib/bson/false_class.rb
CHANGED
data/lib/bson/float.rb
CHANGED
data/lib/bson/hash.rb
CHANGED
data/lib/bson/int32.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2019 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.
|
@@ -14,8 +14,7 @@
|
|
14
14
|
|
15
15
|
module BSON
|
16
16
|
|
17
|
-
# Represents
|
18
|
-
# specification.
|
17
|
+
# Represents int32 type.
|
19
18
|
#
|
20
19
|
# @see http://bsonspec.org/#/specification
|
21
20
|
#
|
@@ -87,9 +86,23 @@ module BSON
|
|
87
86
|
#
|
88
87
|
# @since 4.2.0
|
89
88
|
def to_bson_key(validating_keys = Config.validating_keys?)
|
90
|
-
@integer
|
89
|
+
@integer
|
91
90
|
end
|
92
91
|
|
92
|
+
# Check equality of the int32 with another object.
|
93
|
+
#
|
94
|
+
# @param [ Object ] other The object to check against.
|
95
|
+
#
|
96
|
+
# @return [ true, false ] If the objects are equal.
|
97
|
+
#
|
98
|
+
# @since 4.4.0
|
99
|
+
def ==(other)
|
100
|
+
return false unless other.is_a?(Int32)
|
101
|
+
@integer == other.instance_variable_get('@integer')
|
102
|
+
end
|
103
|
+
alias :eql? :==
|
104
|
+
alias :=== :==
|
105
|
+
|
93
106
|
private
|
94
107
|
|
95
108
|
def out_of_range!
|
data/lib/bson/int64.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2019 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.
|
@@ -14,8 +14,7 @@
|
|
14
14
|
|
15
15
|
module BSON
|
16
16
|
|
17
|
-
# Represents
|
18
|
-
# specification.
|
17
|
+
# Represents int64 type.
|
19
18
|
#
|
20
19
|
# @see http://bsonspec.org/#/specification
|
21
20
|
#
|
@@ -82,9 +81,23 @@ module BSON
|
|
82
81
|
#
|
83
82
|
# @since 4.2.0
|
84
83
|
def to_bson_key(validating_keys = Config.validating_keys?)
|
85
|
-
@integer
|
84
|
+
@integer
|
86
85
|
end
|
87
86
|
|
87
|
+
# Check equality of the int64 with another object.
|
88
|
+
#
|
89
|
+
# @param [ Object ] other The object to check against.
|
90
|
+
#
|
91
|
+
# @return [ true, false ] If the objects are equal.
|
92
|
+
#
|
93
|
+
# @since 4.4.0
|
94
|
+
def ==(other)
|
95
|
+
return false unless other.is_a?(Int64)
|
96
|
+
@integer == other.instance_variable_get('@integer')
|
97
|
+
end
|
98
|
+
alias :eql? :==
|
99
|
+
alias :=== :==
|
100
|
+
|
88
101
|
private
|
89
102
|
|
90
103
|
def out_of_range!
|
data/lib/bson/integer.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2019 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.
|
@@ -156,7 +156,7 @@ module BSON
|
|
156
156
|
#
|
157
157
|
# @since 2.0.0
|
158
158
|
def to_bson_key(validating_keys = Config.validating_keys?)
|
159
|
-
|
159
|
+
self
|
160
160
|
end
|
161
161
|
|
162
162
|
private
|
data/lib/bson/json.rb
CHANGED
data/lib/bson/max_key.rb
CHANGED
data/lib/bson/min_key.rb
CHANGED
data/lib/bson/nil_class.rb
CHANGED
data/lib/bson/object.rb
CHANGED
data/lib/bson/object_id.rb
CHANGED
data/lib/bson/open_struct.rb
CHANGED
data/lib/bson/regexp.rb
CHANGED
data/lib/bson/registry.rb
CHANGED
data/lib/bson/specialized.rb
CHANGED
data/lib/bson/string.rb
CHANGED
data/lib/bson/symbol.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2019 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.
|
@@ -57,7 +57,7 @@ module BSON
|
|
57
57
|
#
|
58
58
|
# @since 2.0.0
|
59
59
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
|
60
|
-
|
60
|
+
buffer.put_symbol(self)
|
61
61
|
end
|
62
62
|
|
63
63
|
# Get the symbol as a BSON key name encoded C symbol.
|
@@ -71,7 +71,10 @@ module BSON
|
|
71
71
|
#
|
72
72
|
# @since 2.0.0
|
73
73
|
def to_bson_key(validating_keys = Config.validating_keys?)
|
74
|
-
|
74
|
+
if validating_keys
|
75
|
+
raise BSON::String::IllegalKey.new(self) if BSON::String::ILLEGAL_KEY =~ self
|
76
|
+
end
|
77
|
+
self
|
75
78
|
end
|
76
79
|
|
77
80
|
# Converts the symbol to a normalized key in a BSON document.
|
data/lib/bson/time.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (C) 2018-2019 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 "active_support/time_with_zone"
|
16
|
+
|
17
|
+
module BSON
|
18
|
+
|
19
|
+
# Injects behaviour for encoding ActiveSupport::TimeWithZone values to
|
20
|
+
# raw bytes as specified by the BSON spec for time.
|
21
|
+
#
|
22
|
+
# @see http://bsonspec.org/#/specification
|
23
|
+
#
|
24
|
+
# @since 4.4.0
|
25
|
+
module TimeWithZone
|
26
|
+
|
27
|
+
# Get the ActiveSupport::TimeWithZone as encoded BSON.
|
28
|
+
#
|
29
|
+
# @example Get the ActiveSupport::TimeWithZone as encoded BSON.
|
30
|
+
# Time.utc(2012, 12, 12, 0, 0, 0).in_time_zone("Pacific Time (US & Canada)").to_bson
|
31
|
+
#
|
32
|
+
# @return [ BSON::ByteBuffer ] The buffer with the encoded object.
|
33
|
+
#
|
34
|
+
# @see http://bsonspec.org/#/specification
|
35
|
+
#
|
36
|
+
# @since 4.4.0
|
37
|
+
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
|
38
|
+
buffer.put_int64((to_i * 1000) + (usec / 1000))
|
39
|
+
end
|
40
|
+
|
41
|
+
# Get the BSON type for the ActiveSupport::TimeWithZone.
|
42
|
+
#
|
43
|
+
# As the ActiveSupport::TimeWithZone is converted to a time, this returns
|
44
|
+
# the BSON type for time.
|
45
|
+
def bson_type
|
46
|
+
::Time::BSON_TYPE
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Enrich the ActiveSupport::TimeWithZone class with this module.
|
51
|
+
#
|
52
|
+
# @since 4.4.0
|
53
|
+
ActiveSupport::TimeWithZone.send(:include, TimeWithZone)
|
54
|
+
end
|
data/lib/bson/timestamp.rb
CHANGED
data/lib/bson/true_class.rb
CHANGED
data/lib/bson/undefined.rb
CHANGED
data/lib/bson/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2019 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.
|
@@ -13,5 +13,5 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
module BSON
|
16
|
-
VERSION = "4.
|
16
|
+
VERSION = "4.4.1".freeze
|
17
17
|
end
|
data/spec/bson/array_spec.rb
CHANGED
data/spec/bson/binary_spec.rb
CHANGED
data/spec/bson/boolean_spec.rb
CHANGED
@@ -196,6 +196,18 @@ describe BSON::ByteBuffer do
|
|
196
196
|
it 'increments the write position by 1' do
|
197
197
|
expect(modified.write_position).to eq(1)
|
198
198
|
end
|
199
|
+
|
200
|
+
context 'when it receives a numeric value' do
|
201
|
+
it 'raises the ArgumentError exception' do
|
202
|
+
expect{buffer.put_byte(1)}.to raise_error(ArgumentError)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'when it receives a nil value' do
|
207
|
+
it 'raises the ArgumentError exception' do
|
208
|
+
expect{buffer.put_byte(nil)}.to raise_error(ArgumentError)
|
209
|
+
end
|
210
|
+
end
|
199
211
|
end
|
200
212
|
|
201
213
|
describe '#put_cstring' do
|
@@ -501,4 +513,32 @@ describe BSON::ByteBuffer do
|
|
501
513
|
it_behaves_like 'a rewindable buffer'
|
502
514
|
end
|
503
515
|
end
|
516
|
+
|
517
|
+
describe '#put_bytes' do
|
518
|
+
|
519
|
+
let(:buffer) do
|
520
|
+
described_class.new
|
521
|
+
end
|
522
|
+
|
523
|
+
let!(:modified) do
|
524
|
+
buffer.put_bytes(BSON::Int32::BSON_TYPE)
|
525
|
+
buffer
|
526
|
+
end
|
527
|
+
|
528
|
+
it 'increments the write position by 1' do
|
529
|
+
expect(modified.write_position).to eq(1)
|
530
|
+
end
|
531
|
+
|
532
|
+
context 'when it receives a numeric value' do
|
533
|
+
it 'raises the ArgumentError exception' do
|
534
|
+
expect{buffer.put_bytes(1)}.to raise_error(ArgumentError)
|
535
|
+
end
|
536
|
+
end
|
537
|
+
|
538
|
+
context 'when it receives a nil value' do
|
539
|
+
it 'raises the ArgumentError exception' do
|
540
|
+
expect{buffer.put_bytes(nil)}.to raise_error(ArgumentError)
|
541
|
+
end
|
542
|
+
end
|
543
|
+
end
|
504
544
|
end
|
data/spec/bson/code_spec.rb
CHANGED
data/spec/bson/date_spec.rb
CHANGED
data/spec/bson/date_time_spec.rb
CHANGED
data/spec/bson/document_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
# Copyright (C) 2009-
|
3
|
+
# Copyright (C) 2009-2019 MongoDB Inc.
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
# you may not use this file except in compliance with the License.
|
@@ -49,6 +49,36 @@ describe BSON::Document do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
describe "#fetch" do
|
53
|
+
|
54
|
+
let(:document) do
|
55
|
+
described_class["key", "value", "key2", "value"]
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when provided string keys" do
|
59
|
+
|
60
|
+
it "returns the value" do
|
61
|
+
expect(document.fetch("key")).to eq("value")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when provided symbol keys" do
|
66
|
+
|
67
|
+
it "returns the value" do
|
68
|
+
expect(document.fetch(:key)).to eq("value")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when key does not exist" do
|
73
|
+
|
74
|
+
it "raises KeyError" do
|
75
|
+
expect do
|
76
|
+
document.fetch(:non_existent_key)
|
77
|
+
end.to raise_exception(KeyError)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
52
82
|
describe "#[]" do
|
53
83
|
|
54
84
|
let(:document) do
|
@@ -68,6 +98,13 @@ describe BSON::Document do
|
|
68
98
|
expect(document[:key]).to eq("value")
|
69
99
|
end
|
70
100
|
end
|
101
|
+
|
102
|
+
context "when key does not exist" do
|
103
|
+
|
104
|
+
it "returns nil" do
|
105
|
+
expect(document[:non_existent_key]).to be nil
|
106
|
+
end
|
107
|
+
end
|
71
108
|
end
|
72
109
|
|
73
110
|
describe "#[]=" do
|
@@ -118,6 +155,28 @@ describe BSON::Document do
|
|
118
155
|
end
|
119
156
|
end
|
120
157
|
|
158
|
+
if described_class.instance_methods.include?(:slice)
|
159
|
+
describe "#slice" do
|
160
|
+
let(:document) do
|
161
|
+
described_class.new("key1" => "value1", key2: "value2")
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when provided string keys" do
|
165
|
+
|
166
|
+
it "returns the partial document" do
|
167
|
+
expect(document.slice("key1")).to contain_exactly(['key1', 'value1'])
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "when provided symbol keys" do
|
172
|
+
|
173
|
+
it "returns the partial document" do
|
174
|
+
expect(document.slice(:key1)).to contain_exactly(['key1', 'value1'])
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
121
180
|
describe "#delete" do
|
122
181
|
|
123
182
|
shared_examples_for "a document with deletable pairs" do
|