Class: Ferret::Store::Directory
- Inherits:
-
Object
- Object
- Ferret::Store::Directory
- Defined in:
- lib/ferret/store/directory.rb,
ext/ram_directory.c
Overview
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
-
RAM based storage
-
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.
Direct Known Subclasses
Instance Method Summary collapse
-
#close ⇒ Object
Closes the store.
-
#create_output(file_name) ⇒ Object
Creates a new, empty file in the directory with the given name.
-
#delete(file) ⇒ Object
Removes an existing file in the directory.
-
#each ⇒ Object
returns an array of strings, one for each file in the directory.
-
#exists?(file) ⇒ Boolean
Returns true if a file with the given name exists.
-
#file_count ⇒ Object
returns the number of files in the directory.
-
#length(file) ⇒ Object
Returns the length of a file in the directory.
-
#make_lock(lock_name) ⇒ Object
Construct a Lock.
-
#modified(file) ⇒ Object
Returns the time the named file was last modified.
-
#open_input(file_name) ⇒ Object
Returns a stream reading an existing file.
-
#rename(from, to) ⇒ Object
Renames an existing file in the directory.
-
#touch(file) ⇒ Object
Set the modified time of an existing file to now.
Instance Method Details
#close ⇒ Object
Closes the store.
78 79 80 |
# File 'lib/ferret/store/directory.rb', line 78 def close raise NotImplementedError end |
#create_output(file_name) ⇒ Object
Creates a new, empty file in the directory with the given name. Returns a stream writing this file.
63 64 65 |
# File 'lib/ferret/store/directory.rb', line 63 def create_output(file_name) raise NotImplementedError end |
#delete(file) ⇒ Object
Removes an existing file in the directory.
45 46 47 |
# File 'lib/ferret/store/directory.rb', line 45 def delete(file) raise NotImplementedError end |
#each ⇒ Object
returns an array of strings, one for each file in the directory
18 19 20 |
# File 'lib/ferret/store/directory.rb', line 18 def each # :yeilds: file_name raise NotImplementedError end |
#exists?(file) ⇒ Boolean
Returns true if a file with the given name exists.
30 31 32 |
# File 'lib/ferret/store/directory.rb', line 30 def exists?(file) raise NotImplementedError end |
#file_count ⇒ Object
returns the number of files in the directory
23 24 25 26 27 |
# File 'lib/ferret/store/directory.rb', line 23 def file_count() i = 0 each {|f| i += 1} return i end |
#length(file) ⇒ Object
Returns the length of a file in the directory.
57 58 59 |
# File 'lib/ferret/store/directory.rb', line 57 def length(file) raise NotImplementedError end |
#make_lock(lock_name) ⇒ Object
Construct a Lock.
73 74 75 |
# File 'lib/ferret/store/directory.rb', line 73 def make_lock(lock_name) raise NotImplementedError end |
#modified(file) ⇒ Object
Returns the time the named file was last modified.
35 36 37 |
# File 'lib/ferret/store/directory.rb', line 35 def modified(file) raise NotImplementedError end |
#open_input(file_name) ⇒ Object
Returns a stream reading an existing file.
68 69 70 |
# File 'lib/ferret/store/directory.rb', line 68 def open_input(file_name) raise NotImplementedError end |
#rename(from, to) ⇒ Object
Renames an existing file in the directory. If a file already exists with the new name, then it is replaced. This replacement should be atomic.
52 53 54 |
# File 'lib/ferret/store/directory.rb', line 52 def rename(from, to) raise NotImplementedError end |
#touch(file) ⇒ Object
Set the modified time of an existing file to now.
40 41 42 |
# File 'lib/ferret/store/directory.rb', line 40 def touch(file) raise NotImplementedError end |