Class: EY::CloudClient::AppEnvironment
- Inherits:
-
Object
- Object
- EY::CloudClient::AppEnvironment
- Defined in:
- lib/engineyard-cloud-client/models/app_environment.rb
Class Method Summary collapse
-
.resolve(api, constraints) ⇒ Object
Return a constrained list of app_environments given a set of constraints like:.
-
.resolve_one(api, constraints) ⇒ Object
Accepts an api object, environment name and optional account name and returns the best matching environment for the given constraints.
Instance Method Summary collapse
- #account_name ⇒ Object
- #app_name ⇒ Object
- #attributes=(attrs) ⇒ Object
-
#deploy(attrs) ⇒ Object
Trigger a deployment on the api side.
- #environment_name ⇒ Object
- #hierarchy_name ⇒ Object
-
#initialize(api, attrs) ⇒ AppEnvironment
constructor
A new instance of AppEnvironment.
- #last_deployment ⇒ Object
-
#new_deployment(attrs) ⇒ Object
Create a new, unsaved, Deployment record.
- #repository_uri ⇒ Object
- #sort_attributes ⇒ Object
Constructor Details
#initialize(api, attrs) ⇒ AppEnvironment
Returns a new instance of AppEnvironment.
58 59 60 61 62 63 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 58 def initialize(api, attrs) super raise ArgumentError, 'AppEnvironment created without app!' unless app raise ArgumentError, 'AppEnvironment created without environment!' unless environment end |
Class Method Details
.resolve(api, constraints) ⇒ Object
Return a constrained list of app_environments given a set of constraints like:
-
app_name: app name full or partial match string
-
account_name: account name full or partial match string
-
environment_name: environment name full or partial match string
-
remotes: An array of git remote URIs
18 19 20 21 22 23 24 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 18 def self.resolve(api, constraints) clean_constraints = constraints.reject { |k,v| v.nil? } params = {'constraints' => clean_constraints} response = api.get("/app_environments/resolve", params)['resolver'] matches = from_array(api, response['matches']) ResolverResult.new(api, matches, response['errors'], response['suggestions']) end |
.resolve_one(api, constraints) ⇒ Object
Accepts an api object, environment name and optional account name and returns the best matching environment for the given constraints.
This is a shortcut for resolve_environments. Raises if nothing is found or if more than one environment is found.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 31 def self.resolve_one(api, constraints) resolver = resolve(api, constraints) resolver.one_match { |match| return match } resolver.no_matches do |errors, suggestions| = nil if suggestions.any? = "Suggestions found:\n" suggestions.sourt_by{|suggest| [suggest['account_name'], suggest['app_name']] }.each do |suggest| << "\t#{suggest['account_name']}/#{suggest['app_name']}/#{suggest['env_name']}\n" end end raise ResourceNotFound.new([errors,].compact.join("\n").strip) end resolver.many_matches do |matches| = "Multiple app_environments possible, please be more specific:\n" matches.sort_by {|ae| ae.app}.each do |ae| << "\t#{ae.hierarchy_name}\n" end raise MultipleMatchesError.new() end end |
Instance Method Details
#account_name ⇒ Object
73 74 75 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 73 def account_name app.account_name end |
#app_name ⇒ Object
77 78 79 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 77 def app_name app.name end |
#attributes=(attrs) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 65 def attributes=(attrs) app_attrs = attrs.delete('app') environment_attrs = attrs.delete('environment') super set_app app_attrs if app_attrs set_environment environment_attrs if environment_attrs end |
#deploy(attrs) ⇒ Object
Trigger a deployment on the api side.
This is like hitting the deploy button on the web interface.
Returns a started deployment that will run from EY Cloud automatically. Load the deployment again to see when it finishes. This action returns immediately before the deployment is complete.
113 114 115 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 113 def deploy(attrs) Deployment.deploy(api, self, attrs) end |
#environment_name ⇒ Object
81 82 83 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 81 def environment_name environment.name end |
#hierarchy_name ⇒ Object
89 90 91 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 89 def hierarchy_name [account_name, app_name, environment_name].join(' / ') end |
#last_deployment ⇒ Object
93 94 95 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 93 def last_deployment Deployment.last(api, self) end |
#new_deployment(attrs) ⇒ Object
Create a new, unsaved, Deployment record.
Call start on the return object to indicate to EY Cloud that you will be starting a deployment using your own connection to your servers. This is the way that the engineyard gem does deployments.
102 103 104 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 102 def new_deployment(attrs) Deployment.from_hash(api, attrs.merge(:app_environment => self)) end |
#repository_uri ⇒ Object
85 86 87 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 85 def repository_uri app.repository_uri end |
#sort_attributes ⇒ Object
117 118 119 |
# File 'lib/engineyard-cloud-client/models/app_environment.rb', line 117 def sort_attributes [sort_string(account_name), sort_string(app_name), sort_string(environment_name)] end |