Class: Imap::Backup::Configuration::Asker
- Inherits:
-
Struct
- Object
- Struct
- Imap::Backup::Configuration::Asker
- 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
-
#highline ⇒ Object
Returns the value of attribute highline.
Class Method Summary collapse
Instance Method Summary collapse
- #backup_path(default, validator) ⇒ Object
- #email(default = "") ⇒ Object
-
#initialize(highline) ⇒ Asker
constructor
A new instance of Asker.
- #password ⇒ Object
Constructor Details
#initialize(highline) ⇒ Asker
Returns a new instance of Asker.
7 8 9 |
# File 'lib/imap/backup/configuration/asker.rb', line 7 def initialize(highline) super end |
Instance Attribute Details
#highline ⇒ Object
Returns the value of attribute highline
4 5 6 |
# File 'lib/imap/backup/configuration/asker.rb', line 4 def highline @highline end |
Class Method Details
.backup_path(default, validator) ⇒ Object
47 48 49 |
# File 'lib/imap/backup/configuration/asker.rb', line 47 def self.backup_path(default, validator) new(Configuration::Setup.highline).backup_path(default, validator) end |
.email(default = "") ⇒ Object
39 40 41 |
# File 'lib/imap/backup/configuration/asker.rb', line 39 def self.email(default = "") new(Configuration::Setup.highline).email(default) end |
.password ⇒ Object
43 44 45 |
# File 'lib/imap/backup/configuration/asker.rb', line 43 def self.password new(Configuration::Setup.highline).password end |
Instance Method Details
#backup_path(default, validator) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/imap/backup/configuration/asker.rb', line 30 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
11 12 13 14 15 16 17 18 |
# File 'lib/imap/backup/configuration/asker.rb', line 11 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
20 21 22 23 24 25 26 27 28 |
# File 'lib/imap/backup/configuration/asker.rb', line 20 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 |