From 3b30cde0fbe674b106cd83e052e0f38caefe853b Mon Sep 17 00:00:00 2001 From: Matt Powell Date: Thu, 14 Jan 2010 15:58:42 +1300 Subject: [PATCH] GridStore#mv --- lib/mongo/gridfs/grid_store.rb | 6 +++++- test/test_grid_store.rb | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/mongo/gridfs/grid_store.rb b/lib/mongo/gridfs/grid_store.rb index 5501d93..a01d1a7 100644 --- a/lib/mongo/gridfs/grid_store.rb +++ b/lib/mongo/gridfs/grid_store.rb @@ -118,7 +118,7 @@ module GridFS gs.readlines(separator) } end - + def unlink(db, *names) names.each { |name| gs = GridStore.new(db, name) @@ -128,6 +128,10 @@ module GridFS end alias_method :delete, :unlink + def mv(db, src, dest, root_collection=DEFAULT_ROOT_COLLECTION) + db.collection("#{root_collection}.files").update({ :filename => src }, { '$set' => { :filename => dest } }) + end + end #--- diff --git a/test/test_grid_store.rb b/test/test_grid_store.rb index 6e85632..5e60ddf 100644 --- a/test/test_grid_store.rb +++ b/test/test_grid_store.rb @@ -151,6 +151,16 @@ class GridStoreTest < Test::Unit::TestCase assert_equal 0, @@files.count assert_equal 0, @@chunks.count end + + def test_mv + assert_equal 1, @@files.count + assert_equal 1, @@chunks.count + GridStore.mv(@@db, 'foobar', 'bazqux') + assert_equal 1, @@files.count + assert_equal 1, @@chunks.count + assert !GridStore.exist?(@@db, 'foobar') + assert GridStore.exist?(@@db, 'bazqux') + end def test_append GridStore.open(@@db, 'foobar', 'w+') { |f| f.write(" how are you?") }