Sha256: afde1b405117127d608812704eb2b5d6751cea8c31e1e8cd050a54b8e3b0ff3c

Contents?: true

Size: 1.95 KB

Versions: 26

Compression:

Stored size: 1.95 KB

Contents

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

module Fog
  module Storage
    class Atmos

      class Files < Fog::Collection

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

        model Fog::Storage::Atmos::File

        def all(options = {})
          requires :directory
          directory ? ns = directory.key : ns = ''
          ns = ns + '/' unless ns =~ /\/$/
          data = service.get_namespace(ns).body[:DirectoryList]
          data = {:DirectoryEntry => []} if data.kind_of? String
          data[:DirectoryEntry] = [data[:DirectoryEntry]] if data[:DirectoryEntry].kind_of? Hash
          files = data[:DirectoryEntry].select {|de| de[:FileType] == 'regular'}
          files.each do |s|
            s[:directory] = directory
          end
          # TODO - Load additional file meta?
          load(files)
        end

        def get(key, &block)
          requires :directory
          data = service.get_namespace(directory.key + key, :parse => false)#, &block)
          file_data = data.headers.merge({
            :body => data.body,
            :key  => key
          })
          new(file_data)
        rescue Fog::Storage::Atmos::NotFound
          nil
        end

        def get_url(key)
          requires :directory
          if self.directory.public_url
            "#{self.directory.public_url}/#{key}"
          end
        end

        def head(key, options = {})
          requires :directory
          data = service.head_namespace(directory.key + key, :parse => false)
          file_data = data.headers.merge({
            :body => data.body,
            :key => key
          })
          new(file_data)
        rescue Fog::Storage::Atmos::NotFound
          nil
        end

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

      end

    end
  end
end

Version data entries

26 entries across 26 versions & 6 rubygems

Version Path
gapinc-fog-1.12.1.2.1 lib/fog/atmos/models/storage/files.rb
fog-maestrodev-1.15.0.20130927082724 lib/fog/atmos/models/storage/files.rb
fog-maestrodev-1.15.0.20130829165835 lib/fog/atmos/models/storage/files.rb
fog-1.15.0 lib/fog/atmos/models/storage/files.rb
gapinc-fog-1.14.0 lib/fog/atmos/models/storage/files.rb
fog-maestrodev-1.14.0.20130806165225 lib/fog/atmos/models/storage/files.rb
fog-1.14.0 lib/fog/atmos/models/storage/files.rb
fog-1.13.0 lib/fog/atmos/models/storage/files.rb
gapinc-fog-1.12.1.2 lib/fog/atmos/models/storage/files.rb
gapinc-fog-1.12.1.1 lib/fog/atmos/models/storage/files.rb
gapinc-fog-1.12.1a lib/fog/atmos/models/storage/files.rb
gapinc-fog-1.12.1 lib/fog/atmos/models/storage/files.rb
fog-1.12.1 lib/fog/atmos/models/storage/files.rb
fog-1.12.0 lib/fog/atmos/models/storage/files.rb
hpfog-0.0.20 lib/fog/atmos/models/storage/files.rb
vagrant-shell-0.2.6 vendor/bundle/gems/fog-1.10.1/lib/fog/atmos/models/storage/files.rb
vagrant-shell-0.2.5 vendor/bundle/gems/fog-1.10.1/lib/fog/atmos/models/storage/files.rb
fog-1.11.1 lib/fog/atmos/models/storage/files.rb
fog-1.11.0 lib/fog/atmos/models/storage/files.rb
fog-1.10.1 lib/fog/atmos/models/storage/files.rb