Class: Fue::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/fue/auth.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



5
6
7
# File 'lib/fue/auth.rb', line 5

def self.instance
  @instance ||= new
end

Instance Method Details

#tokenObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/fue/auth.rb', line 9

def token
  stored_options = { username: username, server: 'github.com', label: 'fue' }
  stored_token = Fue::Security.get(stored_options)
  unless stored_token
    stored_token = github_token
    Fue::Security.store!(stored_options.merge(password: stored_token))
    puts 'Token saved to keychain.'
  end
  stored_token
end

#usernameObject



20
21
22
23
24
25
26
# File 'lib/fue/auth.rb', line 20

def username
  @username ||= begin
    username = get_git_username&.chomp
    username = get_username if username.nil? || username.empty?
    username
  end
end