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



17
18
19
20
21
# File 'lib/aptible/cli/helpers/app.rb', line 17

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

#default_handleObject



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

def default_handle
  git = Git.open(Dir.pwd)
  aptible_remote = git.remote(:aptible).url || ''
  aptible_remote[/:(?<name>.+)\.git/, :name]
rescue
  nil
end

#ensure_app(options = {}) ⇒ Object



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

def ensure_app(options = {})
  handle = options[:app] || ensure_default_handle
  app = app_from_handle(handle)
  return app if app
  fail Thor::Error, "Could not find app #{handle}"
end

#ensure_default_handleObject



23
24
25
26
27
28
29
# File 'lib/aptible/cli/helpers/app.rb', line 23

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