bson 2.0.0.beta → 2.0.0.rc

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 (72) 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/LICENSE +190 -0
  7. data/NOTICE +2 -0
  8. data/README.md +6 -1
  9. data/Rakefile +15 -1
  10. data/ext/bson/native.c +16 -0
  11. data/lib/bson.rb +12 -50
  12. data/lib/bson/array.rb +14 -1
  13. data/lib/bson/binary.rb +14 -1
  14. data/lib/bson/boolean.rb +14 -1
  15. data/lib/bson/code.rb +14 -1
  16. data/lib/bson/code_with_scope.rb +14 -1
  17. data/lib/bson/document.rb +15 -2
  18. data/lib/bson/encodable.rb +14 -1
  19. data/lib/bson/environment.rb +98 -0
  20. data/lib/bson/false_class.rb +14 -1
  21. data/lib/bson/float.rb +14 -1
  22. data/lib/bson/hash.rb +14 -1
  23. data/lib/bson/int32.rb +15 -2
  24. data/lib/bson/int64.rb +15 -2
  25. data/lib/bson/integer.rb +14 -1
  26. data/lib/bson/json.rb +14 -1
  27. data/lib/bson/max_key.rb +14 -1
  28. data/lib/bson/min_key.rb +14 -1
  29. data/lib/bson/nil_class.rb +14 -1
  30. data/lib/bson/object_id.rb +15 -2
  31. data/lib/bson/regexp.rb +14 -1
  32. data/lib/bson/registry.rb +14 -1
  33. data/lib/bson/specialized.rb +14 -1
  34. data/lib/bson/string.rb +14 -1
  35. data/lib/bson/symbol.rb +14 -1
  36. data/lib/bson/time.rb +14 -1
  37. data/lib/bson/timestamp.rb +14 -1
  38. data/lib/bson/true_class.rb +14 -1
  39. data/lib/bson/undefined.rb +15 -2
  40. data/lib/bson/version.rb +15 -2
  41. data/lib/native.bundle +0 -0
  42. data/spec/bson/array_spec.rb +31 -0
  43. data/spec/bson/binary_spec.rb +103 -0
  44. data/spec/bson/boolean_spec.rb +48 -0
  45. data/spec/bson/code_spec.rb +42 -0
  46. data/spec/bson/code_with_scope_spec.rb +70 -0
  47. data/spec/bson/document_spec.rb +778 -0
  48. data/spec/bson/false_class_spec.rb +28 -0
  49. data/spec/bson/float_spec.rb +29 -0
  50. data/spec/bson/hash_spec.rb +56 -0
  51. data/spec/bson/int32_spec.rb +28 -0
  52. data/spec/bson/int64_spec.rb +28 -0
  53. data/spec/bson/integer_spec.rb +76 -0
  54. data/spec/bson/json_spec.rb +53 -0
  55. data/spec/bson/max_key_spec.rb +75 -0
  56. data/spec/bson/min_key_spec.rb +75 -0
  57. data/spec/bson/nil_class_spec.rb +29 -0
  58. data/spec/bson/object_id_spec.rb +418 -0
  59. data/spec/bson/regexp_spec.rb +89 -0
  60. data/spec/bson/registry_spec.rb +55 -0
  61. data/spec/bson/string_spec.rb +271 -0
  62. data/spec/bson/symbol_spec.rb +45 -0
  63. data/spec/bson/time_spec.rb +43 -0
  64. data/spec/bson/timestamp_spec.rb +74 -0
  65. data/spec/bson/true_class_spec.rb +28 -0
  66. data/spec/bson/undefined_spec.rb +29 -0
  67. data/spec/bson_spec.rb +46 -0
  68. data/spec/spec_helper.rb +31 -0
  69. data/spec/support/shared_examples.rb +95 -0
  70. metadata +85 -5
  71. metadata.gz.sig +1 -0
  72. data/LICENSE.md +0 -13
@@ -1,4 +1,17 @@
1
- # encoding: utf-8
1
+ # Copyright (C) 2013 10gen 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
+
2
15
  require "digest/md5"
3
16
  require "socket"
4
17
  require "thread"
@@ -285,7 +298,7 @@ module BSON
285
298
 
286
299
  private
287
300
 
288
- if jruby?
301
+ if Environment.jruby?
289
302
  def process_id
290
303
  "#{Process.pid}#{Thread.current.object_id}".hash % 0xFFFF
291
304
  end
@@ -1,4 +1,17 @@
1
- # encoding: utf-8
1
+ # Copyright (C) 2013 10gen 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
+
2
15
  module BSON
3
16
 
4
17
  # Injects behaviour for encoding and decoding regular expression values to
@@ -1,4 +1,17 @@
1
- # encoding: utf-8
1
+ # Copyright (C) 2013 10gen 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
+
2
15
  module BSON
3
16
 
4
17
  # Provides constant values for each to the BSON types and mappings from raw
@@ -1,4 +1,17 @@
1
- # encoding: utf-8
1
+ # Copyright (C) 2013 10gen 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
+
2
15
  module BSON
3
16
 
4
17
  # Provides behaviour to special values that exist in the BSON spec that don't
@@ -1,4 +1,17 @@
1
- # encoding: utf-8
1
+ # Copyright (C) 2013 10gen 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
+
2
15
  module BSON
3
16
 
4
17
  # Injects behaviour for encoding and decoding string values to and from
@@ -1,4 +1,17 @@
1
- # encoding: utf-8
1
+ # Copyright (C) 2013 10gen 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
+
2
15
  module BSON
3
16
 
4
17
  # Injects behaviour for encoding and decoding symbol values to and from
@@ -1,4 +1,17 @@
1
- # encoding: utf-8
1
+ # Copyright (C) 2013 10gen 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
+
2
15
  module BSON
3
16
 
4
17
  # Injects behaviour for encoding and decoding time values to
@@ -1,4 +1,17 @@
1
- # encoding: utf-8
1
+ # Copyright (C) 2013 10gen 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
+
2
15
  module BSON
3
16
 
4
17
  # Represents a timestamp type, which is predominately used for sharding.
@@ -1,4 +1,17 @@
1
- # encoding: utf-8
1
+ # Copyright (C) 2013 10gen 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
+
2
15
  module BSON
3
16
 
4
17
  # Injects behaviour for encoding and decoding true values to and from
@@ -1,4 +1,17 @@
1
- # encoding: utf-8
1
+ # Copyright (C) 2013 10gen 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
+
2
15
  module BSON
3
16
 
4
17
  # Represents the Undefined BSON type
@@ -27,7 +40,7 @@ module BSON
27
40
  self.class == other.class
28
41
  end
29
42
 
30
- # Encode the Undefined field - has no value since it only needs the type
43
+ # Encode the Undefined field - has no value since it only needs the type
31
44
  # and field name when being encoded.
32
45
  #
33
46
  # @example Encode the undefined value.
@@ -1,4 +1,17 @@
1
- # encoding: utf-8
1
+ # Copyright (C) 2013 10gen 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
+
2
15
  module BSON
3
- VERSION = "2.0.0.beta"
16
+ VERSION = "2.0.0.rc"
4
17
  end
Binary file
@@ -0,0 +1,31 @@
1
+ # Copyright (C) 2013 10gen 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 Array do
18
+
19
+ describe "#to_bson/#from_bson" do
20
+
21
+ let(:type) { 4.chr }
22
+ let(:obj) {[ "one", "two" ]}
23
+ let(:bson) do
24
+ BSON::Document["0", "one", "1", "two"].to_bson
25
+ end
26
+
27
+ it_behaves_like "a bson element"
28
+ it_behaves_like "a serializable bson element"
29
+ it_behaves_like "a deserializable bson element"
30
+ end
31
+ end
@@ -0,0 +1,103 @@
1
+ # Copyright (C) 2013 10gen 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::Binary do
18
+
19
+ describe "#as_json" do
20
+
21
+ let(:object) do
22
+ described_class.new("testing", :user)
23
+ end
24
+
25
+ it "returns the binary data plus type" do
26
+ expect(object.as_json).to eq(
27
+ { "$binary" => "testing", "$type" => :user }
28
+ )
29
+ end
30
+
31
+ it_behaves_like "a JSON serializable object"
32
+ end
33
+
34
+ describe "#to_bson/#from_bson" do
35
+
36
+ let(:type) { 5.chr }
37
+
38
+ it_behaves_like "a bson element"
39
+
40
+ context "when the type is :generic" do
41
+
42
+ let(:obj) { described_class.new("testing") }
43
+ let(:bson) { "#{7.to_bson}#{0.chr}testing" }
44
+
45
+ it_behaves_like "a serializable bson element"
46
+ it_behaves_like "a deserializable bson element"
47
+ end
48
+
49
+ context "when the type is :function" do
50
+
51
+ let(:obj) { described_class.new("testing", :function) }
52
+ let(:bson) { "#{7.to_bson}#{1.chr}testing" }
53
+
54
+ it_behaves_like "a serializable bson element"
55
+ it_behaves_like "a deserializable bson element"
56
+ end
57
+
58
+ context "when the type is :old" do
59
+
60
+ let(:obj) { described_class.new("testing", :old) }
61
+ let(:bson) { "#{11.to_bson}#{2.chr}#{7.to_bson}testing" }
62
+
63
+ it_behaves_like "a serializable bson element"
64
+ it_behaves_like "a deserializable bson element"
65
+ end
66
+
67
+ context "when the type is :uuid_old" do
68
+
69
+ let(:obj) { described_class.new("testing", :uuid_old) }
70
+ let(:bson) { "#{7.to_bson}#{3.chr}testing" }
71
+
72
+ it_behaves_like "a serializable bson element"
73
+ it_behaves_like "a deserializable bson element"
74
+ end
75
+
76
+ context "when the type is :uuid" do
77
+
78
+ let(:obj) { described_class.new("testing", :uuid) }
79
+ let(:bson) { "#{7.to_bson}#{4.chr}testing" }
80
+
81
+ it_behaves_like "a serializable bson element"
82
+ it_behaves_like "a deserializable bson element"
83
+ end
84
+
85
+ context "when the type is :md5" do
86
+
87
+ let(:obj) { described_class.new("testing", :md5) }
88
+ let(:bson) { "#{7.to_bson}#{5.chr}testing" }
89
+
90
+ it_behaves_like "a serializable bson element"
91
+ it_behaves_like "a deserializable bson element"
92
+ end
93
+
94
+ context "when the type is :user" do
95
+
96
+ let(:obj) { described_class.new("testing", :user) }
97
+ let(:bson) { "#{7.to_bson}#{128.chr}testing" }
98
+
99
+ it_behaves_like "a serializable bson element"
100
+ it_behaves_like "a deserializable bson element"
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,48 @@
1
+ # Copyright (C) 2013 10gen 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::Boolean do
18
+
19
+ describe "::BSON_TYPE" do
20
+
21
+ it "returns 8" do
22
+ expect(BSON::Boolean::BSON_TYPE).to eq(8.chr)
23
+ end
24
+ end
25
+
26
+ describe "#from_bson" do
27
+
28
+ let(:type) { 8.chr }
29
+
30
+ it_behaves_like "a bson element"
31
+
32
+ context "when the boolean is true" do
33
+
34
+ let(:obj) { true }
35
+ let(:bson) { 1.chr }
36
+
37
+ it_behaves_like "a deserializable bson element"
38
+ end
39
+
40
+ context "when the boolean is false" do
41
+
42
+ let(:obj) { false }
43
+ let(:bson) { 0.chr }
44
+
45
+ it_behaves_like "a deserializable bson element"
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,42 @@
1
+ # Copyright (C) 2013 10gen 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::Code do
18
+
19
+ describe "#as_json" do
20
+
21
+ let(:object) do
22
+ described_class.new("this.value = 5")
23
+ end
24
+
25
+ it "returns the binary data plus type" do
26
+ expect(object.as_json).to eq({ "$code" => "this.value = 5" })
27
+ end
28
+
29
+ it_behaves_like "a JSON serializable object"
30
+ end
31
+
32
+ describe "#to_bson/#from_bson" do
33
+
34
+ let(:type) { 13.chr }
35
+ let(:obj) { described_class.new("this.value = 5") }
36
+ let(:bson) { "#{15.to_bson}this.value = 5#{BSON::NULL_BYTE}" }
37
+
38
+ it_behaves_like "a bson element"
39
+ it_behaves_like "a serializable bson element"
40
+ it_behaves_like "a deserializable bson element"
41
+ end
42
+ end