Module: Aptible::CLI::Helpers::App
- Includes:
- Environment, Token
- Defined in:
- lib/aptible/cli/helpers/app.rb
Defined Under Namespace
Modules: ClassMethods Classes: GitRemoteHandleStrategy, HandleFromGitRemote, OptionsHandleStrategy
Constant Summary
Constants included from Token
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Environment
#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
19 20 21 |
# File 'lib/aptible/cli/helpers/app.rb', line 19 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#apps_from_handle(handle, environment) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/aptible/cli/helpers/app.rb', line 131 def apps_from_handle(handle, environment) if environment environment.apps else Aptible::Api::App.all(token: fetch_token) end.select { |a| a.handle == handle } end |
#ensure_app(options = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/aptible/cli/helpers/app.rb', line 90 def ensure_app( = {}) s = handle_strategies.map { |cls| cls.new() }.find(&:usable?) if s.nil? err = 'Could not find app in current working directory, please ' \ 'specify with --app' fail Thor::Error, err end environment = nil if s.env_handle environment = environment_from_handle(s.env_handle) if environment.nil? err_bits = ['Could not find environment', s.env_handle] err_bits << s.explain fail Thor::Error, err_bits.join(' ') end end apps = apps_from_handle(s.app_handle, environment) case apps.count when 1 return apps.first when 0 err_bits = ['Could not find app', s.app_handle] if environment err_bits << 'in environment' err_bits << environment.handle else err_bits << 'in any environment' end err_bits << s.explain fail Thor::Error, err_bits.join(' ') else err = "Multiple apps named #{s.app_handle} exist, please specify " \ 'with --environment' fail Thor::Error, err end end |