Class: Provisional::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/provisional/image.rb

Class Method Summary collapse

Class Method Details

.allObject



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(options = {})
  raise "Must pass in a hash" unless options.is_a?(Hash)
  if options[:name] && options[:from]
    # Create a new image from a server.
  else
    raise "Don't know how to create image with that criteria"
  end
end

.customObject



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(options)
  raise "Must pass in a hash" unless options.is_a?(Hash)
  if options[:id]
    Provisional.digital_ocean.images.find(id: id)
  elsif options[:name]
    name = options[: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

.listObject



6
7
8
# File 'lib/provisional/image.rb', line 6

def self.list
  all.map(&:name)
end