Class: CLICredentials

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#titleObject (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

#getObject

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

#passwordObject



43
44
45
# File 'lib/cli_credentials.rb', line 43

def password
  @password ||= prompt_for_password
end

#prompt_for_passwordObject



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_usernameObject



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

#usernameObject



39
40
41
# File 'lib/cli_credentials.rb', line 39

def username
  @username ||= prompt_for_username
end