Class: Sym::App::Input::Handler
Instance Attribute Summary collapse
-
#kernel ⇒ Object
Returns the value of attribute kernel.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdin ⇒ Object
Returns the value of attribute stdin.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Instance Method Summary collapse
- #ask ⇒ Object
- #highline(message, color) ⇒ Object
-
#initialize(stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = nil) ⇒ Handler
constructor
A new instance of Handler.
- #new_password ⇒ Object
- #prompt(message, color) ⇒ Object
- #puts(*args) ⇒ Object
Constructor Details
#initialize(stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = nil) ⇒ Handler
Returns a new instance of Handler.
9 10 11 12 13 14 |
# File 'lib/sym/app/input/handler.rb', line 9 def initialize(stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = nil) self.stdin = stdin self.stdout = stdout self.stderr = stderr self.kernel = kernel end |
Instance Attribute Details
#kernel ⇒ Object
Returns the value of attribute kernel.
7 8 9 |
# File 'lib/sym/app/input/handler.rb', line 7 def kernel @kernel end |
#stderr ⇒ Object
Returns the value of attribute stderr.
7 8 9 |
# File 'lib/sym/app/input/handler.rb', line 7 def stderr @stderr end |
#stdin ⇒ Object
Returns the value of attribute stdin.
7 8 9 |
# File 'lib/sym/app/input/handler.rb', line 7 def stdin @stdin end |
#stdout ⇒ Object
Returns the value of attribute stdout.
7 8 9 |
# File 'lib/sym/app/input/handler.rb', line 7 def stdout @stdout end |
Instance Method Details
#ask ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/sym/app/input/handler.rb', line 16 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 |
#highline(message, color) ⇒ Object
36 37 38 |
# File 'lib/sym/app/input/handler.rb', line 36 def highline(, color) HighLine.new(stdin, stderr).ask(.bold) { |q| q.echo = '•'.send(color) } end |
#new_password ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sym/app/input/handler.rb', line 40 def new_password password = prompt('New Password : ', :blue) raise Sym::Errors::PasswordTooShort.new( 'Minimum length is 7 characters.') if password.length < 7 password_confirm = prompt('Confirm Password : ', :blue) raise Sym::Errors::PasswordsDontMatch.new( 'The passwords you entered do not match.') if password != password_confirm password end |
#prompt(message, color) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/sym/app/input/handler.rb', line 29 def prompt(, color) unless $stdin.isatty && $stdin.tty? raise Sym::Errors::CantReadPasswordNoTTY.new('key requires a password, however STDIN is not a TTY') end highline(, color) end |
#puts(*args) ⇒ Object
25 26 27 |
# File 'lib/sym/app/input/handler.rb', line 25 def puts(*args) stderr.puts args end |