Module: Aptible::CLI::Helpers::Environment
- Includes:
- Token
- Included in:
- App, Database
- Defined in:
- lib/aptible/cli/helpers/environment.rb
Constant Summary
Constants included
from Token
Token::TOKEN_ENV_VAR
Instance Method Summary
collapse
Methods included from Token
#current_token_hash, #fetch_token, #save_token, #token_file
Methods included from ConfigPath
#aptible_config_path
Instance Method Details
#ensure_default_environment ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/aptible/cli/helpers/environment.rb', line 38
def ensure_default_environment
environments = Aptible::Api::Account.all(token: fetch_token)
return environments.first if environments.count == 1
raise Thor::Error, <<-ERR.gsub(/\s+/, ' ').strip
Multiple environments available, please specify with --environment
ERR
end
|
#ensure_environment(options = {}) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/aptible/cli/helpers/environment.rb', line 21
def ensure_environment(options = {})
if (handle = options[:environment])
environment = environment_from_handle(handle)
return environment if environment
raise Thor::Error, "Could not find environment #{handle}"
else
ensure_default_environment
end
end
|
#environment_from_handle(handle) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/aptible/cli/helpers/environment.rb', line 31
def environment_from_handle(handle)
return nil unless handle
Aptible::Api::Account.all(token: fetch_token).find do |a|
a.handle == handle
end
end
|
#scoped_environments(options) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/aptible/cli/helpers/environment.rb', line 9
def scoped_environments(options)
if options[:environment]
if (environment = environment_from_handle(options[:environment]))
[environment]
else
raise Thor::Error, 'Specified account does not exist'
end
else
Aptible::Api::Account.all(token: fetch_token)
end
end
|