### Home Classes Methods

### In Files

- ext/r_store.c

### Parent

Object

### Methods

- #close
- #delete
- #exists?
- #file_count
- #make_lock
- #refresh
- #rename
- #touch

### Files

- MIT-LICENSE
- README
- TODO
- TUTORIAL

### Class/Module Index

Quicksearch

- Ferret
- Ferret::BlankSlate
- Ferret::BoostMixin
- Ferret::Browser
- Ferret::Browser::Controller
- Ferret::Browser::Delegator
- Ferret::Browser::DocumentController
- Ferret::Browser::ErrorController
- Ferret::Browser::HelpController
- Ferret::Browser::HomeController
- Ferret::Browser::TermController
- Ferret::Browser::TermVectorController
- Ferret::Browser::ViewHelper
- Ferret::Document
- Ferret::Field
- Ferret::FieldSymbol
- Ferret::FieldSymbolMethods
- Ferret::FileNotFoundError
- Ferret::Index
- Ferret::Index::FieldInfo
- Ferret::Index::FieldInfos
- Ferret::Index::Index
- Ferret::Index::IndexReader
- Ferret::Index::IndexWriter
- Ferret::Index::LazyDoc
- Ferret::Index::LazyDoc::LazyDocData
- Ferret::Index::TermDocEnum
- Ferret::Index::TermEnum
- Ferret::Index::TermVector
- Ferret::Index::TermVector::TVOffsets
- Ferret::Index::TermVector::TVTerm
- Ferret::ParseError
- Ferret::QueryParser
- Ferret::QueryParser::QueryParseException
- Ferret::Search
- Ferret::Search::BooleanQuery
- Ferret::Search::BooleanQuery::BooleanClause
- Ferret::Search::ConstantScoreQuery
- Ferret::Search::Explanation
- Ferret::Search::Filter
- Ferret::Search::FilteredQuery
- Ferret::Search::FuzzyQuery
- Ferret::Search::Hit
- Ferret::Search::MatchAllQuery
- Ferret::Search::MultiSearcher
- Ferret::Search::MultiTermQuery
- Ferret::Search::PhraseQuery
- Ferret::Search::PrefixQuery
- Ferret::Search::Query
- Ferret::Search::QueryFilter
- Ferret::Search::RangeFilter
- Ferret::Search::RangeQuery
- Ferret::Search::Searcher
- Ferret::Search::Sort
- Ferret::Search::SortField
- Ferret::Search::Spans
- Ferret::Search::Spans::SpanFirstQuery
- Ferret::Search::Spans::SpanMultiTermQuery
- Ferret::Search::Spans::SpanNearQuery
- Ferret::Search::Spans::SpanNotQuery
- Ferret::Search::Spans::SpanOrQuery
- Ferret::Search::Spans::SpanPrefixQuery
- Ferret::Search::Spans::SpanTermQuery
- Ferret::Search::TermQuery
- Ferret::Search::TopDocs
- Ferret::Search::TypedRangeFilter
- Ferret::Search::TypedRangeQuery
- Ferret::Search::WildcardQuery
- Ferret::StateError
- Ferret::Store
- Ferret::Store::Directory
- Ferret::Store::FSDirectory
- Ferret::Store::Lock
- Ferret::Store::Lock::LockError
- Ferret::Store::RAMDirectory
- WEBrick
- WEBrick::FerretBrowserHandler
- Date
- DateTime
- FileUtils
- Float
- Integer
- String
- Symbol
- Time

No matching classes.

# 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

close() → nil click to toggle source

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;
    }

delete(file_name) → nil click to toggle source

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;
    }

exists?(file_name) → nil click to toggle source

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;
    }

count → integer click to toggle source

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_lock(lock_name) → self click to toggle source

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;
    }

refresh → self click to toggle source

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(from, to) → self click to toggle source

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;
    }

touch(file_name) → nil click to toggle source

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;
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.