Module: Aptible::CLI::Helpers::App
Defined Under Namespace
Modules: ClassMethods
Classes: HandleFromGitRemote
Class Method Summary
collapse
Instance Method Summary
collapse
#ensure_default_environment, #ensure_environment, #environment_from_handle, #scoped_environments
Methods included from Token
#current_token_hash, #fetch_token, #save_token, #token_file
Class Method Details
.included(base) ⇒ Object
23
24
25
|
# File 'lib/aptible/cli/helpers/app.rb', line 23
def self.included(base)
base.extend ClassMethods
end
|
Instance Method Details
#apps_from_handle(handle, environment) ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/aptible/cli/helpers/app.rb', line 63
def apps_from_handle(handle, environment)
if environment
apps = environment.apps
else
apps = Aptible::Api::App.all(token: fetch_token)
end
apps.select { |a| a.handle == handle }
end
|
#ensure_app(options = {}) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/aptible/cli/helpers/app.rb', line 35
def ensure_app(options = {})
remote = options[:remote] || ENV['APTIBLE_REMOTE'] || 'aptible'
app_handle = options[:app] || handles_from_remote(remote)[:app_handle]
environment_handle = options[:environment] ||
handles_from_remote(remote)[:environment_handle]
unless app_handle
fail Thor::Error, <<-ERR.gsub(/\s+/, ' ').strip
Could not find app in current working directory, please specify
with --app
ERR
end
environment = environment_from_handle(environment_handle)
if environment_handle && !environment
fail Thor::Error, "Could not find environment #{environment_handle}"
end
apps = apps_from_handle(app_handle, environment)
case apps.count
when 1
return apps.first
when 0
fail Thor::Error, "Could not find app #{app_handle}"
else
fail Thor::Error, 'Multiple apps exist, please specify environment'
end
end
|
#handles_from_remote(remote_name) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/aptible/cli/helpers/app.rb', line 72
def handles_from_remote(remote_name)
git = Git.open(Dir.pwd)
aptible_remote = git.remote(remote_name).url || ''
HandleFromGitRemote.parse(aptible_remote)
rescue
{}
end
|