Class: Shhh::App::Input::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/shhh/app/input/handler.rb

Instance Method Summary collapse

Instance Method Details

#askObject


7
8
9
10
11
12
13
14
# File 'lib/shhh/app/input/handler.rb', line 7

def ask
  retries ||= 0
  prompt('Password: ', :green)
rescue ::OpenSSL::Cipher::CipherError
  STDERR.puts 'Invalid password. Please try again.'
  retry if (retries += 1) < 3
  nil
end

#new_passwordObject


24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/shhh/app/input/handler.rb', line 24

def new_password
  password         = prompt('New Password     : ', :blue)
  password_confirm = prompt('Confirm Password : ', :blue)

  raise Shhh::Errors::PasswordsDontMatch.new(
    'The passwords you entered do not match.') if password != password_confirm

  raise Shhh::Errors::PasswordTooShort.new(
    'Minimum length is 7 characters.') if password.length < 7

  password
end

#prompt(message, color) ⇒ Object


20
21
22
# File 'lib/shhh/app/input/handler.rb', line 20

def prompt(message, color)
  HighLine.new(STDIN, STDERR).ask(message.bold) { |q| q.echo = ''.send(color) }
end

#puts(*args) ⇒ Object


16
17
18
# File 'lib/shhh/app/input/handler.rb', line 16

def puts(*args)
  STDERR.puts args
end