Class: Imap::Backup::Setup::Asker

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/setup/asker.rb

Overview

Implements interactively requesting information from the user

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(highline) ⇒ Asker

Returns a new instance of Asker.

Parameters:

  • highline (Higline)

    the configured Highline instance



9
10
11
# File 'lib/imap/backup/setup/asker.rb', line 9

def initialize(highline)
  @highline = highline
end

Class Method Details

.email(default = "") ⇒ String

Asks for a email address using the configured menu handler

Parameters:

  • default (String) (defaults to: "")

    the existing email address

Returns:

  • (String)

    the email address



45
46
47
# File 'lib/imap/backup/setup/asker.rb', line 45

def self.email(default = "")
  new(Setup.highline).email(default)
end

.passwordString

Asks for a password using the configured menu handler

Returns:

  • (String)

    the password



52
53
54
# File 'lib/imap/backup/setup/asker.rb', line 52

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

Instance Method Details

#email(default = "") ⇒ String

Asks for a email address

Parameters:

  • default (String) (defaults to: "")

    the existing email address

Returns:

  • (String)

    the email address



17
18
19
20
21
22
23
# File 'lib/imap/backup/setup/asker.rb', line 17

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

#passwordString

Asks for a password

Returns:

  • (String)

    the password



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/imap/backup/setup/asker.rb', line 28

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

    return self.password
  end
  password
end