Class: Wlt::CredsManager
- Inherits:
-
Object
- Object
- Wlt::CredsManager
- Defined in:
- lib/wlt/creds_manager.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(username = nil, password = nil) ⇒ CredsManager
constructor
A new instance of CredsManager.
- #load ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(username = nil, password = nil) ⇒ CredsManager
Returns a new instance of CredsManager.
8 9 10 11 |
# File 'lib/wlt/creds_manager.rb', line 8 def initialize(username=nil, password=nil) @username = username @password = password end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/wlt/creds_manager.rb', line 6 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
6 7 8 |
# File 'lib/wlt/creds_manager.rb', line 6 def username @username end |
Instance Method Details
#load ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/wlt/creds_manager.rb', line 24 def load File.open(File.join(Dir.home, '.wlt', 'credentials')) do |file| file.each_line do |line| username = line.match(/WATSON_USERNAME=(.*)/) @username = username[1] if username password = line.match(/WATSON_PASSWORD=(.*)/) @password = password[1] if password end end end |
#save ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/wlt/creds_manager.rb', line 13 def save validate wlt_dir = File.join(Dir.home, '.wlt') FileUtils.mkdir_p(wlt_dir) File.open(File.join(wlt_dir, 'credentials'), 'w+') do |file| file.write("WATSON_USERNAME=#{@username}\n") file.write("WATSON_PASSWORD=#{@password}\n") end end |