class Housekeeper::Cleaner
Constants
- DEFAULT_IGNORES
- IGNORES_FILE_NAME
Attributes
archive_path[R]
base_path[R]
min_age_seconds[R]
Public Class Methods
new(base_path, min_age_seconds: nil)
click to toggle source
# File lib/housekeeper/cleaner.rb, line 12 def initialize(base_path, min_age_seconds: nil) @base_path = base_path @archive_path = File.join(base_path, 'archive/') @min_age_seconds = min_age_seconds || 0 end
Public Instance Methods
archive()
click to toggle source
# File lib/housekeeper/cleaner.rb, line 18 def archive Dir.mkdir(archive_path) unless Dir.exist?(archive_path) Dir.new(base_path).each do |entry| next if skip_entry?(entry) FileUtils.mv(entry_path(entry), archive_path) end end
delete()
click to toggle source
# File lib/housekeeper/cleaner.rb, line 28 def delete Dir.new(base_path).each do |entry| next if skip_entry?(entry) FileUtils.remove_entry_secure(entry_path(entry)) end end
Private Instance Methods
entry_path(entry_name)
click to toggle source
# File lib/housekeeper/cleaner.rb, line 38 def entry_path(entry_name) File.join(base_path, entry_name) end
filed_ignores()
click to toggle source
# File lib/housekeeper/cleaner.rb, line 48 def filed_ignores ignore_file_path = File.join(base_path, IGNORES_FILE_NAME) return [] unless File.exist?(ignore_file_path) File.new(ignore_file_path).readlines end
skip_entry?(entry)
click to toggle source
# File lib/housekeeper/cleaner.rb, line 42 def skip_entry?(entry) return true if DEFAULT_IGNORES.include?(entry) return true if filed_ignores.any? { |pattern| File.fnmatch(pattern, entry) } return true if File.mtime(entry_path(entry)) > Time.now - min_age_seconds end