Skip to content

Instantly share code, notes, and snippets.

@ugdark
Created September 6, 2017 01:39
Show Gist options
  • Save ugdark/b946a5c9b9f3b2863d7291548394af2d to your computer and use it in GitHub Desktop.
Save ugdark/b946a5c9b9f3b2863d7291548394af2d to your computer and use it in GitHub Desktop.
def rotation(file_path, max_history)
if max_history.nil?
return
end
allow_filenames = 1.upto(max_history).to_a.map { |i|
date = Date.today.prev_day(i)
"#{file_path}.#{date.strftime('%Y%m%d')}"
}
allow_filenames.unshift(file_path)
Dir.glob("#{File.dirname(file_path)}/*").each do |target_file_path|
unless allow_filenames.include?(target_file_path)
File.delete(target_file_path)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment