Class: Cloudkeeper::Entities::ImageList
- Inherits:
-
Object
- Object
- Cloudkeeper::Entities::ImageList
- Defined in:
- lib/cloudkeeper/entities/image_list.rb
Instance Attribute Summary collapse
-
#appliances ⇒ Object
Returns the value of attribute appliances.
-
#creation_date ⇒ Object
Returns the value of attribute creation_date.
-
#description ⇒ Object
Returns the value of attribute description.
-
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#source ⇒ Object
Returns the value of attribute source.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .from_hash(image_list_hash) ⇒ Object
- .populate_appliances!(image_list, image_list_hash) ⇒ Object
- .populate_image_list(image_list_hash) ⇒ Object
- .prepare_appliance_hash(image_hash, endorser, vo, image_list_identifier) ⇒ Object
Instance Method Summary collapse
- #add_appliance(appliance) ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(identifier, expiration_date, creation_date = nil, source = '', title = '', description = '', appliances = {}) ⇒ ImageList
constructor
A new instance of ImageList.
Constructor Details
#initialize(identifier, expiration_date, creation_date = nil, source = '', title = '', description = '', appliances = {}) ⇒ ImageList
Returns a new instance of ImageList.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 8 def initialize(identifier, expiration_date, creation_date = nil, source = '', title = '', description = '', appliances = {}) raise Cloudkeeper::Errors::ArgumentError, 'identifier cannot be nil nor empty' if identifier.blank? || expiration_date.blank? @identifier = identifier @expiration_date = expiration_date @creation_date = creation_date @description = description @title = title @source = source @appliances = appliances end |
Instance Attribute Details
#appliances ⇒ Object
Returns the value of attribute appliances.
6 7 8 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 6 def appliances @appliances end |
#creation_date ⇒ Object
Returns the value of attribute creation_date.
6 7 8 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 6 def creation_date @creation_date end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 6 def description @description end |
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
6 7 8 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 6 def expiration_date @expiration_date end |
#identifier ⇒ Object
Returns the value of attribute identifier.
6 7 8 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 6 def identifier @identifier end |
#source ⇒ Object
Returns the value of attribute source.
6 7 8 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 6 def source @source end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 6 def title @title end |
Class Method Details
.from_hash(image_list_hash) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 31 def from_hash(image_list_hash) image_list_hash.deep_symbolize_keys! image_list_hash = image_list_hash[:'hv:imagelist'] image_list = populate_image_list image_list_hash populate_appliances!(image_list, image_list_hash) image_list end |
.populate_appliances!(image_list, image_list_hash) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 66 def populate_appliances!(image_list, image_list_hash) vo = image_list_hash[:'ad:vo'] endorser = image_list_hash[:'hv:endorser'] image_list_hash[:'hv:images'].each do |image_hash| appliance = Appliance.from_hash(prepare_appliance_hash(image_hash, endorser, vo, image_list.identifier)) image_list.add_appliance appliance end end |
.populate_image_list(image_list_hash) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 52 def populate_image_list(image_list_hash) raise Cloudkeeper::Errors::Parsing::InvalidImageListHashError, 'invalid image list hash' if image_list_hash.blank? ImageList.new image_list_hash[:'dc:identifier'], Cloudkeeper::Utils::Date.parse(image_list_hash[:'dc:date:expires']), Cloudkeeper::Utils::Date.parse(image_list_hash[:'dc:date:created']), image_list_hash[:'dc:source'], image_list_hash[:'dc:title'], image_list_hash[:'dc:description'] rescue Cloudkeeper::Errors::ArgumentError => ex raise Cloudkeeper::Errors::Parsing::InvalidImageListHashError, ex, "image list hash #{image_list_hash.inspect} " \ "doesn't contain all the necessary data" end |
.prepare_appliance_hash(image_hash, endorser, vo, image_list_identifier) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 41 def prepare_appliance_hash(image_hash, endorser, vo, image_list_identifier) appliance_hash = {} appliance_hash = image_hash[:'hv:image'] if image_hash && image_hash.key?(:'hv:image') appliance_hash[:vo] = vo appliance_hash[:image_list_identifier] = image_list_identifier appliance_hash.merge!(endorser[:'hv:x509']) if endorser && endorser.key?(:'hv:x509') appliance_hash end |
Instance Method Details
#add_appliance(appliance) ⇒ Object
20 21 22 23 24 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 20 def add_appliance(appliance) raise Cloudkeeper::Errors::ArgumentError, 'appliance cannot be nil' unless appliance appliances[appliance.identifier] = appliance end |
#expired? ⇒ Boolean
26 27 28 |
# File 'lib/cloudkeeper/entities/image_list.rb', line 26 def expired? expiration_date < Time.now end |