Class: EY::CloudClient::App
- Inherits:
-
Object
- Object
- EY::CloudClient::App
- Defined in:
- lib/engineyard-cloud-client/models/app.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#app_environments ⇒ Object
readonly
Returns the value of attribute app_environments.
Class Method Summary collapse
-
.all(api) ⇒ Object
Return list of all Apps linked to all current user’s accounts.
-
.create(api, attrs = {}) ⇒ Object
An everything-you-need helper to create an App If successful, returns new App If unsuccessful, raises
EY::CloudClient::RequestFailed
.
Instance Method Summary collapse
- #account_name ⇒ Object
- #add_app_environment(app_env) ⇒ Object
- #attributes=(attrs) ⇒ Object
- #environments ⇒ Object
- #sort_attributes ⇒ Object
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
10 11 12 |
# File 'lib/engineyard-cloud-client/models/app.rb', line 10 def account @account end |
#app_environments ⇒ Object (readonly)
Returns the value of attribute app_environments.
10 11 12 |
# File 'lib/engineyard-cloud-client/models/app.rb', line 10 def app_environments @app_environments end |
Class Method Details
.all(api) ⇒ Object
Return list of all Apps linked to all current user’s accounts
13 14 15 |
# File 'lib/engineyard-cloud-client/models/app.rb', line 13 def self.all(api) self.from_array(api, api.get("/apps", 'no_instances' => 'true')["apps"]) end |
.create(api, attrs = {}) ⇒ Object
An everything-you-need helper to create an App If successful, returns new App If unsuccessful, raises EY::CloudClient::RequestFailed
Usage App.create(api,
account: account # requires: account.id
name: "myapp",
repository_uri: "[email protected]:mycompany/myapp.git",
app_type_id: "rails3",
)
NOTE: Syntax above is for Ruby 1.9. In Ruby 1.8, keys must all be strings.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/engineyard-cloud-client/models/app.rb', line 30 def self.create(api, attrs = {}) account = attrs.delete("account") params = attrs.dup # no default fields raise EY::CloudClient::AttributeRequiredError.new("account", EY::CloudClient::Account) unless account raise EY::CloudClient::AttributeRequiredError.new("name") unless params["name"] raise EY::CloudClient::AttributeRequiredError.new("repository_uri") unless params["repository_uri"] raise EY::CloudClient::AttributeRequiredError.new("app_type_id") unless params["app_type_id"] response = api.post("/accounts/#{account.id}/apps", "app" => params) from_hash(api, response['app']) end |
Instance Method Details
#account_name ⇒ Object
41 42 43 |
# File 'lib/engineyard-cloud-client/models/app.rb', line 41 def account_name account && account.name end |
#add_app_environment(app_env) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/engineyard-cloud-client/models/app.rb', line 49 def add_app_environment(app_env) @app_environments ||= [] existing_app_env = @app_environments.detect { |ae| app_env.environment == ae.environment } unless existing_app_env @app_environments << app_env end existing_app_env || app_env end |
#attributes=(attrs) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/engineyard-cloud-client/models/app.rb', line 58 def attributes=(attrs) account_attrs = attrs.delete('account') environments_attrs = attrs.delete('environments') super set_account account_attrs if account_attrs set_environments environments_attrs if environments_attrs end |
#environments ⇒ Object
45 46 47 |
# File 'lib/engineyard-cloud-client/models/app.rb', line 45 def environments (app_environments || []).map { |app_env| app_env.environment } end |
#sort_attributes ⇒ Object
66 67 68 |
# File 'lib/engineyard-cloud-client/models/app.rb', line 66 def sort_attributes [sort_string(account_name), sort_string(name)] end |