From d39169530a5981cc0cba1baae6bc49feedb344d2 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Wed, 2 Dec 2009 11:53:59 -0500 Subject: [PATCH] minor: version checking for cbson --- ext/cbson/cbson.c | 6 +++++- ext/cbson/version.h | 17 +++++++++++++++++ lib/mongo.rb | 2 +- mongo-extensions.gemspec | 7 ++++--- 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 ext/cbson/version.h diff --git a/ext/cbson/cbson.c b/ext/cbson/cbson.c index 339b123..b4240b3 100644 --- a/ext/cbson/cbson.c +++ b/ext/cbson/cbson.c @@ -36,6 +36,8 @@ #include "regex.h" #endif +#include "version.h" + #include #include #include @@ -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); diff --git a/ext/cbson/version.h b/ext/cbson/version.h new file mode 100644 index 0000000..1fda318 --- /dev/null +++ b/ext/cbson/version.h @@ -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" diff --git a/lib/mongo.rb b/lib/mongo.rb index 3ec1109..fa19637 100644 --- a/lib/mongo.rb +++ b/lib/mongo.rb @@ -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 diff --git a/mongo-extensions.gemspec b/mongo-extensions.gemspec index 63f9d22..83c06a9 100644 --- a/mongo-extensions.gemspec +++ b/mongo-extensions.gemspec @@ -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']