1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/openstack/models/image/images.rb
Philip Mark Deazeta f67a186902 [openstack|image] Refactor Dynamic Methods on Image Model
-removed method missing, added location attr for image upload
2012-04-30 10:35:00 +08:00

60 lines
1.6 KiB
Ruby

require 'fog/core/collection'
require 'fog/openstack/models/image/image'
module Fog
module Image
class OpenStack
class Images < Fog::Collection
model Fog::Image::OpenStack::Image
def all
load(connection.list_public_images_detailed.body['images'])
end
def details
load(connection.list_public_images_detailed.body['images'])
end
def find_by_id(id)
self.find {|image| image.id == id}
end
def public
images = load(connection.list_public_images_detailed.body['images'])
images.delete_if{|image| image.is_public == false}
end
def private
images = load(connection.list_public_images_detailed.body['images'])
images.delete_if{|image| image.is_public}
end
def destroy(id)
image = self.find_by_id(id)
image.destroy
end
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
def find_by_size_min(size)
find_attribute(__method__, size)
end
def find_by_size_max(size)
find_attribute(__method__, size)
end
def find_attribute(attribute,value)
attribute = attribute.to_s.gsub("find_by_", "")
load(connection.list_public_images_detailed(attribute , value).body['images'])
end
end
end
end
end