Class: Wlt::CredsManager

Inherits:
Object
  • Object
show all
Defined in:
lib/wlt/creds_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/wlt/creds_manager.rb', line 6

def password
  @password
end

#usernameObject

Returns the value of attribute username.



6
7
8
# File 'lib/wlt/creds_manager.rb', line 6

def username
  @username
end

Instance Method Details

#loadObject



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

#saveObject



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