bson 4.0.0.beta-java → 4.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/bson-ruby.jar +0 -0
- data/lib/bson/binary.rb +1 -1
- data/lib/bson/document.rb +24 -3
- data/lib/bson/hash.rb +1 -1
- data/lib/bson/integer.rb +2 -3
- data/lib/bson/registry.rb +1 -1
- data/lib/bson/symbol.rb +17 -1
- data/lib/bson/version.rb +1 -1
- data/lib/native.bundle +0 -0
- data/spec/bson/document_spec.rb +46 -27
- data/spec/bson/hash_spec.rb +15 -0
- data/spec/bson/integer_spec.rb +3 -3
- data/spec/bson/registry_spec.rb +2 -4
- data/spec/bson/symbol_spec.rb +8 -2
- data/spec/spec_helper.rb +0 -9
- metadata +6 -5
- 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: 3a437de13d570ec32baf67a6ab3219e57c339aa9
|
4
|
+
data.tar.gz: 953b083f6212afb23efbc2191d5d39001b989422
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83a525d241bdc949077c03f258e420ac58c2a78319400359c8464e3571b21380446abad9b1811b04925817d29fe74d8c28907d7c975af01c07641f639beb7b37
|
7
|
+
data.tar.gz: c0b3be2540d637ded982aab96e6a0b7839a85159db4c5c13d8eeb5df9fc58f97061889d0540b8bc60e66977144535121a569f8a2d54a946e8b9eda008006b485
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/bson-ruby.jar
CHANGED
Binary file
|
data/lib/bson/binary.rb
CHANGED
@@ -132,7 +132,7 @@ module BSON
|
|
132
132
|
def to_bson(buffer = ByteBuffer.new)
|
133
133
|
position = buffer.length
|
134
134
|
buffer.put_int32(0)
|
135
|
-
buffer.put_byte(SUBTYPES
|
135
|
+
buffer.put_byte(SUBTYPES[type])
|
136
136
|
buffer.put_int32(data.bytesize) if type == :old
|
137
137
|
buffer.put_bytes(data.force_encoding(BINARY))
|
138
138
|
buffer.replace_int32(position, buffer.length - position - 5)
|
data/lib/bson/document.rb
CHANGED
@@ -74,9 +74,11 @@ module BSON
|
|
74
74
|
# @example Test if a key exists using a symbol
|
75
75
|
# document.has_key?(:test)
|
76
76
|
#
|
77
|
+
# @param [ Object ] key The key to check for.
|
78
|
+
#
|
77
79
|
# @return [ true, false]
|
78
80
|
#
|
79
|
-
# @since
|
81
|
+
# @since 4.0.0
|
80
82
|
def has_key?(key)
|
81
83
|
super(convert_key(key))
|
82
84
|
end
|
@@ -85,22 +87,41 @@ module BSON
|
|
85
87
|
alias :key? :has_key?
|
86
88
|
alias :member? :has_key?
|
87
89
|
|
88
|
-
|
89
90
|
# Returns true if the given value is present in the document. Will normalize
|
90
91
|
# symbols into strings.
|
91
92
|
#
|
92
93
|
# @example Test if a key exists using a symbol
|
93
94
|
# document.has_value?(:test)
|
94
95
|
#
|
96
|
+
# @param [ Object ] value THe value to check for.
|
97
|
+
#
|
95
98
|
# @return [ true, false]
|
96
99
|
#
|
97
|
-
# @since
|
100
|
+
# @since 4.0.0
|
98
101
|
def has_value?(value)
|
99
102
|
super(convert_value(value))
|
100
103
|
end
|
101
104
|
|
102
105
|
alias :value :has_value?
|
103
106
|
|
107
|
+
# Deletes the key-value pair and returns the value from the document
|
108
|
+
# whose key is equal to key.
|
109
|
+
# If the key is not found, returns the default value. If the optional code
|
110
|
+
# block is given and the key is not found, pass in the key and return the
|
111
|
+
# result of block.
|
112
|
+
#
|
113
|
+
# @example Delete a key-value pair
|
114
|
+
# document.delete(:test)
|
115
|
+
#
|
116
|
+
# @param [ Object ] key The key of the key-value pair to delete.
|
117
|
+
#
|
118
|
+
# @return [ Object ]
|
119
|
+
#
|
120
|
+
# @since 4.0.0
|
121
|
+
def delete(key, &block)
|
122
|
+
super(convert_key(key), &block)
|
123
|
+
end
|
124
|
+
|
104
125
|
# Instantiate a new Document. Valid parameters for instantiation is a hash
|
105
126
|
# only or nothing.
|
106
127
|
#
|
data/lib/bson/hash.rb
CHANGED
@@ -74,7 +74,7 @@ module BSON
|
|
74
74
|
# @since 2.0.0
|
75
75
|
def from_bson(buffer)
|
76
76
|
hash = Document.allocate
|
77
|
-
buffer.get_int32 # Throw away the size
|
77
|
+
buffer.get_int32 # Throw away the size.
|
78
78
|
while (type = buffer.get_byte) != NULL_BYTE
|
79
79
|
field = buffer.get_cstring
|
80
80
|
hash.store(field, BSON::Registry.get(type).from_bson(buffer))
|
data/lib/bson/integer.rb
CHANGED
@@ -145,8 +145,8 @@ module BSON
|
|
145
145
|
encoded << ((self >> 56) & 255)
|
146
146
|
end
|
147
147
|
|
148
|
-
def to_bson_key
|
149
|
-
|
148
|
+
def to_bson_key
|
149
|
+
to_s
|
150
150
|
end
|
151
151
|
|
152
152
|
private
|
@@ -161,7 +161,6 @@ module BSON
|
|
161
161
|
def out_of_range!
|
162
162
|
raise RangeError.new("#{self} is not a valid 8 byte integer value.")
|
163
163
|
end
|
164
|
-
|
165
164
|
end
|
166
165
|
|
167
166
|
# Enrich the core Integer class with this module.
|
data/lib/bson/registry.rb
CHANGED
data/lib/bson/symbol.rb
CHANGED
@@ -30,6 +30,22 @@ module BSON
|
|
30
30
|
# @since 2.0.0
|
31
31
|
BSON_TYPE = 14.chr.force_encoding(BINARY).freeze
|
32
32
|
|
33
|
+
# Symbols are serialized as strings as symbols are now removed from the
|
34
|
+
# BSON specification. Therefore the bson_type when serializing must be a
|
35
|
+
# string.
|
36
|
+
#
|
37
|
+
# @example Get the BSON type for the symbol.
|
38
|
+
# :test.bson_type
|
39
|
+
#
|
40
|
+
# @return [ String ] The single byte BSON type.
|
41
|
+
#
|
42
|
+
# @see http://bsonspec.org/#/specification
|
43
|
+
#
|
44
|
+
# @since 4.0.0
|
45
|
+
def bson_type
|
46
|
+
String::BSON_TYPE
|
47
|
+
end
|
48
|
+
|
33
49
|
# Get the symbol as encoded BSON.
|
34
50
|
#
|
35
51
|
# @example Get the symbol as encoded BSON.
|
@@ -89,7 +105,7 @@ module BSON
|
|
89
105
|
# Register this type when the module is loaded.
|
90
106
|
#
|
91
107
|
# @since 2.0.0
|
92
|
-
Registry.
|
108
|
+
Registry::MAPPINGS.store(BSON_TYPE, ::Symbol)
|
93
109
|
end
|
94
110
|
|
95
111
|
# Enrich the core Symbol class with this module.
|
data/lib/bson/version.rb
CHANGED
data/lib/native.bundle
ADDED
Binary file
|
data/spec/bson/document_spec.rb
CHANGED
@@ -98,33 +98,61 @@ describe BSON::Document do
|
|
98
98
|
|
99
99
|
describe "#delete" do
|
100
100
|
|
101
|
-
|
102
|
-
let(:val) { "ffffff" }
|
103
|
-
let(:bad_key) { "black" }
|
101
|
+
shared_examples_for "a document with deletable pairs" do
|
104
102
|
|
105
|
-
|
106
|
-
|
107
|
-
|
103
|
+
let!(:deleted) { doc.delete(key) }
|
104
|
+
|
105
|
+
it "returns the deleted value" do
|
106
|
+
expect(deleted).to eq(val)
|
107
|
+
end
|
108
108
|
|
109
|
-
|
109
|
+
it "removes the key from the list" do
|
110
|
+
expect(doc.keys.length).to eq(keys.length)
|
111
|
+
end
|
110
112
|
|
111
|
-
|
112
|
-
|
113
|
-
|
113
|
+
it "matches the keys length to the document length" do
|
114
|
+
expect(doc.length).to eq(doc.keys.length)
|
115
|
+
end
|
114
116
|
|
115
|
-
|
116
|
-
|
117
|
+
context "when removing a bad key" do
|
118
|
+
|
119
|
+
it "returns nil" do
|
120
|
+
expect(doc.delete(bad_key)).to be_nil
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when a block is provided" do
|
124
|
+
|
125
|
+
it "returns the result of the block" do
|
126
|
+
expect(doc.delete(bad_key) { |k| "golden key" }).to eq("golden key")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
117
130
|
end
|
118
131
|
|
119
|
-
|
120
|
-
|
132
|
+
context "when keys are strings" do
|
133
|
+
|
134
|
+
let(:key) { "white" }
|
135
|
+
let(:val) { "ffffff" }
|
136
|
+
let(:bad_key) { "black" }
|
137
|
+
|
138
|
+
before do
|
139
|
+
doc[key] = val
|
140
|
+
end
|
141
|
+
|
142
|
+
it_behaves_like "a document with deletable pairs"
|
121
143
|
end
|
122
144
|
|
123
|
-
context "when
|
145
|
+
context "when keys are symbols" do
|
146
|
+
|
147
|
+
let(:key) { :white }
|
148
|
+
let(:val) { "ffffff" }
|
149
|
+
let(:bad_key) { :black }
|
124
150
|
|
125
|
-
|
126
|
-
|
151
|
+
before do
|
152
|
+
doc[key] = val
|
127
153
|
end
|
154
|
+
|
155
|
+
it_behaves_like "a document with deletable pairs"
|
128
156
|
end
|
129
157
|
end
|
130
158
|
|
@@ -812,15 +840,6 @@ describe BSON::Document do
|
|
812
840
|
end
|
813
841
|
end
|
814
842
|
|
815
|
-
context "when the symbols are utf-8" do
|
816
|
-
|
817
|
-
let(:document) do
|
818
|
-
described_class["type", "gültig".to_sym]
|
819
|
-
end
|
820
|
-
|
821
|
-
it_behaves_like "a document able to handle utf-8"
|
822
|
-
end
|
823
|
-
|
824
843
|
context "when utf-8 string values are in an array" do
|
825
844
|
|
826
845
|
let(:document) do
|
@@ -868,7 +887,7 @@ describe BSON::Document do
|
|
868
887
|
end
|
869
888
|
end
|
870
889
|
|
871
|
-
context "when binary strings with utf-8 values exist", if: BSON::Environment.jruby? &&
|
890
|
+
context "when binary strings with utf-8 values exist", if: BSON::Environment.jruby? && (JRUBY_VERSION !~ /9.0/) do
|
872
891
|
|
873
892
|
let(:string) { "europäisch" }
|
874
893
|
let(:document) do
|
data/spec/bson/hash_spec.rb
CHANGED
@@ -37,6 +37,21 @@ describe Hash do
|
|
37
37
|
it_behaves_like "a deserializable bson element"
|
38
38
|
end
|
39
39
|
|
40
|
+
context "when the hash has non-string keys" do
|
41
|
+
|
42
|
+
let(:obj) do
|
43
|
+
{ 1 => "value" }
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:expected) do
|
47
|
+
{ "1" => "value" }
|
48
|
+
end
|
49
|
+
|
50
|
+
it "properly converts to bson" do
|
51
|
+
expect(BSON::Document.from_bson(BSON::ByteBuffer.new(obj.to_bson.to_s))).to eq(expected)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
40
55
|
context "when the hash is embedded" do
|
41
56
|
|
42
57
|
let(:obj) do
|
data/spec/bson/integer_spec.rb
CHANGED
@@ -62,10 +62,10 @@ describe Integer do
|
|
62
62
|
describe "#to_bson_key" do
|
63
63
|
|
64
64
|
let(:obj) { Integer::MAX_32BIT - 1 }
|
65
|
-
let(:encoded) { obj.to_s
|
65
|
+
let(:encoded) { obj.to_s }
|
66
66
|
|
67
|
-
it "returns the
|
68
|
-
expect(obj.to_bson_key
|
67
|
+
it "returns the key as a string" do
|
68
|
+
expect(obj.to_bson_key).to eq(encoded)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
data/spec/bson/registry_spec.rb
CHANGED
@@ -35,10 +35,8 @@ describe BSON::Registry do
|
|
35
35
|
|
36
36
|
context "when the type has no corresponding class" do
|
37
37
|
|
38
|
-
it "
|
39
|
-
expect
|
40
|
-
described_class.get("test")
|
41
|
-
}.to raise_error(KeyError)
|
38
|
+
it "returns nil" do
|
39
|
+
expect(described_class.get("test")).to be_nil
|
42
40
|
end
|
43
41
|
end
|
44
42
|
end
|
data/spec/bson/symbol_spec.rb
CHANGED
@@ -16,16 +16,22 @@ require "spec_helper"
|
|
16
16
|
|
17
17
|
describe Symbol do
|
18
18
|
|
19
|
+
describe "#bson_type" do
|
20
|
+
|
21
|
+
it "returns the type for a string" do
|
22
|
+
expect(:type.bson_type).to eq("type".bson_type)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
19
26
|
describe "#to_bson/#from_bson" do
|
20
27
|
|
21
|
-
let(:type) {
|
28
|
+
let(:type) { 2.chr }
|
22
29
|
let(:obj) { :test }
|
23
30
|
let(:bson) { "#{5.to_bson.to_s}test#{BSON::NULL_BYTE}" }
|
24
31
|
|
25
32
|
it_behaves_like "a bson element"
|
26
33
|
it_behaves_like "a serializable bson element"
|
27
34
|
it_behaves_like "a deserializable bson element"
|
28
|
-
|
29
35
|
end
|
30
36
|
|
31
37
|
describe "#to_bson_key" do
|
data/spec/spec_helper.rb
CHANGED
@@ -15,15 +15,6 @@
|
|
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"] && !ENV["WITH_EXT"]
|
19
|
-
require "simplecov"
|
20
|
-
require "coveralls"
|
21
|
-
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
22
|
-
SimpleCov.start do
|
23
|
-
add_filter "spec"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
18
|
require "bson"
|
28
19
|
require "json"
|
29
20
|
require "rspec"
|
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: 4.0.0
|
4
|
+
version: 4.0.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Tyler Brock
|
@@ -34,7 +34,7 @@ cert_chain:
|
|
34
34
|
XZOS48LlWh15EG4yZo/gRzqNAW2LUIkYA5eMS2Kp6r+KV8IBUO/LaHdrXbdilpa8
|
35
35
|
BRsuCo7UZDbFVRns04HLyjVvkj+K/ywIcdKdS0csz5M=
|
36
36
|
-----END CERTIFICATE-----
|
37
|
-
date: 2015-
|
37
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
38
38
|
dependencies: []
|
39
39
|
description: A full featured BSON specification implementation, in Ruby
|
40
40
|
email:
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/bson/true_class.rb
|
83
83
|
- lib/bson/undefined.rb
|
84
84
|
- lib/bson/version.rb
|
85
|
+
- lib/native.bundle
|
85
86
|
- spec/bson/array_spec.rb
|
86
87
|
- spec/bson/binary_spec.rb
|
87
88
|
- spec/bson/boolean_spec.rb
|
@@ -124,17 +125,17 @@ require_paths:
|
|
124
125
|
- lib
|
125
126
|
required_ruby_version: !ruby/object:Gem::Requirement
|
126
127
|
requirements:
|
127
|
-
- -
|
128
|
+
- - ">="
|
128
129
|
- !ruby/object:Gem::Version
|
129
130
|
version: 1.9.3
|
130
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
132
|
requirements:
|
132
|
-
- -
|
133
|
+
- - ">="
|
133
134
|
- !ruby/object:Gem::Version
|
134
135
|
version: 1.3.6
|
135
136
|
requirements: []
|
136
137
|
rubyforge_project: bson
|
137
|
-
rubygems_version: 2.4.
|
138
|
+
rubygems_version: 2.4.8
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: Ruby Implementation of the BSON specification
|
metadata.gz.sig
CHANGED
Binary file
|