Sha256: ee13eb92a1decdfcaaad4915fafbdcfbb3f4b49a11e1af80f7daaf8158648ac4

Contents?: true

Size: 1.73 KB

Versions: 61

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

61 entries across 61 versions & 6 rubygems

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