Module: RubyClone::BackupUtils
- Defined in:
- lib/ruby_clone/backup_utils.rb
Class Method Summary collapse
- .delete_files(path, ruby_clone_suffix, limit) ⇒ Object
- .delete_files_reached_the_limit(paths, limit) ⇒ Object
- .find_files_with_same_name(path, ruby_clone_suffix) ⇒ Object
Class Method Details
.delete_files(path, ruby_clone_suffix, limit) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/ruby_clone/backup_utils.rb', line 8 def self.delete_files(path, ruby_clone_suffix, limit) if File.exists?(path) paths = find_files_with_same_name path, ruby_clone_suffix delete_files_reached_the_limit paths, limit end end |
.delete_files_reached_the_limit(paths, limit) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_clone/backup_utils.rb', line 31 def self.delete_files_reached_the_limit(paths, limit) paths.each_value do |files| if files.size > limit files.slice(0, files.size - limit).each do |file| FileUtils.remove_entry file end end end end |
.find_files_with_same_name(path, ruby_clone_suffix) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby_clone/backup_utils.rb', line 16 def self.find_files_with_same_name(path, ruby_clone_suffix) paths = {} Find.find(path) do |path| path_without_suffix = path.sub(/#{ruby_clone_suffix}.*/, '') if FileTest.file? path paths[path_without_suffix] ||= [] paths[path_without_suffix] << path end end paths end |