Class: Imap::Backup::CLI::Transfer

Inherits:
Thor
  • Object
show all
Includes:
Helpers, Thor::Actions
Defined in:
lib/imap/backup/cli/transfer.rb

Overview

Implements migration and mirroring

Constant Summary collapse

ACTIONS =

The possible vaues for the action parameter

%i(migrate mirror).freeze

Instance Method Summary collapse

Methods included from Helpers

#account, included, #load_config, #requested_accounts

Constructor Details

#initialize(action, source_email, destination_email, options) ⇒ Transfer

Returns a new instance of Transfer.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/imap/backup/cli/transfer.rb', line 19

def initialize(action, source_email, destination_email, options)
  super([])
  @action = action
  @source_email = source_email
  @destination_email = destination_email
  @options = options
  @automatic_namespaces = nil
  @config_path = nil
  @destination_delimiter = nil
  @destination_prefix = nil
  @reset = nil
  @source_delimiter = nil
  @source_prefix = nil
end

Instance Method Details

#runvoid

This method returns an undefined value.

Raises:

  • (RuntimeError)

    if the indicated action is unknown, or the source and destination accounts are the same, or either of the accounts is not configured, or incompatible namespace/delimter parameters have been supplied



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/imap/backup/cli/transfer.rb', line 40

no_commands do
  def run
    raise "Unknown action '#{action}'" if !ACTIONS.include?(action)

    process_options!
    prepare_mirror if action == :mirror

    folders.each do |serializer, folder|
      case action
      when :migrate
        Migrator.new(serializer, folder, reset: reset).run
      when :mirror
        Mirror.new(serializer, folder).run
      end
    end
  end
end