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.freeze
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
50 51 52 |
# File 'lib/imap/backup/configuration/asker.rb', line 50 def self.backup_path(default, validator) new(Configuration::Setup.highline).backup_path(default, validator) end |
.email(default = "") ⇒ Object
42 43 44 |
# File 'lib/imap/backup/configuration/asker.rb', line 42 def self.email(default = "") new(Configuration::Setup.highline).email(default) end |
.password ⇒ Object
46 47 48 |
# File 'lib/imap/backup/configuration/asker.rb', line 46 def self.password new(Configuration::Setup.highline).password end |
Instance Method Details
#backup_path(default, validator) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/imap/backup/configuration/asker.rb', line 33 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 29 30 31 |
# 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 if !highline.agree( "the password and confirmation did not match.\nContinue? (y/n) " ) return self.password end password end |