Module: Aptible::CLI::Helpers::Account
- Includes:
- Token
- Defined in:
- lib/aptible/cli/helpers/account.rb
Instance Method Summary
collapse
Methods included from Token
#current_token_hash, #fetch_token, #save_token, #token_file
Instance Method Details
#account_from_handle(handle) ⇒ Object
32
33
34
35
36
|
# File 'lib/aptible/cli/helpers/account.rb', line 32
def account_from_handle(handle)
Aptible::Api::Account.all(token: fetch_token).find do |a|
a.handle == handle
end
end
|
#ensure_account(options = {}) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/aptible/cli/helpers/account.rb', line 22
def ensure_account(options = {})
if (handle = options[:account])
account = account_from_handle(handle)
return account if account
fail "Could not find account #{handle}"
else
ensure_default_account
end
end
|
#ensure_default_account ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/aptible/cli/helpers/account.rb', line 38
def ensure_default_account
accounts = Aptible::Api::Account.all(token: fetch_token)
return accounts.first if accounts.count == 1
fail Thor::Error, " Multiple accounts available, please specify with --account\n ERR\nend\n".gsub(/\s+/, ' ').strip
|
#scoped_accounts(options) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/aptible/cli/helpers/account.rb', line 10
def scoped_accounts(options)
if options[:account]
if (account = account_from_handle(options[:account]))
[account]
else
fail Thor::Error, 'Specified account does not exist'
end
else
Aptible::Api::Account.all(token: fetch_token)
end
end
|