bson 1.12.5-java → 2.0.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.

Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +80 -0
  5. data/CONTRIBUTING.md +42 -0
  6. data/NOTICE +2 -0
  7. data/README.md +190 -0
  8. data/Rakefile +109 -0
  9. data/lib/bson-ruby.jar +0 -0
  10. data/lib/bson.rb +60 -87
  11. data/lib/bson/array.rb +104 -0
  12. data/lib/bson/binary.rb +193 -0
  13. data/lib/bson/boolean.rb +48 -0
  14. data/lib/bson/code.rb +109 -0
  15. data/lib/bson/code_with_scope.rb +120 -0
  16. data/lib/bson/document.rb +549 -0
  17. data/lib/bson/encodable.rb +86 -0
  18. data/lib/bson/environment.rb +98 -0
  19. data/lib/bson/false_class.rb +61 -0
  20. data/lib/bson/float.rb +82 -0
  21. data/lib/bson/hash.rb +84 -0
  22. data/lib/bson/int32.rb +59 -0
  23. data/lib/bson/int64.rb +59 -0
  24. data/lib/bson/integer.rb +185 -0
  25. data/lib/bson/json.rb +37 -0
  26. data/lib/bson/max_key.rb +70 -0
  27. data/lib/bson/min_key.rb +70 -0
  28. data/lib/bson/nil_class.rb +70 -0
  29. data/lib/bson/object_id.rb +395 -0
  30. data/lib/bson/regexp.rb +124 -0
  31. data/lib/bson/registry.rb +70 -0
  32. data/lib/bson/specialized.rb +74 -0
  33. data/lib/bson/string.rb +203 -0
  34. data/lib/bson/symbol.rb +87 -0
  35. data/lib/bson/time.rb +72 -0
  36. data/lib/bson/timestamp.rb +113 -0
  37. data/lib/bson/true_class.rb +61 -0
  38. data/lib/bson/undefined.rb +74 -0
  39. data/lib/bson/version.rb +17 -0
  40. data/spec/bson/array_spec.rb +58 -0
  41. data/spec/bson/binary_spec.rb +115 -0
  42. data/spec/bson/boolean_spec.rb +48 -0
  43. data/spec/bson/code_spec.rb +42 -0
  44. data/spec/bson/code_with_scope_spec.rb +74 -0
  45. data/spec/bson/document_spec.rb +778 -0
  46. data/spec/bson/false_class_spec.rb +28 -0
  47. data/spec/bson/float_spec.rb +29 -0
  48. data/spec/bson/hash_spec.rb +56 -0
  49. data/spec/bson/int32_spec.rb +28 -0
  50. data/spec/bson/int64_spec.rb +28 -0
  51. data/spec/bson/integer_spec.rb +76 -0
  52. data/spec/bson/json_spec.rb +53 -0
  53. data/spec/bson/max_key_spec.rb +75 -0
  54. data/spec/bson/min_key_spec.rb +75 -0
  55. data/spec/bson/nil_class_spec.rb +29 -0
  56. data/spec/bson/object_id_spec.rb +527 -0
  57. data/spec/bson/regexp_spec.rb +89 -0
  58. data/spec/bson/registry_spec.rb +55 -0
  59. data/spec/bson/string_spec.rb +298 -0
  60. data/spec/bson/symbol_spec.rb +55 -0
  61. data/spec/bson/time_spec.rb +43 -0
  62. data/spec/bson/timestamp_spec.rb +74 -0
  63. data/spec/bson/true_class_spec.rb +28 -0
  64. data/spec/bson/undefined_spec.rb +29 -0
  65. data/{lib/bson/types/dbref.rb → spec/bson_spec.rb} +22 -16
  66. data/spec/spec_helper.rb +32 -0
  67. data/spec/support/shared_examples.rb +95 -0
  68. metadata +116 -48
  69. metadata.gz.sig +1 -1
  70. data/VERSION +0 -1
  71. data/bin/b2json +0 -63
  72. data/bin/j2bson +0 -64
  73. data/bson.gemspec +0 -34
  74. data/ext/jbson/lib/java-bson.jar +0 -0
  75. data/ext/jbson/target/jbson.jar +0 -0
  76. data/lib/bson/bson_c.rb +0 -37
  77. data/lib/bson/bson_java.rb +0 -49
  78. data/lib/bson/bson_ruby.rb +0 -645
  79. data/lib/bson/byte_buffer.rb +0 -241
  80. data/lib/bson/exceptions.rb +0 -37
  81. data/lib/bson/grow.rb +0 -173
  82. data/lib/bson/ordered_hash.rb +0 -197
  83. data/lib/bson/support/hash_with_indifferent_access.rb +0 -174
  84. data/lib/bson/types/binary.rb +0 -52
  85. data/lib/bson/types/code.rb +0 -55
  86. data/lib/bson/types/min_max_keys.rb +0 -56
  87. data/lib/bson/types/object_id.rb +0 -226
  88. data/lib/bson/types/regex.rb +0 -116
  89. data/lib/bson/types/timestamp.rb +0 -72
@@ -0,0 +1,28 @@
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 FalseClass do
18
+
19
+ describe "#to_bson" do
20
+
21
+ let(:obj) { false }
22
+ let(:bson) { 0.chr }
23
+ let(:type) { 8.chr }
24
+
25
+ it_behaves_like "a bson element"
26
+ it_behaves_like "a serializable bson element"
27
+ end
28
+ end
@@ -0,0 +1,29 @@
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 Float do
18
+
19
+ describe "#to_bson/#from_bson" do
20
+
21
+ let(:type) { 1.chr }
22
+ let(:obj) { 1.2332 }
23
+ let(:bson) { [ obj ].pack(Float::PACK) }
24
+
25
+ it_behaves_like "a bson element"
26
+ it_behaves_like "a serializable bson element"
27
+ it_behaves_like "a deserializable bson element"
28
+ end
29
+ end
@@ -0,0 +1,56 @@
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 Hash do
18
+
19
+ describe "#to_bson/#from_bson" do
20
+
21
+ let(:type) { 3.chr }
22
+
23
+ it_behaves_like "a bson element"
24
+
25
+ context "when the hash is a single level" do
26
+
27
+ let(:obj) do
28
+ { "key" => "value" }
29
+ end
30
+
31
+ let(:bson) do
32
+ "#{20.to_bson}#{String::BSON_TYPE}key#{BSON::NULL_BYTE}" +
33
+ "#{6.to_bson}value#{BSON::NULL_BYTE}#{BSON::NULL_BYTE}"
34
+ end
35
+
36
+ it_behaves_like "a serializable bson element"
37
+ it_behaves_like "a deserializable bson element"
38
+ end
39
+
40
+ context "when the hash is embedded" do
41
+
42
+ let(:obj) do
43
+ { "field" => { "key" => "value" }}
44
+ end
45
+
46
+ let(:bson) do
47
+ "#{32.to_bson}#{Hash::BSON_TYPE}field#{BSON::NULL_BYTE}" +
48
+ "#{20.to_bson}#{String::BSON_TYPE}key#{BSON::NULL_BYTE}" +
49
+ "#{6.to_bson}value#{BSON::NULL_BYTE}#{BSON::NULL_BYTE}#{BSON::NULL_BYTE}"
50
+ end
51
+
52
+ it_behaves_like "a serializable bson element"
53
+ it_behaves_like "a deserializable bson element"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,28 @@
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 BSON::Int32 do
18
+
19
+ describe "#from_bson" do
20
+
21
+ let(:type) { 16.chr }
22
+ let(:obj) { 123 }
23
+ let(:bson) { [ obj ].pack(BSON::Int32::PACK) }
24
+
25
+ it_behaves_like "a bson element"
26
+ it_behaves_like "a deserializable bson element"
27
+ end
28
+ end
@@ -0,0 +1,28 @@
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 BSON::Int64 do
18
+
19
+ describe "#from_bson" do
20
+
21
+ let(:type) { 18.chr }
22
+ let(:obj) { 1325376000000 }
23
+ let(:bson) { [ obj ].pack(BSON::Int64::PACK) }
24
+
25
+ it_behaves_like "a bson element"
26
+ it_behaves_like "a deserializable bson element"
27
+ end
28
+ end
@@ -0,0 +1,76 @@
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 Integer do
18
+
19
+ describe "#to_bson" do
20
+
21
+ context "when the integer is 32 bit" do
22
+
23
+ let(:type) { 16.chr }
24
+ let(:obj) { Integer::MAX_32BIT - 1 }
25
+ let(:bson) { [ obj ].pack(BSON::Int32::PACK) }
26
+
27
+ it_behaves_like "a serializable bson element"
28
+ end
29
+
30
+ context "when the integer is 64 bit" do
31
+
32
+ let(:type) { 18.chr }
33
+ let(:obj) { Integer::MAX_64BIT - 1 }
34
+ let(:bson) { [ obj ].pack(BSON::Int64::PACK) }
35
+
36
+ it_behaves_like "a serializable bson element"
37
+ end
38
+
39
+ context "when the integer is too large" do
40
+
41
+ let(:integer) { Integer::MAX_64BIT + 1 }
42
+
43
+ it "raises an out of range error" do
44
+ expect {
45
+ integer.to_bson
46
+ }.to raise_error(RangeError)
47
+ end
48
+ end
49
+
50
+ context "when the intger is too small" do
51
+
52
+ let(:integer) { Integer::MIN_64BIT - 1 }
53
+
54
+ it "raises an out of range error" do
55
+ expect {
56
+ integer.to_bson
57
+ }.to raise_error(RangeError)
58
+ end
59
+ end
60
+ end
61
+
62
+ describe "#to_bson_key" do
63
+
64
+ let(:obj) { Integer::MAX_32BIT - 1 }
65
+ let(:encoded) { obj.to_s + BSON::NULL_BYTE }
66
+ let(:previous_content) { 'previous_content'.force_encoding(BSON::BINARY) }
67
+
68
+ it "returns the encoded string" do
69
+ expect(obj.to_bson_key).to eq(encoded)
70
+ end
71
+
72
+ it "appends to optional previous content" do
73
+ expect(obj.to_bson_key(previous_content)).to eq(previous_content << encoded)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,53 @@
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 BSON::JSON do
18
+
19
+ describe "#to_json" do
20
+
21
+ let(:klass) do
22
+ Class.new do
23
+ include BSON::JSON
24
+
25
+ def as_json(*args)
26
+ { :test => "value" }
27
+ end
28
+ end
29
+ end
30
+
31
+ context "when provided no arguments" do
32
+
33
+ let(:json) do
34
+ klass.new.to_json
35
+ end
36
+
37
+ it "returns the object as json" do
38
+ expect(json).to eq("{\"test\":\"value\"}")
39
+ end
40
+ end
41
+
42
+ context "when provided arguments" do
43
+
44
+ let(:json) do
45
+ klass.new.to_json(:test)
46
+ end
47
+
48
+ it "returns the object as json" do
49
+ expect(json).to eq("{\"test\":\"value\"}")
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,75 @@
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 BSON::MaxKey do
18
+
19
+ describe "#==" do
20
+
21
+ context "when the objects are equal" do
22
+
23
+ let(:other) { described_class.new }
24
+
25
+ it "returns true" do
26
+ expect(subject).to eq(other)
27
+ end
28
+ end
29
+
30
+ context "when the other object is not a max_key" do
31
+
32
+ it "returns false" do
33
+ expect(subject).to_not eq("test")
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#>" do
39
+
40
+ it "always returns true" do
41
+ expect(subject > Integer::MAX_64BIT).to be_true
42
+ end
43
+ end
44
+
45
+ describe "#<" do
46
+
47
+ it "always returns false" do
48
+ expect(subject < Integer::MAX_64BIT).to be_false
49
+ end
50
+ end
51
+
52
+ describe "#as_json" do
53
+
54
+ let(:object) do
55
+ described_class.new
56
+ end
57
+
58
+ it "returns the binary data plus type" do
59
+ expect(object.as_json).to eq({ "$maxKey" => 1 })
60
+ end
61
+
62
+ it_behaves_like "a JSON serializable object"
63
+ end
64
+
65
+ describe "#to_bson/#from_bson" do
66
+
67
+ let(:type) { 127.chr }
68
+ let(:obj) { described_class.new }
69
+ let(:bson) { BSON::NO_VALUE }
70
+
71
+ it_behaves_like "a bson element"
72
+ it_behaves_like "a serializable bson element"
73
+ it_behaves_like "a deserializable bson element"
74
+ end
75
+ end
@@ -0,0 +1,75 @@
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 BSON::MinKey do
18
+
19
+ describe "#as_json" do
20
+
21
+ let(:object) do
22
+ described_class.new
23
+ end
24
+
25
+ it "returns the binary data plus type" do
26
+ expect(object.as_json).to eq({ "$minKey" => 1 })
27
+ end
28
+
29
+ it_behaves_like "a JSON serializable object"
30
+ end
31
+
32
+ describe "#==" do
33
+
34
+ context "when the objects are equal" do
35
+
36
+ let(:other) { described_class.new }
37
+
38
+ it "returns true" do
39
+ expect(subject).to eq(other)
40
+ end
41
+ end
42
+
43
+ context "when the other object is not a max_key" do
44
+
45
+ it "returns false" do
46
+ expect(subject).to_not eq("test")
47
+ end
48
+ end
49
+ end
50
+
51
+ describe "#>" do
52
+
53
+ it "always returns false" do
54
+ expect(subject > Integer::MAX_64BIT).to be_false
55
+ end
56
+ end
57
+
58
+ describe "#<" do
59
+
60
+ it "always returns true" do
61
+ expect(subject < Integer::MAX_64BIT).to be_true
62
+ end
63
+ end
64
+
65
+ describe "#to_bson/#from_bson" do
66
+
67
+ let(:type) { 255.chr }
68
+ let(:obj) { described_class.new }
69
+ let(:bson) { BSON::NO_VALUE }
70
+
71
+ it_behaves_like "a bson element"
72
+ it_behaves_like "a serializable bson element"
73
+ it_behaves_like "a deserializable bson element"
74
+ end
75
+ end