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 (handle)
  Aptible::Api::.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 (options = {})
  if (handle = options[:account])
     = (handle)
    return  if 
    fail "Could not find account #{handle}"
  else
    
  end
end

#ensure_default_account ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/aptible/cli/helpers/account.rb', line 38

def 
  accounts = Aptible::Api::.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 ( = (options[:account]))
      []
    else
      fail Thor::Error, 'Specified account does not exist'
    end
  else
    Aptible::Api::.all(token: fetch_token)
  end
end