diff --git a/ext/mdbx_ext/database.c b/ext/mdbx_ext/database.c index 35753c7..cbf1739 100644 --- a/ext/mdbx_ext/database.c +++ b/ext/mdbx_ext/database.c @@ -603,7 +603,13 @@ rmdbx_set_subdb( int argc, VALUE *argv, VALUE self ) strcpy( prev_db, db->subdb ); } - db->subdb = NIL_P( subdb ) ? NULL : StringValueCStr( subdb ); + if ( NIL_P(subdb) ) { + db->subdb = NULL; + } + else { + subdb = rb_funcall( subdb, rb_intern("to_s"), 0 ); + db->subdb = StringValueCStr( subdb ); + } rmdbx_close_dbi( db ); /* diff --git a/spec/mdbx/database_spec.rb b/spec/mdbx/database_spec.rb index 0b62512..ff1f8e7 100644 --- a/spec/mdbx/database_spec.rb +++ b/spec/mdbx/database_spec.rb @@ -224,6 +224,11 @@ RSpec.describe( MDBX::Database ) do expect( db['key'] ).to be_truthy end + it "automatically stringifies the collection argument" do + db.collection( :bucket ) + expect( db.collection ).to eq( 'bucket' ) + end + it "revert back to the previous collection when used in a block" do expect( db.collection ).to be_nil db.collection( 'bucket' ) { 'no-op' }