Class: Rod::Index::FlatIndex
Overview
Class implementing segmented index, i.e. an index which allows for lazy loading of its pieces.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroys the index (removes it from the disk completely).
- #each ⇒ Object
-
#initialize(path, klass, options = {}) ⇒ FlatIndex
constructor
Creats the index with given
pathfor givenklass. -
#save ⇒ Object
Stores the index on disk.
Methods inherited from Base
#[], #copy, create, #key_persisted, #to_s
Methods included from Utils
#remove_file, #remove_files, #remove_files_but, #report_progress
Constructor Details
#initialize(path, klass, options = {}) ⇒ FlatIndex
Creats the index with given path for given klass. Options are not used in the case of FlatIndex.
11 12 13 14 15 |
# File 'lib/rod/index/flat_index.rb', line 11 def initialize(path,klass,={}) super(klass) @path = path + ".idx" @index = nil end |
Instance Method Details
#destroy ⇒ Object
Destroys the index (removes it from the disk completely).
35 36 37 |
# File 'lib/rod/index/flat_index.rb', line 35 def destroy remove_file(@path) end |
#each ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rod/index/flat_index.rb', line 39 def each load_index unless loaded? if block_given? @index.each_key do |key| yield key, self[key] end else enum_for(:each) end end |
#save ⇒ Object
Stores the index on disk.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rod/index/flat_index.rb', line 18 def save # The index was not loaded nor modified. return if @index.nil? File.open(@path,"w") do |out| proxy_index = {} #load_index unless loaded? @index.each_key do |key| col = self[key] col.save proxy_index[key] = [col.offset,col.size] end out.puts(Marshal.dump(proxy_index)) @index = nil end end |