Class: Fog::Image::OpenStack::Images

Inherits:
Collection
  • Object
show all
Defined in:
lib/rackspace-fog/openstack/models/image/images.rb

Instance Attribute Summary

Attributes inherited from Collection

#connection

Instance Method Summary collapse

Methods inherited from Collection

#clear, #create, #initialize, #inspect, #load, model, #model, #new, #reload, #table, #to_json

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Collection

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/rackspace-fog/openstack/models/image/images.rb', line 37

def method_missing(method_sym, *arguments, &block)
  if method_sym.to_s =~ /^find_by_(.*)$/
    load(connection.list_public_images_detailed($1 ,arguments.first).body['images'])
  else
    super
  end
end

Instance Method Details

#allObject



10
11
12
# File 'lib/rackspace-fog/openstack/models/image/images.rb', line 10

def all
  load(connection.list_public_images_detailed.body['images'])
end

#destroy(id) ⇒ Object



32
33
34
35
# File 'lib/rackspace-fog/openstack/models/image/images.rb', line 32

def destroy(id)
  image = self.find_by_id(id)
  image.destroy
end

#detailsObject



14
15
16
# File 'lib/rackspace-fog/openstack/models/image/images.rb', line 14

def details
  load(connection.list_public_images_detailed.body['images'])
end

#find_attribute(attribute, value) ⇒ Object



53
54
55
56
# File 'lib/rackspace-fog/openstack/models/image/images.rb', line 53

def find_attribute(attribute,value)
  attribute = attribute.to_s.gsub("find_by_", "")
  load(connection.list_public_images_detailed(attribute , value).body['images'])
end

#find_by_id(id) ⇒ Object



18
19
20
# File 'lib/rackspace-fog/openstack/models/image/images.rb', line 18

def find_by_id(id)
  self.find {|image| image.id == id}
end

#find_by_size_max(size) ⇒ Object



49
50
51
# File 'lib/rackspace-fog/openstack/models/image/images.rb', line 49

def find_by_size_max(size)
  find_attribute(__method__, size)
end

#find_by_size_min(size) ⇒ Object



45
46
47
# File 'lib/rackspace-fog/openstack/models/image/images.rb', line 45

def find_by_size_min(size)
  find_attribute(__method__, size)
end

#privateObject



27
28
29
30
# File 'lib/rackspace-fog/openstack/models/image/images.rb', line 27

def private
  images = load(connection.list_public_images_detailed.body['images'])
  images.delete_if{|image| image.is_public}
end

#publicObject



22
23
24
25
# File 'lib/rackspace-fog/openstack/models/image/images.rb', line 22

def public
  images = load(connection.list_public_images_detailed.body['images'])
  images.delete_if{|image| image.is_public == false}
end