Class: Imap::Backup::Serializer::UnusedNameFinder

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(serializer:) ⇒ UnusedNameFinder

Returns a new instance of UnusedNameFinder.

Parameters:



11
12
13
# File 'lib/imap/backup/serializer/unused_name_finder.rb', line 11

def initialize(serializer:)
  @serializer = serializer
end

Instance Method Details

#runString

Finds the name

Returns:

  • (String)

    the name



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/imap/backup/serializer/unused_name_finder.rb', line 17

def run
  digit = 0
  folder = nil

  loop do
    extra = digit.zero? ? "" : "-#{digit}"
    folder = "#{serializer.folder}-#{serializer.uid_validity}#{extra}"
    test = Serializer.new(serializer.path, folder)
    break if !test.validate!

    digit += 1
  end

  folder
end