Class: Imap::Backup::Migrator
- Inherits:
-
Object
- Object
- Imap::Backup::Migrator
- Defined in:
- lib/imap/backup/migrator.rb
Overview
Copies a folder of backed-up emails to an online folder
Instance Method Summary collapse
-
#initialize(serializer, folder, reset: false) ⇒ Migrator
constructor
A new instance of Migrator.
-
#run ⇒ void
Runs the migration.
Constructor Details
#initialize(serializer, folder, reset: false) ⇒ Migrator
Returns a new instance of Migrator.
8 9 10 11 12 |
# File 'lib/imap/backup/migrator.rb', line 8 def initialize(serializer, folder, reset: false) @folder = folder @reset = reset @serializer = serializer end |
Instance Method Details
#run ⇒ void
This method returns an undefined value.
Runs the migration
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/imap/backup/migrator.rb', line 16 def run count = serializer.uids.count folder.create folder.clear if reset Logger.logger.debug "[#{folder.name}] #{count} to migrate" serializer.(serializer.uids).with_index do |, i| next if .nil? log_prefix = "[#{folder.name}] uid: #{.uid} (#{i + 1}/#{count}) -" Logger.logger.debug( "#{log_prefix} #{.body.size} bytes" ) begin folder.append() rescue StandardError => e Logger.logger.warn "#{log_prefix} append error: #{e}" end end end |