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
  module BSON
3
16
 
4
17
  # Injects behaviour for encoding and decoding arrays 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 binary data.
@@ -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 $maxKey type, which compares less than any other value in the
@@ -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 code type, which is a wrapper around javascript code.
@@ -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 code with scope, which is a wrapper around javascript code
@@ -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 "yaml"
3
16
 
4
17
  # Since we have a custom bsondoc type for yaml serialization, we need
@@ -44,7 +57,7 @@ module BSON
44
57
  # not, then we need to import our custom BSON::Document implementation.
45
58
  #
46
59
  # @since 2.0.0
47
- unless ordered_hash_support?
60
+ unless Environment.retaining_hash_order?
48
61
 
49
62
  # Message for argument error when providing bad arguments to [].
50
63
  #
@@ -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
  # Defines behaviour around objects that can be encoded.
@@ -0,0 +1,98 @@
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
+ module BSON
16
+
17
+ # Provides static helper methods around determining what environment is
18
+ # running without polluting the global namespace.
19
+ #
20
+ # @since 2.0.0
21
+ module Environment
22
+ extend self
23
+
24
+ # Determine if we are using JRuby or not.
25
+ #
26
+ # @example Are we running with JRuby?
27
+ # Environment.jruby?
28
+ #
29
+ # @return [ true, false ] If JRuby is our vm.
30
+ #
31
+ # @since 2.0.0
32
+ def jruby?
33
+ defined?(JRUBY_VERSION)
34
+ end
35
+
36
+ # Does the Ruby runtime we are using support ordered hashes?
37
+ #
38
+ # @example Does the runtime support ordered hashes?
39
+ # Environment.retaining_hash_order?
40
+ #
41
+ # @return [ true, false ] If the runtime has ordered hashes.
42
+ #
43
+ # @since 2.0.0
44
+ def retaining_hash_order?
45
+ jruby? || RUBY_VERSION > "1.9.1"
46
+ end
47
+
48
+ # Are we running in a ruby runtime that is version 1.8.x?
49
+ #
50
+ # @example Is the ruby runtime in 1.8 mode?
51
+ # Environment.ruby_18?
52
+ #
53
+ # @return [ true, false ] If we are running in 1.8.
54
+ #
55
+ # @since 2.0.0
56
+ def ruby_18?
57
+ RUBY_VERSION < "1.9"
58
+ end
59
+ end
60
+ end
61
+
62
+ # In the case where we don't have encoding, we need to monkey
63
+ # patch string to ignore the encoding directives.
64
+ #
65
+ # @since 2.0.0
66
+ if BSON::Environment.ruby_18?
67
+
68
+ # Making string in 1.8 respond like a 1.9 string, without any modifications.
69
+ #
70
+ # @since 2.0.0
71
+ class String
72
+
73
+ # Simply return the string when asking for it's character.
74
+ #
75
+ # @since 2.0.0
76
+ def chr; self; end
77
+
78
+ # Force the string to the provided encoding. NOOP.
79
+ #
80
+ # @since 2.0.0
81
+ def force_encoding(*); self; end
82
+
83
+ # Encode the string as the provided type. NOOP.
84
+ #
85
+ # @since 2.0.0
86
+ def encode(*); self; end
87
+
88
+ # Encode the string in place. NOOP.
89
+ #
90
+ # @since 2.0.0
91
+ def encode!(*); self; end
92
+ end
93
+
94
+ # No encoding error is defined in 1.8.
95
+ #
96
+ # @since 2.0.0
97
+ class EncodingError < RuntimeError; end
98
+ 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 false 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 floating point values
@@ -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 hashes 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 $maxKey type, which compares less than any other value in the
@@ -17,7 +30,7 @@ module BSON
17
30
  # Constant for the int 32 pack directive.
18
31
  #
19
32
  # @since 2.0.0
20
- PACK = ruby_18? ? "l".freeze : "l<".freeze
33
+ PACK = Environment.ruby_18? ? "l".freeze : "l<".freeze
21
34
 
22
35
  # Deserialize an Integer from BSON.
23
36
  #
@@ -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 $maxKey type, which compares less than any other value in the
@@ -17,7 +30,7 @@ module BSON
17
30
  # Constant for the int 64 pack directive.
18
31
  #
19
32
  # @since 2.0.0
20
- PACK = ruby_18? ? "q".freeze : "q<".freeze
33
+ PACK = Environment.ruby_18? ? "q".freeze : "q<".freeze
21
34
 
22
35
  # Deserialize an Integer from BSON.
23
36
  #
@@ -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 integer 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
  require "json"
3
16
 
4
17
  module BSON
@@ -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 $maxKey type, which compares less than any other value in the
@@ -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 $minKey type, which compares less than any other value in the
@@ -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 nil values to and from