Module: UsernamePassword
- Defined in:
- lib/username_password.rb,
lib/username_password/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
- @@input_io =
$stdin
- @@output_io =
$stderr
- @@auth_file =
nil
Class Method Summary collapse
-
.auth_file=(path) ⇒ Object
Set the location of a file to save the username/password (encrypted) so the user won’t have to type it in every time.
-
.get ⇒ Object
Asks the user for a username/password.
-
.input=(io) ⇒ Object
Set the IO object to use for input.
-
.output=(io) ⇒ Object
Set the IO object to use for output.
Class Method Details
.auth_file=(path) ⇒ Object
Set the location of a file to save the username/password (encrypted) so the user won’t have to type it in every time
22 23 24 |
# File 'lib/username_password.rb', line 22 def self.auth_file=(path) @@auth_file = path end |
.get ⇒ Object
Asks the user for a username/password. If an auth_file has been specified the results will be saved to that file and the user will not have to type the information in again.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/username_password.rb', line 29 def self.get return read_file if @@auth_file && File.exists?(@@auth_file) highline = HighLine.new(@@input_io, @@output_io) username = highline.ask("Username: ") password = highline.ask("Password: ") { |q| q.echo = false } result = {:username => username.to_s, :password => password.to_s} save_file(result) if @@auth_file result end |
.input=(io) ⇒ Object
Set the IO object to use for input
11 12 13 |
# File 'lib/username_password.rb', line 11 def self.input=(io) @@input_io = io end |
.output=(io) ⇒ Object
Set the IO object to use for output
16 17 18 |
# File 'lib/username_password.rb', line 16 def self.output=(io) @@output_io = io end |