Sha256: 3064615ea0475fdaa3da9ac50432e38ddaa3099a4d468c8dbcc1e3b16788bb7b

Contents?: true

Size: 1.81 KB

Versions: 29

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

29 entries across 29 versions & 4 rubygems

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