Class | Ferret::Store::Directory
In: | ext/r_store.c
Parent: | Object

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.

### Methods

close delete exists? file_count make_lock refresh rename touch

### Constants

LOCK_PREFIX | = | rb_str_new2(LOCK_PREFIX)

### Public Instance methods

dir.close() → nil

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.

dir.delete(file_name) → nil

Remove file `file_name` from the directory. Returns true if successful.

dir.exists?(file_name) → nil

Return true if a file with the name `file_name` exists in the directory.

dir.count → integer

Return a count of the number of files in the directory.

dir.make_lock(lock_name) → self

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

dir.refresh → self

Delete all files in the directory. It gives you a clean slate.

dir.rename(from, to) → 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.

dir.touch(file_name) → nil

Create an empty file in the directory with the name `file_name`.

[Validate]