class Atlas::BoxVersion

Representation and handling of Box Version objects.

@attr_accessor [String] version The version number. @attr_accessor [String] description Markdown test used as a full-length and

in-depth description of the version.

@attr_accessor [String] status The status of the version

(unreleased/releases) (cannot be set directly)

@attr_accessor [Array] providers The providers associated with this version.

Attributes

description[RW]

Properties of the version.

providers[RW]

Properties of the version.

status[RW]

Properties of the version.

version[RW]

Properties of the version.

Public Class Methods

create(box_tag, attr = {}) click to toggle source

Create a new version.

@param [String] box_tag the box tag to create the version under. @param [Hash] attr attributes to create the version with. @param attr [String] :version The version number. @param attr [String] :description Description of the box.

@return [Version] a newly created version.

# File lib/atlas/box_version.rb, line 37
def self.create(box_tag, attr = {})
  tag = "#{box_tag}/#{attr[:version]}"
  version = new(tag, attr)
  version.save
  version
end
find(tag) click to toggle source

Find a version by it's tag.

@param [String] tag the tag of the version.

@return [Version] a representation of the version.

# File lib/atlas/box_version.rb, line 22
def self.find(tag)
  url_builder = UrlBuilder.new tag
  response = Atlas.client.get(url_builder.box_version_url)

  new(tag, response)
end
new(tag, hash = {}) click to toggle source

Initialize a version from a versiontag and object hash.

@param [String] tag the tag which represents the origin of the version. @param [Hash] hash the attributes for the version. @param attr [String] :version The version number. @param attr [String] :description Description of the box.

Calls superclass method
# File lib/atlas/box_version.rb, line 50
def initialize(tag, hash = {})
  hash.replace_key!("description_markdown", "description")

  super(tag, hash)
end

Public Instance Methods

create_provider(attr) click to toggle source

Create a provider for this version.

@param [Hash] attr attributes for the provider.

@return [BoxProvider] a representation of the provider.

# File lib/atlas/box_version.rb, line 73
def create_provider(attr)
  BoxProvider.create(tag, attr)
end
delete() click to toggle source

Delete the version.

@return [Hash] Atlas response object.

# File lib/atlas/box_version.rb, line 120
def delete
  Atlas.client.delete(url_builder.box_version_url)
end
providers=(attr) click to toggle source

Assign the providers of this version.

@note This is intended to be used to assign the response object, not

calling directly.

@param [Array] attr an array of response hashes.

# File lib/atlas/box_version.rb, line 62
def providers=(attr)
  @providers = attr.collect do |v|
    BoxProvider.new("#{tag}/#{v['name']}", v)
  end
end
release() click to toggle source

Release the version.

@return [Hash] Atlas response object.

# File lib/atlas/box_version.rb, line 102
def release
  response = Atlas.client.put("#{url_builder.box_version_url}/release")

  update_with_response(response)
end
revoke() click to toggle source

Revoke the version.

@return [Hash] Atlas response object.

# File lib/atlas/box_version.rb, line 111
def revoke
  response = Atlas.client.put("#{url_builder.box_version_url}/revoke")

  update_with_response(response)
end
save() click to toggle source

Save the version.

@return [Hash] Atlas response object.

# File lib/atlas/box_version.rb, line 80
def save # rubocop:disable Metrics/AbcSize
  body = { version: to_hash }

  # providers are saved seperately
  body[:version].delete(:providers)

  begin
    response = Atlas.client.put(url_builder.box_version_url, body: body)
  rescue Atlas::Errors::NotFoundError
    response = Atlas.client.post("#{url_builder.box_url}/versions",
                                 body: body)
  end

  # trigger the same on the providers
  providers.each(&:save) if providers

  update_with_response(response, [:providers])
end