Class: Provisional::Image
- Inherits:
-
Object
- Object
- Provisional::Image
- Defined in:
- lib/provisional/image.rb
Class Method Summary collapse
- .all ⇒ Object
- .create(options = {}) ⇒ Object
- .custom ⇒ Object
- .find(options) ⇒ Object
- .list ⇒ Object
Class Method Details
.all ⇒ Object
10 11 12 |
# File 'lib/provisional/image.rb', line 10 def self.all Provisional.digital_ocean.images.all.to_a # select{|image| image.type == "snapshot"} end |
.create(options = {}) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/provisional/image.rb', line 34 def self.create( = {}) raise "Must pass in a hash" unless .is_a?(Hash) if [:name] && [:from] # Create a new image from a server. else raise "Don't know how to create image with that criteria" end end |
.custom ⇒ Object
14 15 16 |
# File 'lib/provisional/image.rb', line 14 def self.custom all.select{|image| !image.public && image.name =~ /-\d{14}$/} end |
.find(options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/provisional/image.rb', line 18 def self.find() raise "Must pass in a hash" unless .is_a?(Hash) if [:id] Provisional.digital_ocean.images.find(id: id) elsif [:name] name = [:name] image = all.select{|image| image.slug == name || image.name == name}.first if image.nil? image = all.select{|image| image.name =~ /#{name}-\d{14}/}.sort.last end return image else raise "Don't know how to find image with that criteria" end end |
.list ⇒ Object
6 7 8 |
# File 'lib/provisional/image.rb', line 6 def self.list all.map(&:name) end |