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
-
#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
#inspect, #to_hash, #update_with_response
Constructor Details
#initialize(tag, hash = {}) ⇒ Box
Initialize a box from a tag and object hash.
62 63 64 65 66 67 |
# File 'lib/atlas/box.rb', line 62 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.
41 42 43 44 45 46 |
# File 'lib/atlas/box.rb', line 41 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.
21 22 23 24 25 26 |
# File 'lib/atlas/box.rb', line 21 def self.find(tag) url_builder = UrlBuilder.new tag response = Atlas.client.get(url_builder.box_url) new(tag, JSON.parse(response.body)) end |
Instance Method Details
#delete ⇒ Hash
Delete the box.
120 121 122 123 124 |
# File 'lib/atlas/box.rb', line 120 def delete response = Atlas.client.delete(url_builder.box_url) JSON.parse(response.body) end |
#save ⇒ Hash
Save the box.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/atlas/box.rb', line 98 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 Excon::Errors::NotFound response = Atlas.client.post('/boxes', body: body) end # trigger the same on versions versions.each(&:save) if versions update_with_response(response.body, [:versions]) end |