Class: Atlas::BoxVersion

Inherits:
Resource show all
Defined in:
lib/atlas/box_version.rb

Overview

Representation and handling of Box Version objects.

Constant Summary

Constants inherited from Resource

Resource::INTERNAL_ATTRIBUTE_KEYS

Instance Attribute Summary collapse

Attributes inherited from Resource

#tag, #url_builder

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#attributes, date_accessor, date_writer, #inspect, #to_hash, #update_with_response

Methods included from Validations

included

Constructor Details

#initialize(tag, hash = {}) ⇒ BoxVersion

Initialize a version from a versiontag and object hash.

Parameters:

  • tag (String)

    the tag which represents the origin of the version.

  • hash (Hash) (defaults to: {})

    the attributes for the version.

  • attr (String)

    :version The version number.

  • attr (String)

    :description Description of the box.



50
51
52
53
54
# File 'lib/atlas/box_version.rb', line 50

def initialize(tag, hash = {})
  hash.replace_key!("description_markdown", "description")

  super(tag, hash)
end

Instance Attribute Details

#descriptionObject

Properties of the version.



12
13
14
# File 'lib/atlas/box_version.rb', line 12

def description
  @description
end

#providersObject

Properties of the version.



12
13
14
# File 'lib/atlas/box_version.rb', line 12

def providers
  @providers
end

#statusObject

Properties of the version.



12
13
14
# File 'lib/atlas/box_version.rb', line 12

def status
  @status
end

#versionObject

Properties of the version.



12
13
14
# File 'lib/atlas/box_version.rb', line 12

def version
  @version
end

Class Method Details

.create(box_tag, attr = {}) ⇒ Version

Create a new version.

Parameters:

  • box_tag (String)

    the box tag to create the version under.

  • attr (Hash) (defaults to: {})

    attributes to create the version with.

  • attr (String) (defaults to: {})

    :version The version number.

  • attr (String) (defaults to: {})

    :description Description of the box.

Returns:

  • (Version)

    a newly created version.



37
38
39
40
41
42
# 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) ⇒ Version

Find a version by it’s tag.

Parameters:

  • tag (String)

    the tag of the version.

Returns:

  • (Version)

    a representation of the version.



22
23
24
25
26
27
# 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

Instance Method Details

#create_provider(attr) ⇒ BoxProvider

Create a provider for this version.

Parameters:

  • attr (Hash)

    attributes for the provider.

Returns:



73
74
75
# File 'lib/atlas/box_version.rb', line 73

def create_provider(attr)
  BoxProvider.create(tag, attr)
end

#deleteHash

Delete the version.

Returns:

  • (Hash)

    Atlas response object.



120
121
122
# File 'lib/atlas/box_version.rb', line 120

def delete
  Atlas.client.delete(url_builder.box_version_url)
end

#releaseHash

Release the version.

Returns:

  • (Hash)

    Atlas response object.



102
103
104
105
106
# 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

#revokeHash

Revoke the version.

Returns:

  • (Hash)

    Atlas response object.



111
112
113
114
115
# 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

#saveHash

Save the version.

Returns:

  • (Hash)

    Atlas response object.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# 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