Sha256: 8143273fe1d5f3e08af85d1f96f41058664c7e2079b7b167d3f4e3796529fa47

Contents?: true

Size: 1.81 KB

Versions: 61

Compression:

Stored size: 1.81 KB

Contents

require 'fog/core/model'

module Fog
  module Storage
    class HP

      class SharedFile < Fog::Model

        identity  :key,             :aliases => 'name'
        attribute :url

        attribute :content_length,  :aliases => ['bytes', 'Content-Length'], :type => :integer
        attribute :content_type,    :aliases => ['content_type', 'Content-Type']
        attribute :etag,            :aliases => ['hash', 'Etag']
        attribute :last_modified,   :aliases => ['last_modified', 'Last-Modified'], :type => :time

        def url
          "#{self.collection.shared_directory.url}/#{key}"
        end

        def body
          attributes[:body] ||= if last_modified
            collection.get(identity).body
          else
            ''
          end
        end

        def body=(new_body)
          attributes[:body] = new_body
        end

        def destroy
          requires :shared_directory, :key
          service.delete_shared_object(self.url)
          true
        # throws exception Fog::HP::Errors::Forbidden if insufficient access
        rescue Fog::Storage::HP::NotFound
          false
        end

        def shared_directory
          @shared_directory
        end

        def save(options = {})
          requires :shared_directory, :key
          options['Content-Type'] = content_type if content_type
          data = service.put_shared_object(shared_directory.url, key, body, options)
          merge_attributes(data.headers)
          self.content_length = Fog::Storage.get_body_size(body)
          true
        # throws exception Fog::HP::Errors::Forbidden if insufficient access
        rescue Fog::Storage::HP::NotFound
          false
        end

        private

        def shared_directory=(new_shared_directory)
          @shared_directory = new_shared_directory
        end
      end

    end
  end
end

Version data entries

61 entries across 61 versions & 6 rubygems

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