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



20
21
22
23
24
# File 'lib/aptible/cli/helpers/app.rb', line 20

def app_from_handle(handle)
  Aptible::Api::App.all(token: fetch_token).find do |a|
    a.handle == handle
  end
end

#default_handle ⇒ Object



34
35
36
# File 'lib/aptible/cli/helpers/app.rb', line 34

def default_handle
  handle_from_remote(:aptible)
end

#ensure_app(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/aptible/cli/helpers/app.rb', line 10

def ensure_app(options = {})
  remote = options[:remote] || ENV['APTIBLE_REMOTE']
  handle = options[:app] ||
           handle_from_remote(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



26
27
28
29
30
31
32
# File 'lib/aptible/cli/helpers/app.rb', line 26

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



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

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