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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01ad7308ec0a814e717219df3f2c8740b5f72d46
4
- data.tar.gz: 07588d4b17b511b33d0bab4cf8990d84d7878e6c
3
+ metadata.gz: adc9440ef40323da8c8098642b894593864cd07d
4
+ data.tar.gz: 1618998d46b189ff41371626e91e6e236dddd850
5
5
  SHA512:
6
- metadata.gz: fbc4f3ea261b682700b87d04170e11bba3a3998e5bf1df3a001cb9e141f5eb8bd6550649b742decb653c2ebd651866a821d13790ab8c7dedc001945e32682ce8
7
- data.tar.gz: cc54f36478149b4ab24a1cd9b77355f6480452fa98a2406bae42aec5fbfa1c16bc1ccb98ddde2e3a7fa696317c3129cfb9df14a889c0801a60b95ce53404f1e2
6
+ metadata.gz: 8c48f605a15889ccbf0293bb0483a200ec300749b18e3239c3f12b0ff118e52582fe696f3e243323ece726ffe2344669ca78af41d20a8f36b025bb6cf1f73d3d
7
+ data.tar.gz: d1284a224eb9ddd3bb9557aa33d88d328538adc44c64a622f5ed0f1f9a305023cd399bf3b2c1ce60549bfe80529a4abfef5bdce73654e52c1caac4328b83c6ff
Binary file
data.tar.gz.sig CHANGED
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/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Ruby BSON
2
+ Copyright (C) 2009-2013 MongoDB, Inc.
@@ -0,0 +1,190 @@
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
+ ====
3
+
4
+ An implementation of the BSON specification in Ruby.
5
+
6
+ Compatibility
7
+ -------------
8
+
9
+ BSON is tested against MRI (1.8.7+), JRuby (1.5.0+), Rubinius (2.0.0+), and REE.
10
+
11
+ Installation
12
+ ------------
13
+
14
+ With bundler, add the `bson` gem to your `Gemfile`. As of 2.0.0 native extensions
15
+ are bundled with the `bson` gem and `bson_ext` is no longer needed.
16
+
17
+ ```ruby
18
+ gem "bson", "~> 2.0"
19
+ ```
20
+
21
+ Require the `bson` gem in your application.
22
+
23
+ ```ruby
24
+ require "bson"
25
+ ```
26
+
27
+ Usage
28
+ -----
29
+
30
+ ### BSON Serialization
31
+
32
+ Getting a Ruby object's raw BSON representation is done by calling `to_bson`
33
+ on the Ruby object. For example:
34
+
35
+ ```ruby
36
+ "Shall I compare thee to a summer's day".to_bson
37
+ 1024.to_bson
38
+ ```
39
+
40
+ Generating an object from BSON is done via calling `from_bson` on the class
41
+ you wish to instantiate and passing it the `StringIO` bytes.
42
+
43
+ ```ruby
44
+ String.from_bson(string_io)
45
+ Int32.from_bson(string_io)
46
+ ```
47
+
48
+ Core Ruby object's that have representations in the BSON specification and
49
+ will have a `to_bson` method defined for them are:
50
+
51
+ - `Array`
52
+ - `FalseClass`
53
+ - `Float`
54
+ - `Hash`
55
+ - `Integer`
56
+ - `NilClass`
57
+ - `Regexp`
58
+ - `String`
59
+ - `Symbol` (deprecated)
60
+ - `Time`
61
+ - `TrueClass`
62
+
63
+ In addition to the core Ruby objects, BSON also provides some special types
64
+ specific to the specification:
65
+
66
+ #### `BSON::Binary`
67
+
68
+ This is a representation of binary data, and must provide the raw data and
69
+ a subtype when constructing.
70
+
71
+ ```ruby
72
+ BSON::Binary.new(binary_data, :md5)
73
+ ```
74
+
75
+ Valid subtypes are: `:generic`, `:function`, `:old`, `:uuid_old`, `:uuid`,
76
+ `:md5`, `:user`.
77
+
78
+ #### `BSON::Code`
79
+
80
+ Represents a string of Javascript code.
81
+
82
+ ```ruby
83
+ BSON::Code.new("this.value = 5;")
84
+ ```
85
+
86
+ #### `BSON::CodeWithScope`
87
+
88
+ Represents a string of Javascript code with a hash of values.
89
+
90
+ ```ruby
91
+ BSON::CodeWithScope.new("this.value = age;", age: 5)
92
+ ```
93
+
94
+ #### `BSON::Document`
95
+
96
+ This is a special ordered hash for use with Ruby below 1.9, and is simply
97
+ a subclass of a Ruby hash in 1.9 and higher.
98
+
99
+ ```ruby
100
+ BSON::Document[:key, "value"]
101
+ BSON::Document.new
102
+ ```
103
+
104
+ #### `BSON::MaxKey`
105
+
106
+ Represents a value in BSON that will always compare higher to another value.
107
+
108
+ ```ruby
109
+ BSON::MaxKey.new
110
+ ```
111
+
112
+ #### `BSON::MinKey`
113
+
114
+ Represents a value in BSON that will always compare lower to another value.
115
+
116
+ ```ruby
117
+ BSON::MinKey.new
118
+ ```
119
+
120
+ #### `BSON::ObjectId`
121
+
122
+ Represents a 12 byte unique identifier for an object on a given machine.
123
+
124
+ ```ruby
125
+ BSON::ObjectId.new
126
+ ```
127
+
128
+ #### `BSON::Timestamp`
129
+
130
+ Represents a special time with a start and increment value.
131
+
132
+ ```ruby
133
+ BSON::Timestamp.new(5, 30)
134
+ ```
135
+
136
+ #### `BSON::Undefined`
137
+
138
+ Represents a placeholder for a value that was not provided.
139
+
140
+ ```ruby
141
+ BSON::Undefined.new
142
+ ```
143
+
144
+ ### JSON Serialization
145
+
146
+ Some BSON types have special representations in JSON. These are as follows
147
+ and will be automatically serialized in the form when calling `to_json` on
148
+ them.
149
+
150
+ - `BSON::Binary`: `{ "$binary" : "\x01", "$type" : "md5" }`
151
+ - `BSON::Code`: `{ "$code" : "this.v = 5 }`
152
+ - `BSON::CodeWithScope`: `{ "$code" : "this.v = value", "$scope" : { v => 5 }}`
153
+ - `BSON::MaxKey`: `{ "$maxKey" : 1 }`
154
+ - `BSON::MinKey`: `{ "$minKey" : 1 }`
155
+ - `BSON::ObjectId`: `{ "$oid" : "4e4d66343b39b68407000001" }`
156
+ - `BSON::Timestamp`: `{ "t" : 5, "i" : 30 }`
157
+ - `Regexp`: `{ "$regex" : "[abc]", "$options" : "i" }`
158
+
159
+ API Documentation
160
+ -----------------
161
+
162
+ The [API Documentation](http://rdoc.info/github/mongodb/bson-ruby/master/frames) is
163
+ located at rdoc.info.
164
+
165
+ BSON Specification
166
+ ------------------
167
+
168
+ The [BSON specification](http://bsonspec.org) is at bsonspec.org.
169
+
170
+ Versioning
171
+ ----------
172
+
173
+ As of 2.0.0, this project adheres to the [Semantic Versioning Specification](http://semver.org/).
174
+
175
+ License
176
+ -------
177
+
178
+ Copyright (C) 2009-2013 MongoDB 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.
@@ -0,0 +1,109 @@
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 "bundler"
16
+ Bundler.setup
17
+
18
+ $LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
19
+
20
+ require "rake"
21
+ require "rake/extensiontask"
22
+ require "rspec/core/rake_task"
23
+
24
+ def jruby?
25
+ defined?(JRUBY_VERSION)
26
+ end
27
+
28
+ if jruby?
29
+ require "rake/javaextensiontask"
30
+ Rake::JavaExtensionTask.new do |ext|
31
+ ext.name = "bson-ruby"
32
+ ext.ext_dir = "src"
33
+ ext.lib_dir = "lib"
34
+ end
35
+ else
36
+ require "rake/extensiontask"
37
+ Rake::ExtensionTask.new do |ext|
38
+ ext.name = "native"
39
+ ext.ext_dir = "ext/bson"
40
+ ext.lib_dir = "lib"
41
+ end
42
+ end
43
+
44
+ require "bson/version"
45
+
46
+ def extension
47
+ RUBY_PLATFORM =~ /darwin/ ? "bundle" : "so"
48
+ end
49
+
50
+ if RUBY_VERSION < "1.9"
51
+ require "perf/bench"
52
+ else
53
+ require_relative "perf/bench"
54
+ end
55
+
56
+ RSpec::Core::RakeTask.new(:spec)
57
+ RSpec::Core::RakeTask.new(:rspec)
58
+
59
+ if jruby?
60
+ task :build => [ :clean_all, :compile ] do
61
+ system "gem build bson.gemspec"
62
+ end
63
+ else
64
+ task :build => :clean_all do
65
+ system "gem build bson.gemspec"
66
+ end
67
+ end
68
+
69
+ task :clean_all => :clean do
70
+ begin
71
+ Dir.chdir(Pathname(__FILE__).dirname + "lib") do
72
+ `rm native.#{extension}`
73
+ `rm native.o`
74
+ `rm bson-ruby.jar`
75
+ end
76
+ rescue Exception => e
77
+ puts e.message
78
+ end
79
+ end
80
+
81
+ # Run bundle exec rake release with mri and jruby.
82
+ task :release => :build do
83
+ system "git tag -a v#{BSON::VERSION} -m 'Tagging release: #{BSON::VERSION}'"
84
+ system "git push --tags"
85
+ if jruby?
86
+ system "gem push bson-#{BSON::VERSION}-java.gem"
87
+ system "rm bson-#{BSON::VERSION}-java.gem"
88
+ else
89
+ system "gem push bson-#{BSON::VERSION}.gem"
90
+ system "rm bson-#{BSON::VERSION}.gem"
91
+ end
92
+ end
93
+
94
+ namespace :benchmark do
95
+
96
+ task :ruby => :clean_all do
97
+ puts "Benchmarking pure Ruby..."
98
+ require "bson"
99
+ benchmark!
100
+ end
101
+
102
+ task :native => :compile do
103
+ puts "Benchmarking with native extensions..."
104
+ require "bson"
105
+ benchmark!
106
+ end
107
+ end
108
+
109
+ task :default => [ :clean_all, :spec, :compile, :rspec ]
Binary file
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2013 MongoDB, Inc.
1
+ # Copyright (C) 2009-2013 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -12,102 +12,75 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- module BSON
16
- DEFAULT_MAX_BSON_SIZE = 4 * 1024 * 1024
15
+ require "bson/environment"
17
16
 
18
- def self.serialize(obj, check_keys=false, move_id=false)
19
- BSON_CODER.serialize(obj, check_keys, move_id)
20
- end
17
+ # The core namespace for all BSON related behaviour.
18
+ #
19
+ # @since 0.0.0
20
+ module BSON
21
21
 
22
- def self.deserialize(buf=nil, opts={})
23
- BSON_CODER.deserialize(buf, opts)
24
- end
22
+ # Constant for binary string encoding.
23
+ #
24
+ # @since 2.0.0
25
+ BINARY = "BINARY".freeze
25
26
 
26
- # Reads a single BSON document from an IO object.
27
- # This method is used in the executable b2json, bundled with
28
- # the bson gem, for reading a file of bson documents.
27
+ # Constant for bson types that don't actually serialize a value.
29
28
  #
30
- # @param [IO] io an io object containing a bson object.
29
+ # @since 2.0.0
30
+ NO_VALUE = "".force_encoding(BINARY).freeze
31
+
32
+ # Constant for a null byte (0x00).
31
33
  #
32
- # @return [ByteBuffer]
33
- def self.read_bson_document(io)
34
- bytebuf = BSON::ByteBuffer.new
35
- sz = io.read(4).unpack("V")[0]
36
- bytebuf.put_int(sz)
37
- bytebuf.put_array(io.read(sz-4).unpack("C*"))
38
- bytebuf.rewind
39
- return BSON.deserialize(bytebuf)
40
- end
34
+ # @since 2.0.0
35
+ NULL_BYTE = 0.chr.force_encoding(BINARY).freeze
41
36
 
42
- def self.extension?
43
- !((ENV.key?('BSON_EXT_DISABLED') && RUBY_PLATFORM =~ /java/) ||
44
- (ENV.key?('BSON_EXT_DISABLED') || "\x01\x00\x00\x00".unpack("i")[0] != 1))
45
- end
37
+ # Constant for UTF-8 string encoding.
38
+ #
39
+ # @since 2.0.0
40
+ UTF8 = "UTF-8".freeze
46
41
  end
47
42
 
48
- begin
49
- # Skips loading extensions if one of the following is true:
50
- # 1) JRuby and BSON_EXT_DISABLED is set.
51
- # -OR-
52
- # 2) Ruby MRI and big endian or BSON_EXT_DISABLED is set.
53
- raise LoadError unless BSON.extension?
43
+ require "bson/registry"
44
+ require "bson/specialized"
45
+ require "bson/json"
46
+ require "bson/int32"
47
+ require "bson/int64"
48
+ require "bson/integer"
49
+ require "bson/encodable"
50
+ require "bson/array"
51
+ require "bson/binary"
52
+ require "bson/boolean"
53
+ require "bson/code"
54
+ require "bson/code_with_scope"
55
+ require "bson/document"
56
+ require "bson/false_class"
57
+ require "bson/float"
58
+ require "bson/hash"
59
+ require "bson/max_key"
60
+ require "bson/min_key"
61
+ require "bson/nil_class"
62
+ require "bson/object_id"
63
+ require "bson/regexp"
64
+ require "bson/string"
65
+ require "bson/symbol"
66
+ require "bson/time"
67
+ require "bson/timestamp"
68
+ require "bson/true_class"
69
+ require "bson/undefined"
70
+ require "bson/version"
54
71
 
55
- if RUBY_PLATFORM =~ /java/
56
- require 'bson/bson_java'
57
- module BSON
58
- BSON_CODER = BSON_JAVA
59
- end
72
+ # If we are using JRuby, attempt to load the Java extensions, if we are using
73
+ # MRI or Rubinius, attempt to load the C extenstions. If either of these fail,
74
+ # we revert back to a pure Ruby implementation of the Buffer class.
75
+ #
76
+ # @since 2.0.0
77
+ begin
78
+ if BSON::Environment.jruby?
79
+ require "bson-ruby.jar"
80
+ org.bson.NativeService.new.basicLoad(JRuby.runtime)
60
81
  else
61
- require 'bson_ext/cbson'
62
- raise LoadError unless defined?(CBson::VERSION)
63
- require 'bson/bson_c'
64
- module BSON
65
- BSON_CODER = BSON_C
66
- end
82
+ require "native"
67
83
  end
68
84
  rescue LoadError
69
- require 'bson/bson_ruby'
70
- module BSON
71
- BSON_CODER = BSON_RUBY
72
- end
73
-
74
- if RUBY_PLATFORM =~ /java/
75
- unless ENV['TEST_MODE']
76
- warn <<-NOTICE
77
- ** Notice: The BSON extension was not loaded. **
78
-
79
- For optimal performance, use of the BSON extension is recommended. To
80
- enable the extension make sure ENV['BSON_EXT_DISABLED'] is not set.
81
- NOTICE
82
- end
83
- else
84
- unless ENV['TEST_MODE']
85
- warn <<-NOTICE
86
- ** Notice: The native BSON extension was not loaded. **
87
-
88
- For optimal performance, use of the BSON extension is recommended.
89
-
90
- To enable the extension make sure ENV['BSON_EXT_DISABLED'] is not set
91
- and run the following command:
92
-
93
- gem install bson_ext
94
-
95
- If you continue to receive this message after installing, make sure that
96
- the bson_ext gem is in your load path.
97
- NOTICE
98
- end
99
- end
85
+ $stderr.puts("BSON is using the pure Ruby implementation.")
100
86
  end
101
-
102
- require 'base64'
103
- require 'bson/bson_ruby'
104
- require 'bson/byte_buffer'
105
- require 'bson/exceptions'
106
- require 'bson/ordered_hash'
107
- require 'bson/types/binary'
108
- require 'bson/types/code'
109
- require 'bson/types/dbref'
110
- require 'bson/types/min_max_keys'
111
- require 'bson/types/regex'
112
- require 'bson/types/object_id'
113
- require 'bson/types/timestamp'