minor: version checking for cbson

This commit is contained in:
Kyle Banker 2009-12-02 11:53:59 -05:00
parent 02ed79d19b
commit d39169530a
4 changed files with 27 additions and 5 deletions

View File

@ -36,6 +36,8 @@
#include "regex.h"
#endif
#include "version.h"
#include <assert.h>
#include <math.h>
#include <unistd.h>
@ -792,7 +794,7 @@ static VALUE objectid_generate(VALUE self)
void Init_cbson() {
VALUE mongo, CBson, Digest;
VALUE mongo, CBson, Digest, ext_version;
Time = rb_const_get(rb_cObject, rb_intern("Time"));
mongo = rb_const_get(rb_cObject, rb_intern("Mongo"));
@ -812,6 +814,8 @@ void Init_cbson() {
OrderedHash = rb_const_get(rb_cObject, rb_intern("OrderedHash"));
CBson = rb_define_module("CBson");
ext_version = rb_str_new2(VERSION);
rb_define_const(CBson, "VERSION", ext_version);
rb_define_module_function(CBson, "serialize", method_serialize, 2);
rb_define_module_function(CBson, "deserialize", method_deserialize, 1);

17
ext/cbson/version.h Normal file
View File

@ -0,0 +1,17 @@
/*
* Copyright 2009 10gen, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define VERSION "0.18\0"

View File

@ -10,8 +10,8 @@ end
begin
# Need this for running test with and without c ext in Ruby 1.9.
raise LoadError if ENV['TEST_MODE'] && !ENV['C_EXT']
gem 'mongo_ext', "= #{Mongo::VERSION}"
require 'mongo_ext/cbson'
raise LoadError if CBson::VERSION != Mongo::VERSION
require 'mongo/util/bson_c'
BSON = BSON_C
BSON_SERIALIZER = CBson

View File

@ -1,11 +1,12 @@
require 'lib/mongo'
VERSION_HEADER = File.open(File.join(File.dirname(__FILE__), 'ext', 'cbson', 'version.h'), "r")
VERSION = VERSION_HEADER.read.scan(/VERSION\s+"(\d+\.\d+)\\/)[0][0]
Gem::Specification.new do |s|
s.name = 'mongo_ext'
s.version = Mongo::VERSION
s.version = VERSION
s.platform = Gem::Platform::RUBY
s.summary = 'C extensions for the MongoDB Ruby driver'
s.summary = 'C extensions for the MongoDB Ruby driver'
s.description = 'C extensions to accelerate the MongoDB Ruby driver. For more information about Mongo, see http://www.mongodb.org.'
s.require_paths = ['ext']