Class: Housekeeper::Cleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/housekeeper/cleaner.rb

Constant Summary collapse

IGNORES_FILE_NAME =
'.housekeeper_ignore'
DEFAULT_IGNORES =
['.', '..', 'archive'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path, min_age_seconds: nil) ⇒ Cleaner

Returns a new instance of Cleaner.



12
13
14
15
16
# 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

Instance Attribute Details

#archive_pathObject (readonly)

Returns the value of attribute archive_path.



5
6
7
# File 'lib/housekeeper/cleaner.rb', line 5

def archive_path
  @archive_path
end

#base_pathObject (readonly)

Returns the value of attribute base_path.



7
8
9
# File 'lib/housekeeper/cleaner.rb', line 7

def base_path
  @base_path
end

#min_age_secondsObject (readonly)

Returns the value of attribute min_age_seconds.



6
7
8
# File 'lib/housekeeper/cleaner.rb', line 6

def min_age_seconds
  @min_age_seconds
end

Instance Method Details

#archiveObject



18
19
20
21
22
23
24
25
26
# 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

#deleteObject



28
29
30
31
32
33
34
# 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