Sha256: e65fdb54bbd8955b377c732bd3284931a24a4cb2e8bb83d89a603de0a52fbd5e

Contents?: true

Size: 1.84 KB

Versions: 37

Compression:

Stored size: 1.84 KB

Contents

require 'fog/core/collection'
require 'fog/hp/models/storage/meta_parent'
require 'fog/hp/models/storage/meta'

module Fog
  module Storage
    class HP

      class Metadata < Fog::Collection

        model Fog::Storage::HP::Meta

        include Fog::Storage::HP::MetaParent

        def all
          requires :parent
          if @parent.key
            metadata = service.head_container(@parent.key).headers
            metas = []
            metadata.each_pair {|k,v| metas << {'key' => k, 'value' => v} }
            load(metas)
          end
        rescue Fog::Storage::HP::NotFound
          nil
        end

        def destroy
          false
        end

        def get(key)
          requires :parent
          if @parent.key
            metadata = service.head_container(@parent.key).headers
            metas = []
            metas << {'key' => key, 'value' => metadata[key]}
            new(metas[0])
          end
        rescue Fog::Storage::HP::NotFound
          nil
        end

        def new(attributes = {})
          requires :parent
          super({ :parent => @parent }.merge!(attributes))
        end

        def set(data=nil)
          requires :parent
          if @parent.key
            service.put_container(@parent.key, meta_hash(data))
          end
        end

        def update(data=nil)
          requires :parent
          if @parent.key
            service.post_container(@parent.key, meta_hash(data))
          end
        end


        private
        def meta_hash(data=nil)
          if data.nil?
            data={}
            self.each do |meta|
              if meta.is_a?(Fog::Storage::HP::Meta) then
                data.store(meta.key, meta.value)
              else
                data.store(meta['key'], meta['value'])
              end
            end
          end
          data
        end

      end

    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
fog-1.22.0 lib/fog/hp/models/storage/metadata.rb
fog-1.21.0 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/hp/models/storage/metadata.rb
fog-1.20.0 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/hp/models/storage/metadata.rb
fog-1.19.0 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/hp/models/storage/metadata.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/hp/models/storage/metadata.rb