Sha256: c3e411f959d0ea1dc0cf017655ff7322c0133bb42a28add0cfadb7ae9f3a75de

Contents?: true

Size: 1.58 KB

Versions: 63

Compression:

Stored size: 1.58 KB

Contents

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(service.list_public_images_detailed.body['images'])
        end

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

        def find_by_id(id)
          all.find {|image| image.id == id}
        end
        alias_method :get, :find_by_id

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

        def private
          images = load(service.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(service.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(service.list_public_images_detailed(attribute , value).body['images'])
        end
      end
    end
  end
end

Version data entries

63 entries across 63 versions & 6 rubygems

Version Path
fog-1.20.0 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/openstack/models/image/images.rb
fog-1.19.0 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131209090811 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131206115947 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131205181604 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131127194823 lib/fog/openstack/models/image/images.rb
fog-maestrodev-1.18.0.20131126183714 lib/fog/openstack/models/image/images.rb