Class: NauktisUtils::Duplicate::HandlingStrategy::NoDeleteIn
- Inherits:
-
BaseHandlingStrategy
- Object
- BaseHandlingStrategy
- NauktisUtils::Duplicate::HandlingStrategy::NoDeleteIn
- Defined in:
- lib/nauktis_utils/duplicate.rb
Instance Attribute Summary
Attributes inherited from BaseHandlingStrategy
Instance Method Summary collapse
- #handle(files) ⇒ Object
-
#initialize(deleting_strategy, directories) ⇒ NoDeleteIn
constructor
A new instance of NoDeleteIn.
Constructor Details
permalink #initialize(deleting_strategy, directories) ⇒ NoDeleteIn
Returns a new instance of NoDeleteIn.
61 62 63 64 |
# File 'lib/nauktis_utils/duplicate.rb', line 61 def initialize(deleting_strategy, directories) super(deleting_strategy) @directories = directories.map { |d| File.(d) } end |
Instance Method Details
permalink #handle(files) ⇒ Object
[View source]
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/nauktis_utils/duplicate.rb', line 66 def handle(files) files = files.sort files_kept, files_deleted = files.partition do |e| @directories.any? {|d| e.start_with?(d) } end if files_kept.size > 0 files_deleted.each do |duplicate| @deleting_strategy.delete_duplicate(duplicate, files_kept.first) end end end |