Module: Capitate::Plugins::Prompt
- Defined in:
- lib/capitate/plugins/prompt.rb
Instance Method Summary collapse
-
#ask(label, options = {}, &block) ⇒ Object
Prompt.
-
#password(label, options = {}) ⇒ Object
Prompt for password.
Instance Method Details
#ask(label, options = {}, &block) ⇒ Object
Prompt.
Options
label-
Label
options-
Options (none yet)
11 12 13 |
# File 'lib/capitate/plugins/prompt.rb', line 11 def ask(label, = {}, &block) Capistrano::CLI.ui.ask(label, &block) end |
#password(label, options = {}) ⇒ Object
Prompt for password.
Options
label-
Label
options-
Options (see Password options)
Password options
verify-
If true, prompt twice and verify
lazy-
If true, returns a Proc. _Defaults to true_
check_hash-
If present, checks that md5 is same as password md5
max_attempts-
Number of attempts to retry. _Defaults to 3_
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/capitate/plugins/prompt.rb', line 27 def password(label, = {}) verify = [:verify] lazy = [:lazy].nil? ? true : [:lazy] check_hash = [:check_hash] max_attempts = [:max_attempts] || 3 # Lazy password_prompt = Proc.new { attempts = 0 password = nil success = true loop do password = Capistrano::CLI.password_prompt(label) attempts += 1 if verify password_verify = Capistrano::CLI.password_prompt("[VERIFY] #{label}") if password != password_verify logger.important "Passwords do not match" success = false end end if check_hash if MD5.md5(password).hexdigest != check_hash logger.important "Invalid password, try again." success = false end end break if success break if attempts >= max_attempts # Reset success success = true end raise "Invalid password, too many tries" unless success password } return password_prompt if lazy password_prompt.call end |