Class: CrudInspector::Files::Cleaner
- Inherits:
-
Object
- Object
- CrudInspector::Files::Cleaner
- Defined in:
- lib/crud_inspector/files/cleaner.rb
Instance Method Summary collapse
- #delete_oldest_file ⇒ Object
- #file_count ⇒ Object
- #files ⇒ Object
- #full_path(filename) ⇒ Object
-
#initialize(repo) ⇒ Cleaner
constructor
A new instance of Cleaner.
- #try_clean ⇒ Object
Constructor Details
#initialize(repo) ⇒ Cleaner
Returns a new instance of Cleaner.
6 7 8 |
# File 'lib/crud_inspector/files/cleaner.rb', line 6 def initialize(repo) @repo = repo end |
Instance Method Details
#delete_oldest_file ⇒ Object
14 15 16 |
# File 'lib/crud_inspector/files/cleaner.rb', line 14 def delete_oldest_file FileUtils.rm full_path(files.first) end |
#file_count ⇒ Object
26 27 28 |
# File 'lib/crud_inspector/files/cleaner.rb', line 26 def file_count files.count end |
#files ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/crud_inspector/files/cleaner.rb', line 18 def files @files ||= begin entries = Dir.entries(@repo).drop_while { |file| ['.','..'].include?(file) } entries = entries.sort_by { |filename| File.ctime(full_path(filename)) } entries end end |
#full_path(filename) ⇒ Object
30 31 32 |
# File 'lib/crud_inspector/files/cleaner.rb', line 30 def full_path(filename) @repo.dup + '/' + filename end |
#try_clean ⇒ Object
10 11 12 |
# File 'lib/crud_inspector/files/cleaner.rb', line 10 def try_clean delete_oldest_file if file_count > 30 end |