Skip to content

Instantly share code, notes, and snippets.

@geoffreywiseman
Created December 17, 2010 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geoffreywiseman/745599 to your computer and use it in GitHub Desktop.
Save geoffreywiseman/745599 to your computer and use it in GitHub Desktop.
An example of what a prune DSL could look like.
preprocess do |file|
file.modified_time = File.mtime( file.name )
modified_date = Date.parse modified_time.to_s
file.days_since_modified = Date.today - modified_date
file.months_since_modified = ( Date.today.year - modified_date.year ) * 12 + (Date.today.month - modified_date.month)
end
category "Ignoring directories" do
match { |file| File.directory?(file.name) }
ignore
end
category "Retaining Files from the Last Two Weeks" do
match do |file|
file.days_since_modified <= 14
end
retain
end
category "Retaining 'Friday' Files in Last Two Months" do
match { |file| file.modified_time.wday == 5 && file.months_since_modified < 2 && file.days_since_modified > 14 }
retain
end
category "Removing Non-Friday Files Older Than Two Weeks" do
match { |file| file.modified_time.wday != 5 && file.days_since_modified > 14 }
remove
end
category "Archiving Files Order than Last Two Months" do
match { |file| file.modified_time.wday == 5 && file.months_since_modified >= 2 }
archive
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment