From 0e38252e45f45a9ae938837c4ad5689b3b39c4de Mon Sep 17 00:00:00 2001 From: Fedor Yudanov Date: Thu, 28 Mar 2013 14:56:22 +0700 Subject: [PATCH] #50 --- rbejdb/src/rbejdb.c | 13 ++++++++----- rbejdb/test/t1.rb | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/rbejdb/src/rbejdb.c b/rbejdb/src/rbejdb.c index 03530d1..f9275f2 100644 --- a/rbejdb/src/rbejdb.c +++ b/rbejdb/src/rbejdb.c @@ -85,11 +85,14 @@ void EJDB_dropCollection(VALUE self, VALUE collName, VALUE prune) { } } -void EJDB_ensureCollection(VALUE self, VALUE collName, VALUE copts) { +void EJDB_ensureCollection(int argc, VALUE* argv, VALUE self) { + VALUE collName, copts; + rb_scan_args(argc, argv, "11", &collName, &copts); + Check_SafeStr(collName); EJCOLLOPTS jcopts = {NULL}; - if (TYPE(copts) != T_NIL) { + if (!NIL_P(copts)) { Check_Type(copts, T_HASH); VALUE cachedrecords = rb_hash_aref(copts, rb_str_new2("cachedrecords")); @@ -97,10 +100,10 @@ void EJDB_ensureCollection(VALUE self, VALUE collName, VALUE copts) { VALUE large = rb_hash_aref(copts, rb_str_new2("large")); VALUE records = rb_hash_aref(copts, rb_str_new2("records")); - jcopts.cachedrecords = TYPE(cachedrecords) != T_NIL ? NUM2INT(cachedrecords) : 0; + jcopts.cachedrecords = !NIL_P(cachedrecords) ? NUM2INT(cachedrecords) : 0; jcopts.compressed = TYPE(compressed) == T_TRUE; jcopts.large = TYPE(large) == T_TRUE; - jcopts.records = TYPE(records) != T_NIL ? NUM2INT(records) : 0; + jcopts.records = !NIL_P(records) ? NUM2INT(records) : 0; } EJDB* ejdb = getEJDB(self); @@ -184,5 +187,5 @@ Init_rbejdb() { rb_define_method(ejdbClass, "find", RUBY_METHOD_FUNC(EJDB_find), 2); rb_define_method(ejdbClass, "dropCollection", RUBY_METHOD_FUNC(EJDB_dropCollection), 2); - rb_define_method(ejdbClass, "ensureCollection", RUBY_METHOD_FUNC(EJDB_ensureCollection), 2); + rb_define_method(ejdbClass, "ensureCollection", RUBY_METHOD_FUNC(EJDB_ensureCollection), -1); } \ No newline at end of file diff --git a/rbejdb/test/t1.rb b/rbejdb/test/t1.rb index 61814dc..072bff2 100644 --- a/rbejdb/test/t1.rb +++ b/rbejdb/test/t1.rb @@ -7,6 +7,7 @@ raise "Failed to open ejdb" unless ejdb.is_open? ejdb.dropCollection("parrots", true) +ejdb.ensureCollection("parrots") ejdb.ensureCollection("parrots", {"large" => true, "records" => 200000}) class Parrot -- 2.7.4