Class: Gista::LoginPrompt

Inherits:
Object
  • Object
show all
Defined in:
lib/gista/login_prompt.rb

Overview

Create an object that responds to username and password messages by prompting the user on the command line. Helpful when creating a command-line client. When using as a library, simply substitute with a Struct or something similar.

Examples:

Asking the user for username and password

lp = LoginPrompt.new
lp.username
# ... prompt for username and password...
# => "username"
lp.password
# => "password"

Instance Method Summary collapse

Constructor Details

#initializeLoginPrompt

Returns a new instance of LoginPrompt.



16
17
18
19
# File 'lib/gista/login_prompt.rb', line 16

def initialize
  @username = nil
  @password = nil
end

Instance Method Details

#passwordString

Return the password if set, or prompt the user to enter both his username and password.

Returns:

  • (String)


34
35
36
37
# File 'lib/gista/login_prompt.rb', line 34

def password
  prompt unless @password
  @password
end

#usernameString

Return the username if set, or prompt the user to enter both his username and password.

Returns:

  • (String)


25
26
27
28
# File 'lib/gista/login_prompt.rb', line 25

def username
  prompt unless @username
  @username
end