Class: Atlas::Box
Overview
Representation and handling of Box objects.
Constant Summary
Constants inherited from Resource
Resource::INTERNAL_ATTRIBUTE_KEYS
Instance Attribute Summary collapse
-
#current_version ⇒ Object
Returns the value of attribute current_version.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#private ⇒ Object
Returns the value of attribute private.
-
#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
#attributes, date_accessor, date_writer, #inspect, #to_hash, #update_with_response
Methods included from Validations
Constructor Details
#initialize(tag, hash = {}) ⇒ Box
Initialize a box from a tag and object hash.
65 66 67 68 69 70 |
# File 'lib/atlas/box.rb', line 65 def initialize(tag, hash = {}) hash.replace_key!("private", "is_private") hash.replace_key!("description_markdown", "description") 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 |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/atlas/box.rb', line 13 def name @name end |
#private ⇒ Object
Returns the value of attribute private.
13 14 15 |
# File 'lib/atlas/box.rb', line 13 def private @private 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.
44 45 46 47 48 49 |
# File 'lib/atlas/box.rb', line 44 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.
24 25 26 27 28 29 |
# File 'lib/atlas/box.rb', line 24 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.
103 104 105 |
# File 'lib/atlas/box.rb', line 103 def create_version(attr) BoxVersion.create(tag, attr) end |
#delete ⇒ Hash
Delete the box.
136 137 138 |
# File 'lib/atlas/box.rb', line 136 def delete Atlas.client.delete(url_builder.box_url) end |
#save ⇒ Hash
Save the box.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/atlas/box.rb', line 110 def save validate! 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 body[:box].replace_key!(:private, :is_private) response = Atlas.client.post("/boxes", body: body) end # trigger the same on versions versions.each(&:save) if versions update_with_response(response, [:versions]) end |