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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfc4e9e218bc9b71f1881192cfe7d4a647a085c2
4
- data.tar.gz: 3b4f3a00ffb362383bb153471683ccb117d7bed6
3
+ metadata.gz: 51d0ffbb27a8a61c61ddb11362bedefc925bb93b
4
+ data.tar.gz: 704a6ba96297053bca1ca64bf4c3955636e3dda1
5
5
  SHA512:
6
- metadata.gz: 2fe2667809ba737140cc19a02c75cee9e2a96c107ab99d3cd7b6b87f060b15cdfca75eba4ae43eec222a3da8f059a4f8fd5935baec018ea43d76473ac563378e
7
- data.tar.gz: 88d6cd83e9f4160c12a433ff624932e4868d6605a3c8202587a5a89a1f8353fb86aecbc4e455e0b4b7eaa1be5cf63dc897774c2a56219d7a65504bd9e48e30d6
6
+ metadata.gz: da4ee6399c526058ab0448f91e9bac86d8ff1a239e080e4d4f1357689919e5056c987ead50f45b59aa2e7cff7fe5bea52479e6f94021d46729e9512297f51050
7
+ data.tar.gz: f3e9bd53a3bb5d43b0f07615c0a63b1aef057876fc319e50f8f584fddee3cd08ad3ebb522f3fb19cd69373df0e4fcc88af202fe8250035eaa673e5bd5a663aa5
Binary file
Binary file
@@ -0,0 +1,80 @@
1
+ BSON Changelog
2
+ ==============
3
+
4
+ ## 2.0.0
5
+
6
+ ### Backwards Incompatible Changes
7
+
8
+ * `BSON::DEFAULT_MAX_BSON_SIZE` has been removed, as the BSON specification does not
9
+ provide an upper limit on how large BSON documents can be.
10
+
11
+ * `BSON.serialize` is no longer the entry point to serialize a BSON document into its
12
+ raw bytes.
13
+
14
+ For Ruby runtimes that support ordered hashes, you may simply call `to_bson` on
15
+ the hash instance (Alternatively a `BSON::Document` is also a hash:
16
+
17
+ { key: "value" }.to_bson
18
+ BSON::Document[:key, "value"].to_bson
19
+
20
+ For Ruby runtimes that do not support ordered hashes, then you must instantiate
21
+ an instance of a `BSON::Document` (which is a subclass of hash) and call `to_bson`
22
+ on that, since the BSON specification guarantees order of the fields:
23
+
24
+ BSON::Document[:key, "value"].to_bson
25
+
26
+ * `BSON.deserialize` is no longer the entry point for raw byte deserialization into
27
+ a document.
28
+
29
+ For Ruby runtimes that support ordered hashes, you may simply call `from_bson` on
30
+ the `Hash` class if you want a `Hash` instance, or on `BSON::Document` if you
31
+ want an instance of that. The input must be a `StringIO` object:
32
+
33
+ Hash.from_bson(stringio)
34
+ BSON::Document.from_bson(stringio)
35
+
36
+ For Ruby runtimes that do not support ordered hashes, then `from_bson` must be
37
+ called on `BSON::Document` in order to guarantee order:
38
+
39
+ BSON::Document.from_bson(stringio)
40
+
41
+ * Calling `to_json` on custom BSON objects now outputs different results from before, and
42
+ conforms the BSON specification:
43
+
44
+ - `BSON::Binary`: `{ "$binary" : "\x01", "$type" : "md5" }`
45
+ - `BSON::Code`: `{ "$code" : "this.v = 5 }`
46
+ - `BSON::CodeWithScope`: `{ "$code" : "this.v = value", "$scope" : { v => 5 }}`
47
+ - `BSON::MaxKey`: `{ "$maxKey" : 1 }`
48
+ - `BSON::MinKey`: `{ "$minKey" : 1 }`
49
+ - `BSON::ObjectId`: `{ "$oid" : "4e4d66343b39b68407000001" }`
50
+ - `BSON::Timestamp`: `{ "t" : 5, "i" : 30 }`
51
+ - `Regexp`: `{ "$regex" : "[abc]", "$options" : "i" }`
52
+
53
+ ### New Features
54
+
55
+ * All Ruby objects that have a corresponding object defined in the BSON specification
56
+ can now have `to_bson` called on them to get the raw BSON bytes. These objects include:
57
+
58
+ - `Array`
59
+ - `FalseClass`
60
+ - `Float`
61
+ - `Hash`
62
+ - `Integer`
63
+ - `NilClass`
64
+ - `Regexp`
65
+ - `String`
66
+ - `Symbol` (deprecated)
67
+ - `Time`
68
+ - `TrueClass`
69
+
70
+ * Custom types specific to the BSON specification that have Ruby objects defined for them
71
+ may also have `to_bson` called on them to get the raw bytes. These types are:
72
+
73
+ - `BSON::Binary`
74
+ - `BSON::Code`
75
+ - `BSON::CodeWithScope`
76
+ - `BSON::MaxKey`
77
+ - `BSON::MinKey`
78
+ - `BSON::ObjectId`
79
+ - `BSON::Timestamp`
80
+ - `BSON::Undefined`
@@ -0,0 +1,42 @@
1
+ Contributing
2
+ ============
3
+
4
+ Code Conventions
5
+ ----------------
6
+
7
+ Code style should fall in line with the style guide outlined by
8
+ [Github](https://github.com/styleguide/ruby)
9
+
10
+ Testing
11
+ -------
12
+
13
+ Bug fixes and new features should always have the appropriate specs, and the
14
+ specs should follow the following guidelines:
15
+
16
+ - Prefer `let` and `let!` over the use of instance variables and `subject`.
17
+ - Prefer `expect(...).to eq(...) syntax over `...should eq(...)`.
18
+ - Use shared examples to reduce duplication.
19
+ - Use `describe "#method"` for instance method specs.
20
+ - Use `describe ".method"` for class method specs.
21
+ - Use `context` blocks to set up conditions.
22
+ - Always provide descriptive specifications via `it`.
23
+
24
+ Specs can be automatically run with Guard, via `bundle exec guard`
25
+
26
+ Before commiting, run `rake` to ensure all specs pass with both pure Ruby and
27
+ the native extensions.
28
+
29
+ Git Etiquette
30
+ -------------
31
+
32
+ Please follow the commit message guidelines as outlined
33
+ [in this blog post](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
34
+
35
+ If the commit fixes a bug, please add the JIRA number on the last line:
36
+
37
+ ```
38
+ [ close RUBY-492 ]
39
+ ```
40
+
41
+ Please ensure that only one feature/bug fix is in each pull request, and
42
+ that it is squashed into a single commit.
data/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright (C) 2008-2013 10gen, Inc.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
data/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Ruby BSON
2
+ Copyright (C) 2009-2013 10gen, Inc.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- BSON [![Build Status](https://secure.travis-ci.org/mongodb/bson-ruby.png?branch=master&.png)](http://travis-ci.org/mongodb/bson-ruby) [![Code Climate](https://codeclimate.com/github/mongodb/bson-ruby.png)](https://codeclimate.com/github/mongodb/bson-ruby)
1
+ BSON [![Build Status](https://secure.travis-ci.org/mongodb/bson-ruby.png?branch=master&.png)](http://travis-ci.org/mongodb/bson-ruby) [![Code Climate](https://codeclimate.com/github/mongodb/bson-ruby.png)](https://codeclimate.com/github/mongodb/bson-ruby) [![Coverage Status](https://coveralls.io/repos/mongodb/bson-ruby/badge.png?branch=master)](https://coveralls.io/r/mongodb/bson-ruby?branch=master)
2
2
  ====
3
3
 
4
4
  An implementation of the BSON specification in Ruby.
@@ -167,6 +167,11 @@ BSON Specification
167
167
 
168
168
  The [BSON specification](http://bsonspec.org) is at bsonspec.org.
169
169
 
170
+ Versioning
171
+ ----------
172
+
173
+ As of 2.0.0, this project adheres to the [Semantic Versioning Specification](http://semver.org/).
174
+
170
175
  License
171
176
  -------
172
177
 
data/Rakefile CHANGED
@@ -1,3 +1,17 @@
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
+
1
15
  require "bundler"
2
16
  Bundler.setup
3
17
 
@@ -42,7 +56,7 @@ end
42
56
  RSpec::Core::RakeTask.new(:spec)
43
57
  RSpec::Core::RakeTask.new(:rspec)
44
58
 
45
- task :build do
59
+ task :build => :clean_all do
46
60
  system "gem build bson.gemspec"
47
61
  end
48
62
 
@@ -1,3 +1,19 @@
1
+ /*
2
+ * Copyright (C) 2013 10gen Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
1
17
  #include <arpa/inet.h>
2
18
  #include <ruby.h>
3
19
  #include <stdint.h>
@@ -1,57 +1,19 @@
1
- # encoding: utf-8
2
-
3
- # Determine if we are using JRuby or not.
1
+ # Copyright (C) 2013 10gen Inc.
4
2
  #
5
- # @example Are we running with JRuby?
6
- # jruby?
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
7
6
  #
8
- # @return [ true, false ] If JRuby is our vm.
7
+ # http://www.apache.org/licenses/LICENSE-2.0
9
8
  #
10
- # @since 2.0.0
11
- def jruby?
12
- defined?(JRUBY_VERSION)
13
- end
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
14
 
15
- # Does the Ruby runtime we are using support ordered hashes?
16
- #
17
- # @example Does the runtime support ordered hashes?
18
- # ordered_hash_support?
19
- #
20
- # @return [ true, false ] If the runtime has ordered hashes.
21
- #
22
- # @since 2.0.0
23
- def ordered_hash_support?
24
- jruby? || RUBY_VERSION > "1.9.1"
25
- end
15
+ require "bson/environment"
26
16
 
27
- # Are we running in a ruby runtime that is version 1.8.x?
28
- #
29
- # @since 2.0.0
30
- def ruby_18?
31
- RUBY_VERSION < "1.9"
32
- end
33
-
34
- # In the case where we don't have encoding, we need to monkey
35
- # patch string to ignore the encoding directives.
36
- #
37
- # @since 2.0.0
38
- if ruby_18?
39
-
40
- class String
41
-
42
- # In versions prior to 1.9 we need to ignore the encoding requests.
43
- #
44
- # @since 2.0.0
45
- def chr; self; end
46
- def force_encoding(*); self; end
47
- def encode(*); self; end
48
- def encode!(*); self; end
49
- end
50
-
51
- class EncodingError < RuntimeError; end
52
- end
53
-
54
- #
55
17
  # The core namespace for all BSON related behaviour.
56
18
  #
57
19
  # @since 0.0.0
@@ -113,7 +75,7 @@ require "bson/version"
113
75
  #
114
76
  # @since 2.0.0
115
77
  begin
116
- if jruby?
78
+ if BSON::Environment.jruby?
117
79
  require "bson-ruby.jar"
118
80
  org.bson.NativeService.new.basicLoad(JRuby.runtime)
119
81
  else