mongo_ext 0.18.2 → 0.18.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +19 -0
  2. data/ext/cbson/cbson.c +48 -7
  3. data/ext/cbson/version.h +1 -1
  4. metadata +2 -2
data/Rakefile CHANGED
@@ -28,6 +28,7 @@ namespace :test do
28
28
  Rake::Task['test:unit'].invoke
29
29
  Rake::Task['test:functional'].invoke
30
30
  Rake::Task['test:pooled_threading'].invoke
31
+ Rake::Task['test:drop_databases'].invoke
31
32
  ENV['C_EXT'] = nil
32
33
  end
33
34
 
@@ -37,6 +38,7 @@ namespace :test do
37
38
  Rake::Task['test:unit'].invoke
38
39
  Rake::Task['test:functional'].invoke
39
40
  Rake::Task['test:pooled_threading'].invoke
41
+ Rake::Task['test:drop_databases'].invoke
40
42
  end
41
43
 
42
44
  Rake::TestTask.new(:unit) do |t|
@@ -73,6 +75,15 @@ namespace :test do
73
75
  t.test_files = FileList['test/replica/query_test.rb']
74
76
  t.verbose = true
75
77
  end
78
+
79
+ task :drop_databases do |t|
80
+ puts "Dropping test database..."
81
+ require File.join(File.dirname(__FILE__), 'lib', 'mongo')
82
+ include Mongo
83
+ con = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
84
+ ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT)
85
+ con.drop_database('ruby-mongo-test')
86
+ end
76
87
  end
77
88
 
78
89
  desc "Generate documentation"
@@ -83,6 +94,14 @@ task :rdoc do
83
94
  system "rdoc --main README.rdoc --op #{out} --inline-source --quiet README.rdoc `find lib -name '*.rb'`"
84
95
  end
85
96
 
97
+ desc "Generate YARD documentation"
98
+ task :ydoc do
99
+ version = eval(File.read("mongo-ruby-driver.gemspec")).version
100
+ out = File.join('ydoc', version.to_s)
101
+ FileUtils.rm_rf('ydoc')
102
+ system "yardoc lib/**/*.rb lib/mongo/**/*.rb -o #{out} --title MongoRuby-#{version}"
103
+ end
104
+
86
105
  desc "Publish documentation to mongo.rubyforge.org"
87
106
  task :publish => [:rdoc] do
88
107
  # Assumes docs are in ./html
@@ -60,6 +60,8 @@ static VALUE Time;
60
60
  static VALUE ObjectID;
61
61
  static VALUE DBRef;
62
62
  static VALUE Code;
63
+ static VALUE MinKey;
64
+ static VALUE MaxKey;
63
65
  static VALUE RegexpOfHolding;
64
66
  static VALUE OrderedHash;
65
67
  static VALUE InvalidName;
@@ -189,7 +191,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
189
191
  case T_FIXNUM:
190
192
  {
191
193
  if (rb_funcall(value, rb_intern(">"), 1, LL2NUM(9223372036854775807LL)) == Qtrue ||
192
- rb_funcall(value, rb_intern("<"), 1, LL2NUM(-9223372036854775808LL)) == Qtrue) {
194
+ rb_funcall(value, rb_intern("<"), 1, LL2NUM(-9223372036854775808ULL)) == Qtrue) {
193
195
  buffer_free(buffer);
194
196
  rb_raise(rb_eRangeError, "MongoDB can only handle 8-byte ints");
195
197
  }
@@ -272,7 +274,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
272
274
  case T_STRING:
273
275
  {
274
276
  if (strcmp(rb_class2name(RBASIC(value)->klass),
275
- "Mongo::Code") == 0) {
277
+ "Mongo::Code") == 0) {
276
278
  buffer_position length_location, start_position, total_length;
277
279
  int length;
278
280
  write_name_and_type(buffer, key, 0x0F);
@@ -369,13 +371,30 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
369
371
  SAFE_WRITE_AT_POS(buffer, length_location, (const char*)&obj_length, 4);
370
372
  break;
371
373
  }
374
+ if (strcmp(cls, "Mongo::MaxKey") == 0) {
375
+ write_name_and_type(buffer, key, 0x7f);
376
+ break;
377
+ }
378
+ if (strcmp(cls, "Mongo::MinKey") == 0) {
379
+ write_name_and_type(buffer, key, 0xff);
380
+ break;
381
+ }
382
+ if (strcmp(cls, "DateTime") == 0 || strcmp(cls, "Date") == 0 || strcmp(cls, "ActiveSupport::TimeWithZone") == 0) {
383
+ buffer_free(buffer);
384
+ rb_raise(InvalidDocument, "%s is not currently supported; use a UTC Time instance instead.", cls);
385
+ break;
386
+ }
387
+ if(strcmp(cls, "Complex") == 0 || strcmp(cls, "Rational") == 0 || strcmp(cls, "BigDecimal") == 0) {
388
+ buffer_free(buffer);
389
+ rb_raise(InvalidDocument, "Cannot serialize the Numeric type %s as BSON; only Bignum, Fixnum, and Float are supported.", cls);
390
+ break;
391
+ }
372
392
  buffer_free(buffer);
373
- rb_raise(InvalidDocument, "Unsupported type for BSON (%d)", TYPE(value));
393
+ rb_raise(InvalidDocument, "Cannot serialize an object of class %s into BSON.", cls);
374
394
  break;
375
395
  }
376
396
  case T_DATA:
377
397
  {
378
- // TODO again, is this really the only way to do this?
379
398
  const char* cls = rb_class2name(RBASIC(value)->klass);
380
399
  if (strcmp(cls, "Time") == 0) {
381
400
  double t = NUM2DBL(rb_funcall(value, rb_intern("to_f"), 0));
@@ -384,6 +403,14 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
384
403
  SAFE_WRITE(buffer, (const char*)&time_since_epoch, 8);
385
404
  break;
386
405
  }
406
+ if(strcmp(cls, "BigDecimal") == 0) {
407
+ buffer_free(buffer);
408
+ rb_raise(InvalidDocument, "Cannot serialize the Numeric type %s as BSON; only Bignum, Fixnum, and Float are supported.", cls);
409
+ break;
410
+ }
411
+ buffer_free(buffer);
412
+ rb_raise(InvalidDocument, "Cannot serialize an object of class %s into BSON.", cls);
413
+ break;
387
414
  }
388
415
  case T_REGEXP:
389
416
  {
@@ -423,8 +450,9 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
423
450
  }
424
451
  default:
425
452
  {
453
+ const char* cls = rb_class2name(RBASIC(value)->klass);
426
454
  buffer_free(buffer);
427
- rb_raise(InvalidDocument, "Unsupported type for BSON (%d)", TYPE(value));
455
+ rb_raise(InvalidDocument, "Cannot serialize an object of class %s (type %d) into BSON.", cls, TYPE(value));
428
456
  break;
429
457
  }
430
458
  }
@@ -478,7 +506,7 @@ static void write_doc(buffer_t buffer, VALUE hash, VALUE check_keys) {
478
506
  rb_raise(InvalidDocument, "Document too large: BSON documents are limited to 4MB.");
479
507
  return;
480
508
  }
481
- SAFE_WRITE_AT_POS(buffer, length_location, &length, 4);
509
+ SAFE_WRITE_AT_POS(buffer, length_location, (const char*)&length, 4);
482
510
  }
483
511
 
484
512
  static VALUE method_serialize(VALUE self, VALUE doc, VALUE check_keys) {
@@ -500,6 +528,11 @@ static VALUE method_serialize(VALUE self, VALUE doc, VALUE check_keys) {
500
528
  static VALUE get_value(const char* buffer, int* position, int type) {
501
529
  VALUE value;
502
530
  switch (type) {
531
+ case -1:
532
+ {
533
+ value = rb_class_new_instance(0, NULL, MinKey);
534
+ break;
535
+ }
503
536
  case 1:
504
537
  {
505
538
  double d;
@@ -721,6 +754,11 @@ static VALUE get_value(const char* buffer, int* position, int type) {
721
754
  *position += 8;
722
755
  break;
723
756
  }
757
+ case 127:
758
+ {
759
+ value = rb_class_new_instance(0, NULL, MaxKey);
760
+ break;
761
+ }
724
762
  default:
725
763
  {
726
764
  rb_raise(rb_eTypeError, "no c decoder for this type yet (%d)", type);
@@ -819,9 +857,12 @@ void Init_cbson() {
819
857
  DBRef = rb_const_get(mongo, rb_intern("DBRef"));
820
858
  rb_require("mongo/types/code");
821
859
  Code = rb_const_get(mongo, rb_intern("Code"));
860
+ rb_require("mongo/types/min_max_keys");
861
+ MinKey = rb_const_get(mongo, rb_intern("MinKey"));
862
+ MaxKey = rb_const_get(mongo, rb_intern("MaxKey"));
822
863
  rb_require("mongo/types/regexp_of_holding");
823
864
  RegexpOfHolding = rb_const_get(mongo, rb_intern("RegexpOfHolding"));
824
- rb_require("mongo/errors");
865
+ rb_require("mongo/exceptions");
825
866
  InvalidName = rb_const_get(mongo, rb_intern("InvalidName"));
826
867
  InvalidStringEncoding = rb_const_get(mongo, rb_intern("InvalidStringEncoding"));
827
868
  InvalidDocument = rb_const_get(mongo, rb_intern("InvalidDocument"));
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- #define VERSION "0.18.2"
17
+ #define VERSION "0.18.3"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.2
4
+ version: 0.18.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Dirolf
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-29 00:00:00 -05:00
12
+ date: 2010-01-25 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15