Module: Aptible::CLI::Helpers::App
- Includes:
- Token
- Defined in:
- lib/aptible/cli/helpers/app.rb
Instance Method Summary
collapse
Methods included from Token
#current_token_hash, #fetch_token, #save_token, #token_file
Instance Method Details
#app_from_handle(handle) ⇒ Object
19
20
21
22
23
|
# File 'lib/aptible/cli/helpers/app.rb', line 19
def app_from_handle(handle)
Aptible::Api::App.all(token: fetch_token).find do |a|
a.handle == handle
end
end
|
#default_handle ⇒ Object
33
34
35
|
# File 'lib/aptible/cli/helpers/app.rb', line 33
def default_handle
handle_from_remote(:aptible)
end
|
#ensure_app(options = {}) ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/aptible/cli/helpers/app.rb', line 10
def ensure_app(options = {})
handle = options[:app] ||
handle_from_remote(options[:remote]) ||
ensure_default_handle
app = app_from_handle(handle)
return app if app
fail Thor::Error, "Could not find app #{handle}"
end
|
#ensure_default_handle ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/aptible/cli/helpers/app.rb', line 25
def ensure_default_handle
return default_handle if default_handle
fail Thor::Error, <<-ERR.gsub(/\s+/, ' ').strip
Could not find app in current working directory, please specify
with --app
ERR
end
|
#handle_from_remote(remote_name) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/aptible/cli/helpers/app.rb', line 37
def handle_from_remote(remote_name)
git = Git.open(Dir.pwd)
aptible_remote = git.remote(remote_name).url || ''
aptible_remote[/:(?<name>.+)\.git/, :name]
rescue
nil
end
|