lib/picky/backends/memory/basic.rb in picky-4.26.2 vs lib/picky/backends/memory/basic.rb in picky-4.27.0

- old
+ new

@@ -16,16 +16,21 @@ include Helpers::File # This file's location. # attr_reader :cache_path + + # What hash type to use. Default: ::Hash + # + attr_reader :hash_type # An index cache takes a path, without file extension, # which will be provided by the subclasses. # - def initialize cache_path, options = {} + def initialize cache_path, hash_type = Hash, options = {} @cache_path = "#{cache_path}.memory.#{extension}" + @hash_type = hash_type @empty = options[:empty] @initial = options[:initial] end # The default extension for index files is "index". @@ -36,11 +41,11 @@ # The empty index that is used for putting the index # together before it is dumped into the files. # def empty - @empty && @empty.clone || empty_hash + @empty && @empty.clone || hash_type.new end def empty_hash # TODO Make this an explicit option. if defined? GoogleHashSparseRubyToRuby @@ -48,13 +53,13 @@ else {} end end - # The initial content before loading from file. + # The initial content before loading from file/indexing. # def initial - @initial && @initial.clone || {} + @initial && @initial.clone || hash_type.new end # Deletes the file. # def delete \ No newline at end of file