Class: Imap::Backup::Configuration::Asker

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

Constant Summary collapse

EMAIL_MATCHER =
/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+$/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(highline) ⇒ Asker

Returns a new instance of Asker.



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

def initialize(highline)
  super
end

Instance Attribute Details

#highline ⇒ Object

Returns the value of attribute highline

Returns:

  • (Object) —

    the current value of highline



6
7
8
# File 'lib/imap/backup/configuration/asker.rb', line 6

def highline
  @highline
end

Class Method Details

.backup_path(default, validator) ⇒ Object



49
50
51
# File 'lib/imap/backup/configuration/asker.rb', line 49

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

.email(default = '') ⇒ Object



41
42
43
# File 'lib/imap/backup/configuration/asker.rb', line 41

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

.password ⇒ Object



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

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

Instance Method Details

#backup_path(default, validator) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/imap/backup/configuration/asker.rb', line 32

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

#email(default = '') ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/imap/backup/configuration/asker.rb', line 13

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

#password ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/imap/backup/configuration/asker.rb', line 22

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