GridStore.list to list gridfs files
This commit is contained in:
parent
242d0020a5
commit
73d7b5ea5d
|
@ -93,6 +93,18 @@ module XGen
|
|||
}
|
||||
end
|
||||
|
||||
# List the contains of all GridFS files stored in the given db and
|
||||
# root collection.
|
||||
#
|
||||
# :db :: the database to use
|
||||
#
|
||||
# :root_collection :: the root collection to use
|
||||
def list(db, root_collection=DEFAULT_ROOT_COLLECTION)
|
||||
db.collection("#{root_collection}.files").find().map { |f|
|
||||
f['filename']
|
||||
}
|
||||
end
|
||||
|
||||
def readlines(db, name, separator=$/)
|
||||
GridStore.open(db, name, 'r') { |gs|
|
||||
gs.readlines(separator)
|
||||
|
|
|
@ -31,6 +31,16 @@ class GridStoreTest < Test::Unit::TestCase
|
|||
assert !GridStore.exist?(@@db, 'foobar', 'another_root')
|
||||
end
|
||||
|
||||
def test_list
|
||||
assert_equal ['foobar'], GridStore.list(@@db)
|
||||
assert_equal ['foobar'], GridStore.list(@@db, 'fs')
|
||||
assert_equal [], GridStore.list(@@db, 'my_fs')
|
||||
|
||||
GridStore.open(@@db, 'test', 'w') { |f| f.write("my file") }
|
||||
|
||||
assert_equal ['foobar', 'test'], GridStore.list(@@db)
|
||||
end
|
||||
|
||||
def test_small_write
|
||||
rows = @@files.find({'filename' => 'foobar'}).to_a
|
||||
assert_not_nil rows
|
||||
|
|
Loading…
Reference in New Issue