Created
September 6, 2017 01:39
-
-
Save ugdark/b946a5c9b9f3b2863d7291548394af2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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