Sha256: 7e18acacffe4d3d665fd9309c05daaa0c28efc5ead25c679cba81774b8b30033

Contents?: true

Size: 922 Bytes

Versions: 21

Compression:

Stored size: 922 Bytes

Contents

module Imap::Backup
  class Setup; end

  class Setup::BackupPath
    attr_reader :account
    attr_reader :config

    def initialize(account:, config:)
      @account = account
      @config = config
    end

    def run
      account.local_path = highline.ask("backup directory: ") do |q|
        q.default  = account.local_path
        q.readline = true
        q.validate = ->(path) { path_modification_validator(path) }
        q.responses[:not_valid] = "Choose a different directory "
      end
    end

    private

    def highline
      Setup.highline
    end

    def path_modification_validator(path)
      same = config.accounts.find do |a|
        a.username != account.username && a.local_path == path
      end
      if same
        Kernel.puts "The path '#{path}' is used to backup " \
                    "the account '#{same.username}'"
        false
      else
        true
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
imap-backup-10.0.0 lib/imap/backup/setup/backup_path.rb
imap-backup-9.3.2 lib/imap/backup/setup/backup_path.rb
imap-backup-9.4.0.pre1 lib/imap/backup/setup/backup_path.rb
imap-backup-9.3.1 lib/imap/backup/setup/backup_path.rb
imap-backup-9.3.0 lib/imap/backup/setup/backup_path.rb
imap-backup-9.2.0 lib/imap/backup/setup/backup_path.rb
imap-backup-9.1.1 lib/imap/backup/setup/backup_path.rb
imap-backup-9.1.0 lib/imap/backup/setup/backup_path.rb
imap-backup-9.0.2 lib/imap/backup/setup/backup_path.rb
imap-backup-9.0.1.rc1 lib/imap/backup/setup/backup_path.rb
imap-backup-9.0.0 lib/imap/backup/setup/backup_path.rb
imap-backup-9.0.0.rc1 lib/imap/backup/setup/backup_path.rb
imap-backup-8.0.2 lib/imap/backup/setup/backup_path.rb
imap-backup-8.0.1 lib/imap/backup/setup/backup_path.rb
imap-backup-8.0.0 lib/imap/backup/setup/backup_path.rb
imap-backup-8.0.0.rc1 lib/imap/backup/setup/backup_path.rb
imap-backup-7.0.2 lib/imap/backup/setup/backup_path.rb
imap-backup-7.0.0.rc1 lib/imap/backup/setup/backup_path.rb
imap-backup-6.3.0 lib/imap/backup/setup/backup_path.rb
imap-backup-6.0.1 lib/imap/backup/setup/backup_path.rb