Class: Atlas::Box
Overview
Representation and handling of Box objects.
Instance Attribute Summary collapse
-
#current_version ⇒ Object
Returns the value of attribute current_version.
-
#description ⇒ Object
Returns the value of attribute description.
-
#is_private ⇒ Object
Returns the value of attribute is_private.
-
#name ⇒ Object
Returns the value of attribute name.
-
#short_description ⇒ Object
Returns the value of attribute short_description.
-
#username ⇒ Object
Returns the value of attribute username.
-
#versions ⇒ Object
Returns the value of attribute versions.
Attributes inherited from Resource
Class Method Summary collapse
-
.create(attr = {}) ⇒ Box
Create a new Box.
-
.find(tag) ⇒ Box
Find a box by it’s tag.
Instance Method Summary collapse
-
#create_version(attr) ⇒ BoxVersion
Create a version for this box.
-
#delete ⇒ Hash
Delete the box.
-
#initialize(tag, hash = {}) ⇒ Box
constructor
Initialize a box from a tag and object hash.
-
#save ⇒ Hash
Save the box.
Methods inherited from Resource
date_accessor, date_writer, #inspect, #to_hash, #update_with_response
Constructor Details
#initialize(tag, hash = {}) ⇒ Box
Initialize a box from a tag and object hash.
63 64 65 66 67 68 |
# File 'lib/atlas/box.rb', line 63 def initialize(tag, hash = {}) hash['is_private'] = hash['private'] hash['description'] = hash['description_markdown'] super(tag, hash) end |
Instance Attribute Details
#current_version ⇒ Object
Returns the value of attribute current_version.
13 14 15 |
# File 'lib/atlas/box.rb', line 13 def current_version @current_version end |
#description ⇒ Object
Returns the value of attribute description.
13 14 15 |
# File 'lib/atlas/box.rb', line 13 def description @description end |
#is_private ⇒ Object
Returns the value of attribute is_private.
13 14 15 |
# File 'lib/atlas/box.rb', line 13 def is_private @is_private end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/atlas/box.rb', line 13 def name @name end |
#short_description ⇒ Object
Returns the value of attribute short_description.
13 14 15 |
# File 'lib/atlas/box.rb', line 13 def short_description @short_description end |
#username ⇒ Object
Returns the value of attribute username.
13 14 15 |
# File 'lib/atlas/box.rb', line 13 def username @username end |
#versions ⇒ Object
Returns the value of attribute versions.
13 14 15 |
# File 'lib/atlas/box.rb', line 13 def versions @versions end |
Class Method Details
.create(attr = {}) ⇒ Box
Create a new Box.
42 43 44 45 46 47 |
# File 'lib/atlas/box.rb', line 42 def self.create(attr = {}) tag = "#{attr.fetch(:username, '')}/#{attr[:name]}" box = new(tag, attr) box.save box end |
.find(tag) ⇒ Box
Find a box by it’s tag.
22 23 24 25 26 27 |
# File 'lib/atlas/box.rb', line 22 def self.find(tag) url_builder = UrlBuilder.new tag response = Atlas.client.get(url_builder.box_url) new(tag, response) end |
Instance Method Details
#create_version(attr) ⇒ BoxVersion
Create a version for this box.
101 102 103 |
# File 'lib/atlas/box.rb', line 101 def create_version(attr) BoxVersion.create(tag, attr) end |
#delete ⇒ Hash
Delete the box.
130 131 132 |
# File 'lib/atlas/box.rb', line 130 def delete Atlas.client.delete(url_builder.box_url) end |
#save ⇒ Hash
Save the box.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/atlas/box.rb', line 108 def save body = { box: to_hash } # versions are saved seperately body[:box].delete(:versions) # update or create the box begin response = Atlas.client.put(url_builder.box_url, body: body) rescue Atlas::Errors::NotFoundError response = Atlas.client.post('/boxes', body: body) end # trigger the same on versions versions.each(&:save) if versions update_with_response(response, [:versions]) end |