Class: CLICredentials
- Inherits:
-
Object
- Object
- CLICredentials
- Defined in:
- lib/cli_credentials.rb,
lib/cli_credentials/version.rb
Overview
Stores credentials for a user in memory Prompts user for credentials if they aren’t already stored
Constant Summary collapse
- VERSION =
'0.0.4'
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.for(username) ⇒ Object
Semantically nicer equivalent to new.
Instance Method Summary collapse
-
#get ⇒ Object
Make sure we have all of the credentials.
-
#initialize(opts = {}) ⇒ CLICredentials
constructor
A new instance of CLICredentials.
- #password ⇒ Object
- #prompt_for_password ⇒ Object
- #prompt_for_username ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ CLICredentials
Returns a new instance of CLICredentials.
9 10 11 12 |
# File 'lib/cli_credentials.rb', line 9 def initialize(opts = {}) @username = opts[:username] if opts[:username] @title = opts[:title] if opts[:title] end |
Instance Attribute Details
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/cli_credentials.rb', line 7 def title @title end |
Class Method Details
.for(username) ⇒ Object
Semantically nicer equivalent to new
15 16 17 |
# File 'lib/cli_credentials.rb', line 15 def self.for(username) instance = self.new(username) end |
Instance Method Details
#get ⇒ Object
Make sure we have all of the credentials
20 21 22 23 24 |
# File 'lib/cli_credentials.rb', line 20 def get username password self end |
#password ⇒ Object
43 44 45 |
# File 'lib/cli_credentials.rb', line 43 def password @password ||= prompt_for_password end |
#prompt_for_password ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/cli_credentials.rb', line 31 def prompt_for_password print "#{title.to_s + ' ' if title}Password: " password = '' $stdin.noecho {|io| password = $stdin.gets.chomp} print "\n\n" password end |
#prompt_for_username ⇒ Object
26 27 28 29 |
# File 'lib/cli_credentials.rb', line 26 def prompt_for_username print "#{title.to_s + ' ' if title}Username: " gets.chomp end |
#username ⇒ Object
39 40 41 |
# File 'lib/cli_credentials.rb', line 39 def username @username ||= prompt_for_username end |