lib/picky/backends/file/basic.rb in picky-3.2.0 vs lib/picky/backends/file/basic.rb in picky-3.3.0

- old
+ new

@@ -19,41 +19,44 @@ :mapping_file # The index file's mapping file (loaded into memory for quick access). # An index cache takes a path, without file extension, # which will be provided by the subclasses. # - def initialize cache_path + def initialize cache_path, options = {} @cache_path = "#{cache_path}.file.#{extension}" # This is the mapping file with the in-memory hash for the # file position/offset mappings. # @mapping_file = Memory::JSON.new "#{cache_path}.file_mapping.#{extension}" + + @empty = options[:empty] + @initial = options[:initial] end # The default extension for index files is "index". # def extension :index end + # The empty index that is used for putting the index + # together before it is saved into the files. + # + def empty + @empty && @empty.clone || {} + end + # The initial content before loading. # # Note: We could also load the mapping file # as in #load. # def initial - nil + @initial && @initial.clone || nil end - # The empty index that is used for putting the index - # together before it is saved into the files. - # - def empty - {} - end - # Will copy the index file to a location that # is in a directory named "backup" right under # the directory the index file is in. # def backup @@ -92,9 +95,15 @@ # # A small cache is still ok. # def cache_ok? size_of(cache_path) > 0 + end + + # + # + def to_s + "#{self.class}(#{cache_path},#{mapping_file.cache_path})" end end end \ No newline at end of file