Sha256: 194a628768e1b217152186cc7567790880d90aff06540042472f331fa9f1b938

Contents?: true

Size: 1.84 KB

Versions: 29

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

29 entries across 29 versions & 4 rubygems

Version Path
fog-1.37.0 lib/fog/hp/models/storage/metadata.rb
fog-1.36.0 lib/fog/hp/models/storage/metadata.rb
fog-1.35.0 lib/fog/hp/models/storage/metadata.rb
fog-2.0.0.pre.0 lib/fog/hp/models/storage/metadata.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-1.32.0/lib/fog/hp/models/storage/metadata.rb
fog-1.34.0 lib/fog/hp/models/storage/metadata.rb
fog-1.33.0 lib/fog/hp/models/storage/metadata.rb
fog-1.32.0 lib/fog/hp/models/storage/metadata.rb
fog-1.31.0 lib/fog/hp/models/storage/metadata.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/hp/models/storage/metadata.rb
fog-1.30.0 lib/fog/hp/models/storage/metadata.rb
fog-1.29.0 lib/fog/hp/models/storage/metadata.rb
fog-1.28.0 lib/fog/hp/models/storage/metadata.rb
fog-1.27.0 lib/fog/hp/models/storage/metadata.rb
fog-1.26.0 lib/fog/hp/models/storage/metadata.rb
fog-1.25.0 lib/fog/hp/models/storage/metadata.rb
nsidc-fog-1.24.1 lib/fog/hp/models/storage/metadata.rb
fog-1.24.0 lib/fog/hp/models/storage/metadata.rb
ns-fog-1.22.11 lib/fog/hp/models/storage/metadata.rb
ns-fog-1.22.10 lib/fog/hp/models/storage/metadata.rb