class Polecat::IndexReader
reads an index directory
This class reads the content of an index directory and builds the necessary structures for the index type.
Attributes
path[R]
Public Class Methods
new(path)
click to toggle source
initialize a new reader
Create a new reader for the given path. If the directory is empty, you will get an empty index, else all documents stored in that directory. @param [String] path the path to the index directory
# File lib/polecat/index_reader.rb, line 14 def initialize path @path = path raise ArgumentError, 'no valid directory' unless File.directory? @path end
Public Instance Methods
locked?()
click to toggle source
checks whether the directory is locked or not
# File lib/polecat/index_reader.rb, line 39 def locked? if File.exists? @path + '/index.lock' true else false end end
read()
click to toggle source
read the content of the directory
Read all files of the directory and return an index object. @raise [IOError] raised when the directory is locked @return [Polecat::Index] the index with all documents
# File lib/polecat/index_reader.rb, line 24 def read raise IOError, 'index is locked' if locked? files = Dir[@path + '/*'] if files.count > 0 documents = [] files.each do |file| documents += Marshal.load(File.read(file)) end documents else [] end end