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
Constant Summary collapse
- LOCK_PREFIX =
"ferret-"
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.
80 81 82 |
# File 'lib/ferret/store/directory.rb', line 80 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.
65 66 67 |
# File 'lib/ferret/store/directory.rb', line 65 def create_output(file_name) raise NotImplementedError end |
#delete(file) ⇒ Object
Removes an existing file in the directory.
47 48 49 |
# File 'lib/ferret/store/directory.rb', line 47 def delete(file) raise NotImplementedError end |
#each ⇒ Object
returns an array of strings, one for each file in the directory
20 21 22 |
# File 'lib/ferret/store/directory.rb', line 20 def each # :yeilds: file_name raise NotImplementedError end |
#exists?(file) ⇒ Boolean
Returns true if a file with the given name exists.
32 33 34 |
# File 'lib/ferret/store/directory.rb', line 32 def exists?(file) raise NotImplementedError end |
#file_count ⇒ Object
returns the number of files in the directory
25 26 27 28 29 |
# File 'lib/ferret/store/directory.rb', line 25 def file_count() i = 0 each {|f| i += 1} return i end |
#length(file) ⇒ Object
Returns the length of a file in the directory.
59 60 61 |
# File 'lib/ferret/store/directory.rb', line 59 def length(file) raise NotImplementedError end |
#make_lock(lock_name) ⇒ Object
Construct a Lock.
75 76 77 |
# File 'lib/ferret/store/directory.rb', line 75 def make_lock(lock_name) raise NotImplementedError end |
#modified(file) ⇒ Object
Returns the time the named file was last modified.
37 38 39 |
# File 'lib/ferret/store/directory.rb', line 37 def modified(file) raise NotImplementedError end |
#open_input(file_name) ⇒ Object
Returns a stream reading an existing file.
70 71 72 |
# File 'lib/ferret/store/directory.rb', line 70 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.
54 55 56 |
# File 'lib/ferret/store/directory.rb', line 54 def rename(from, to) raise NotImplementedError end |
#touch(file) ⇒ Object
Set the modified time of an existing file to now.
42 43 44 |
# File 'lib/ferret/store/directory.rb', line 42 def touch(file) raise NotImplementedError end |