Class: DailyWeeklyMonthly::Cleaner
- Inherits:
-
Object
- Object
- DailyWeeklyMonthly::Cleaner
- Defined in:
- lib/daily_weekly_monthly/cleaner.rb
Instance Method Summary collapse
- #call(dir, number_to_keep) ⇒ Object
-
#initialize(backups_dir, output_extension) ⇒ Cleaner
constructor
A new instance of Cleaner.
- #old_backups(dir, number_to_keep) ⇒ Object
Constructor Details
#initialize(backups_dir, output_extension) ⇒ Cleaner
Returns a new instance of Cleaner.
5 6 7 8 |
# File 'lib/daily_weekly_monthly/cleaner.rb', line 5 def initialize backups_dir, output_extension @backups_dir = backups_dir @output_extension = output_extension end |
Instance Method Details
#call(dir, number_to_keep) ⇒ Object
10 11 12 13 14 |
# File 'lib/daily_weekly_monthly/cleaner.rb', line 10 def call dir, number_to_keep old_backups(dir, number_to_keep).each do |file| FileUtils.rm file end end |
#old_backups(dir, number_to_keep) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/daily_weekly_monthly/cleaner.rb', line 16 def old_backups dir, number_to_keep Dir[File.join(@backups_dir, dir, "*.#{@output_extension}")] .sort .reverse .drop(number_to_keep) end |