Class: Imap::Backup::Serializer::UnusedNameFinder
- Inherits:
-
Object
- Object
- Imap::Backup::Serializer::UnusedNameFinder
- Defined in:
- lib/imap/backup/serializer/unused_name_finder.rb
Overview
Finds a name that can be used to rename a serialized folder
Instance Method Summary collapse
-
#initialize(serializer:) ⇒ UnusedNameFinder
constructor
A new instance of UnusedNameFinder.
-
#run ⇒ Serializer::Files::Path
Finds the name.
Constructor Details
#initialize(serializer:) ⇒ UnusedNameFinder
Returns a new instance of UnusedNameFinder.
11 12 13 |
# File 'lib/imap/backup/serializer/unused_name_finder.rb', line 11 def initialize(serializer:) @serializer = serializer end |
Instance Method Details
#run ⇒ Serializer::Files::Path
Finds the name
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/imap/backup/serializer/unused_name_finder.rb', line 17 def run digit = 0 files_path = nil loop do extra = digit.zero? ? "" : "-#{digit}" folder = "#{serializer.files_path.folder_name}-#{serializer.uid_validity}#{extra}" files_path = Serializer::Files::Path.new( base_path: serializer.files_path.base_path, folder_name: folder ) imap_path = "#{files_path}.imap" mbox_path = "#{files_path}.mbox" break if !File.exist?(imap_path) && !File.exist?(mbox_path) digit += 1 end files_path end |