Sha256: 6ea869c742dd388dc1e81890d78fb2255571d06e2ccfcf4e652caf3889e82539

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

# encoding: utf-8

module Imap::Backup
  module Configuration; end

  class Configuration::Asker < Struct.new(:highline)
    EMAIL_MATCHER = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i

    def initialize(highline)
      super
    end

    def email(default = '')
      highline.ask('email address: ') do |q|
        q.default               = default
        q.readline              = true
        q.validate              = EMAIL_MATCHER
        q.responses[:not_valid] = 'Enter a valid email address '
      end
    end

    def password
      password     = highline.ask('password: ')        { |q| q.echo = false }
      confirmation = highline.ask('repeat password: ') { |q| q.echo = false }
      if password != confirmation
        return nil unless highline.agree("the password and confirmation did not match.\nContinue? (y/n) ")
        return self.password
      end
      password
    end

    def backup_path(default, validator)
      highline.ask('backup directory: ') do |q|
        q.default  = default
        q.readline = true
        q.validate = validator
        q.responses[:not_valid] = 'Choose a different directory '
      end
    end

    def self.email(default = '')
      new(Configuration::Setup.highline).email(default)
    end

    def self.password
      new(Configuration::Setup.highline).password
    end

    def self.backup_path(default, validator)
      new(Configuration::Setup.highline).backup_path(default, validator)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
imap-backup-1.1.0 lib/imap/backup/configuration/asker.rb
imap-backup-1.0.17 lib/imap/backup/configuration/asker.rb
imap-backup-1.0.16 lib/imap/backup/configuration/asker.rb
imap-backup-1.0.15 lib/imap/backup/configuration/asker.rb
imap-backup-1.0.14 lib/imap/backup/configuration/asker.rb
imap-backup-1.0.13 lib/imap/backup/configuration/asker.rb
imap-backup-1.0.12 lib/imap/backup/configuration/asker.rb
imap-backup-1.0.11 lib/imap/backup/configuration/asker.rb