lib/picky/backend/file/basic.rb in picky-2.6.0 vs lib/picky/backend/file/basic.rb in picky-2.7.0

- old
+ new

@@ -11,23 +11,21 @@ # Not directly useable, as it does not provide # dump/load methods. # class Basic + # This file's location. + # attr_reader :cache_path # An index cache takes a path, without file extension, # which will be provided by the subclasses. # def initialize cache_path @cache_path = "#{cache_path}.#{extension}" end - def to_s - cache_path - end - # The default extension for index files is "index". # def extension :index end @@ -38,16 +36,19 @@ # def backup prepare_backup backup_directory FileUtils.cp cache_path, target, verbose: true end + # The backup directory of this file. # Equal to the file's dirname plus /backup # + def backup_directory ::File.join ::File.dirname(cache_path), 'backup' end + # Prepares the backup directory for the file. # def prepare_backup target FileUtils.mkdir target unless Dir.exists?(target) end @@ -56,10 +57,11 @@ # to the original location. # def restore FileUtils.cp backup_file_path_of(cache_path), cache_path, verbose: true end + # The backup filename. # def backup_file_path_of path dir, name = ::File.split path ::File.join dir, 'backup', name @@ -90,9 +92,15 @@ end # Extracts the size of the file in Bytes. # def size_of path `ls -l #{path} | awk '{print $5}'`.to_i + end + + # + # + def to_s + "#{self.class}(#{cache_path})" end end end \ No newline at end of file