Sha256: 706857c2928c2788d14563bd3f801dea5416f94155cfbe7f8bb53a6a83afdab5

Contents?: true

Size: 1 KB

Versions: 15

Compression:

Stored size: 1 KB

Contents

class Ey::Core::Client::Addon < Ey::Core::Model
  extend Ey::Core::Associations

  identity :id, type: :integer

  attribute :vars
  attribute :name
  attribute :sso_url

  has_one  :account
  has_many :addon_attachments, aliases: ["addon_attachments", "attachments"]

  alias :attachments :addon_attachments

  def resource_url
    "#{collection.url}/#{id}"
  end

  def save!
    params = {
      "addon" => {
        "name" => self.name,
        "vars" => self.vars,
        "sso_url" => self.sso_url,
      },
    }
    if new_record?
      params["url"] = self.collection.url
      merge_attributes(self.connection.create_addon(params).body["addon"])
    else # update
      params["url"] = self.resource_url
      merge_attributes(self.connection.update_addon(params).body["addon"])
    end
  end

  def destroy!
    self.connection.destroy_addon("url" => self.resource_url)
    nil
  end

  def attach!(key, app, env)
    self.attachments.create!("key" => key, "app_id" => app.id, "environment_id" => env.id)
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ey-pro-cli-0.0.17 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.16 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.15 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.14 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.13 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.12 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.11 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.10 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.9 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.8 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.7 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.6 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.5 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.4 lib/vendor/core/ey-core/models/addon.rb
ey-pro-cli-0.0.3 lib/vendor/core/ey-core/models/addon.rb