Sha256: a1655f1e1425efa29b5f1ad7cc6d3cfde9ab08457ad57dd23ad302114e147a5e

Contents?: true

Size: 1.78 KB

Versions: 3

Compression:

Stored size: 1.78 KB

Contents

require 'fog/core/collection'
require 'fog/rackspace/models/storage/file'

module Fog
  module Rackspace
    class Storage

      class Files < Fog::Collection

        attribute :directory
        attribute :limit
        attribute :marker
        attribute :path
        attribute :prefix

        model Fog::Rackspace::Storage::File

        def all(options = {})
          requires :directory
          options = {
            'limit'   => limit,
            'marker'  => marker,
            'path'    => path,
            'prefix'  => prefix
          }.merge!(options)
          merge_attributes(options)
          parent = directory.collection.get(
            directory.key,
            options
          )
          if parent
            load(parent.files.map {|file| file.attributes})
          else
            nil
          end
        end

        def get(key, &block)
          requires :directory
          data = connection.get_object(directory.key, key, &block)
          file_data = data.headers.merge({
            :body => data.body,
            :key  => key
          })
          new(file_data)
        rescue Fog::Rackspace::Storage::NotFound
          nil
        end

        def get_url(key, expires)
          requires :directory
          connection.get_object_url(directory.name, key, expires)
        end

        def head(key, options = {})
          requires :directory
          data = connection.head_object(directory.name, key, options)
          file_data = data.headers.merge({
            :key => key
          })
          new(file_data)
        rescue Fog::Rackspace::Storage::NotFound
          nil
        end

        def new(attributes = {})
          requires :directory
          super({ :directory => directory }.merge!(attributes))
        end

      end

    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
fog-0.3.24 lib/fog/rackspace/models/storage/files.rb
bbcloud-0.8.1 lib/bbcloud/vendor/fog-0.3.23/lib/fog/rackspace/models/storage/files.rb
fog-0.3.23 lib/fog/rackspace/models/storage/files.rb