Class: TrelloFs::AttachmentCleaner
- Inherits:
-
Object
- Object
- TrelloFs::AttachmentCleaner
- Defined in:
- lib/trello-fs/attachment_cleaner.rb
Instance Method Summary collapse
-
#initialize(repository) ⇒ AttachmentCleaner
constructor
A new instance of AttachmentCleaner.
- #remove_old_attachments ⇒ Object
- #set_of_attachment_paths ⇒ Object
Constructor Details
#initialize(repository) ⇒ AttachmentCleaner
Returns a new instance of AttachmentCleaner.
6 7 8 |
# File 'lib/trello-fs/attachment_cleaner.rb', line 6 def initialize(repository) @repository = repository end |
Instance Method Details
#remove_old_attachments ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/trello-fs/attachment_cleaner.rb', line 16 def = Dir. glob(File.join(@repository.path, "Attachments/**/*")). reject {|fn| File.directory?(fn) }. each do |file| next if .include? file FileUtils.rm(file) # remove parent dir if empty dirname = File.dirname(file) FileUtils.rm_rf(dirname) if Dir[File.join(dirname, '*')].empty? end end |
#set_of_attachment_paths ⇒ Object
10 11 12 13 14 |
# File 'lib/trello-fs/attachment_cleaner.rb', line 10 def @repository..map do || AttachmentBuilder.(@repository, ).path end.to_set end |