Class: Faf::Auth

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



3
4
5
# File 'lib/faf/auth.rb', line 3

def self.instance
  @instance ||= new
end

Instance Method Details

#tokenObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/faf/auth.rb', line 7

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

#usernameObject



18
19
20
21
22
23
24
25
# File 'lib/faf/auth.rb', line 18

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