class Ferret::Store::Directory
A Directory is an object which is used to access the index storage. Ruby's IO API is not used so that we can use different storage mechanisms to store the index. Some examples are;
-
File system based storage (currently implemented as FSDirectory)
-
RAM based storage (currently implemented as RAMDirectory)
-
Database based storage
NOTE: Once a file has been written and closed, it can no longer be modified. To make any changes to the file it must be deleted and rewritten. For this reason, the method to open a file for writing is called create_output, while the method to open a file for reading is called open_input If there is a risk of simultaneous modifications of the files then locks should be used. See Lock to find out how.
Constants
- LOCK_PREFIX
Public Instance Methods
It is a good idea to close a directory when you have finished using it. Although the garbage collector will currently handle this for you, this behaviour may change in future.
static VALUE frb_dir_close(VALUE self) { Store *store = DATA_PTR(self); int ref_cnt = FIX2INT(rb_ivar_get(self, id_ref_cnt)) - 1; rb_ivar_set(self, id_ref_cnt, INT2FIX(ref_cnt)); if (ref_cnt < 0) { Frt_Unwrap_Struct(self); object_del(store); frb_unwrap_locks(store); store_deref(store); } return Qnil; }
Remove file file_name
from the directory. Returns true if
successful.
static VALUE frb_dir_delete(VALUE self, VALUE rfname) { Store *store = DATA_PTR(self); StringValue(rfname); return (store->remove(store, rs2s(rfname)) == 0) ? Qtrue : Qfalse; }
Return true if a file with the name file_name
exists in the
directory.
static VALUE frb_dir_exists(VALUE self, VALUE rfname) { Store *store = DATA_PTR(self); StringValue(rfname); return store->exists(store, rs2s(rfname)) ? Qtrue : Qfalse; }
Return a count of the number of files in the directory.
static VALUE frb_dir_file_count(VALUE self) { Store *store = DATA_PTR(self); return INT2FIX(store->count(store)); }
Make a lock with the name lock_name
. Note that lockfiles will
be stored in the directory with other files but they won't be visible
to you. You should avoid using files with a .lck extension as this
extension is reserved for lock files
static VALUE frb_dir_make_lock(VALUE self, VALUE rlock_name) { VALUE rlock; Lock *lock; Store *store = DATA_PTR(self); StringValue(rlock_name); lock = open_lock(store, rs2s(rlock_name)); rlock = Data_Wrap_Struct(cLock, &frb_lock_mark, &frb_lock_free, lock); object_add(lock, rlock); return rlock; }
Delete all files in the directory. It gives you a clean slate.
static VALUE frb_dir_refresh(VALUE self) { Store *store = DATA_PTR(self); store->clear_all(store); return self; }
Rename a file from from
to to
. An error will be
raised if the file doesn't exist or there is some other type of
IOError.
static VALUE frb_dir_rename(VALUE self, VALUE rfrom, VALUE rto) { Store *store = DATA_PTR(self); StringValue(rfrom); StringValue(rto); store->rename(store, rs2s(rfrom), rs2s(rto)); return self; }
Create an empty file in the directory with the name file_name
.
static VALUE frb_dir_touch(VALUE self, VALUE rfname) { Store *store = DATA_PTR(self); StringValue(rfname); store->touch(store, rs2s(rfname)); return Qnil; }