Sha256: 2de093f43cd64c0eb03eef37709b4aadcd11724ab2fc74fb68530e1a8d70176d

Contents?: true

Size: 1.73 KB

Versions: 29

Compression:

Stored size: 1.73 KB

Contents

require 'fog/core/collection'
require 'fog/hp/models/storage/shared_file'

module Fog
  module Storage
    class HP
      class SharedFiles < Fog::Collection
        attribute :shared_directory

        model Fog::Storage::HP::SharedFile

        def all
          requires :shared_directory
          parent = shared_directory.collection.get(shared_directory.url)
          if parent
            load(parent.files.map {|file| file.attributes})
          else
            nil
          end
        # throws exception Fog::HP::Errors::Forbidden if insufficient access
        rescue Fog::Storage::HP::NotFound
          nil
        end

        def get(key, &block)
          requires :shared_directory
          shared_object_url = "#{shared_directory.url}/#{key}"
          data = service.get_shared_object(shared_object_url, &block)
          file_data = data.headers.merge({
            :body => data.body,
            :key  => key
          })
          new(file_data)
        # throws exception Fog::HP::Errors::Forbidden if insufficient access
        rescue Fog::Storage::HP::NotFound
          nil
        end

        def head(key)
          requires :shared_directory
          shared_object_url = "#{shared_directory.url}/#{key}"
          data = service.head_shared_object(shared_object_url)
          file_data = data.headers.merge({
            :body => '',
            :key => key
          })
          new(file_data)
        # throws exception Fog::HP::Errors::Forbidden if insufficient access
        rescue Fog::Storage::HP::NotFound
          nil
        end

        def new(attributes = {})
          requires :shared_directory
          super({ :shared_directory => shared_directory }.merge!(attributes))
        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_files.rb
fog-1.36.0 lib/fog/hp/models/storage/shared_files.rb
fog-1.35.0 lib/fog/hp/models/storage/shared_files.rb
fog-2.0.0.pre.0 lib/fog/hp/models/storage/shared_files.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-1.32.0/lib/fog/hp/models/storage/shared_files.rb
fog-1.34.0 lib/fog/hp/models/storage/shared_files.rb
fog-1.33.0 lib/fog/hp/models/storage/shared_files.rb
fog-1.32.0 lib/fog/hp/models/storage/shared_files.rb
fog-1.31.0 lib/fog/hp/models/storage/shared_files.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/hp/models/storage/shared_files.rb
fog-1.30.0 lib/fog/hp/models/storage/shared_files.rb
fog-1.29.0 lib/fog/hp/models/storage/shared_files.rb
fog-1.28.0 lib/fog/hp/models/storage/shared_files.rb
fog-1.27.0 lib/fog/hp/models/storage/shared_files.rb
fog-1.26.0 lib/fog/hp/models/storage/shared_files.rb
fog-1.25.0 lib/fog/hp/models/storage/shared_files.rb
nsidc-fog-1.24.1 lib/fog/hp/models/storage/shared_files.rb
fog-1.24.0 lib/fog/hp/models/storage/shared_files.rb
ns-fog-1.22.11 lib/fog/hp/models/storage/shared_files.rb
ns-fog-1.22.10 lib/fog/hp/models/storage/shared_files.rb