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

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/serializer/unused_name_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serializer:) ⇒ UnusedNameFinder

Returns a new instance of UnusedNameFinder.


5
6
7
# File 'lib/imap/backup/serializer/unused_name_finder.rb', line 5

def initialize(serializer:)
  @serializer = serializer
end

Instance Attribute Details

#serializerObject (readonly)

Returns the value of attribute serializer.


3
4
5
# File 'lib/imap/backup/serializer/unused_name_finder.rb', line 3

def serializer
  @serializer
end

Instance Method Details

#runObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/imap/backup/serializer/unused_name_finder.rb', line 9

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