Sha256: 4450017ba1532a110950cfb091395d913b9fda42c8dd43ccbf79a47a4d2f33f8

Contents?: true

Size: 1.97 KB

Versions: 25

Compression:

Stored size: 1.97 KB

Contents

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

module Fog
  module Storage
    class Ninefold

      class Files < Fog::Collection

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

        model Fog::Storage::Ninefold::File

        def all(options = {})
          requires :directory
          directory ? ns = directory.key : ns = ''
          ns = ns + '/' unless ns =~ /\/$/
          data = connection.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 = connection.get_namespace(directory.key + key, :parse => false)#, &block)
          file_data = data.headers.merge({
            :body => data.body,
            :key  => key
          })
          new(file_data)
        rescue Fog::Storage::Ninefold::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 = connection.head_namespace(directory.key + key, :parse => false)
          file_data = data.headers.merge({
            :body => data.body,
            :key => key
          })
          new(file_data)
        rescue Fog::Storage::Ninefold::NotFound
          nil
        end

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

      end

    end
  end
end

Version data entries

25 entries across 25 versions & 8 rubygems

Version Path
fog-parser-fix-1.6.1 lib/fog/ninefold/models/storage/files.rb
fog-test-again-1.6.0 lib/fog/ninefold/models/storage/files.rb
fog-parser-fix-1.6.0 lib/fog/ninefold/models/storage/files.rb
fog-1.6.0 lib/fog/ninefold/models/storage/files.rb
fog-1.5.0 lib/fog/ninefold/models/storage/files.rb
fog-1.4.0 lib/fog/ninefold/models/storage/files.rb
brightbox-cli-0.18.1 lib/brightbox-cli/vendor/fog/lib/fog/ninefold/models/storage/files.rb
michiels-fog-1.3.1 lib/fog/ninefold/models/storage/files.rb
ftl-0.2.0 vendor/bundle/gems/fog-1.3.1/lib/fog/ninefold/models/storage/files.rb
brightbox-cli-0.18.0 lib/brightbox-cli/vendor/fog/lib/fog/ninefold/models/storage/files.rb
fog-1.3.1 lib/fog/ninefold/models/storage/files.rb
fog-1.3.0 lib/fog/ninefold/models/storage/files.rb
brightbox-cli-0.17.5 lib/brightbox-cli/vendor/fog/lib/fog/ninefold/models/storage/files.rb
fog-1.2.0 lib/fog/ninefold/models/storage/files.rb
ktheory-fog-1.1.2 lib/fog/ninefold/models/storage/files.rb
brightbox-cli-0.17.4 lib/brightbox-cli/vendor/fog/lib/fog/ninefold/models/storage/files.rb
brightbox-cli-0.17.3 lib/brightbox-cli/vendor/fog/lib/fog/ninefold/models/storage/files.rb
brightbox-cli-0.17.2 lib/brightbox-cli/vendor/fog/lib/fog/ninefold/models/storage/files.rb
brightbox-cli-0.17.1 lib/brightbox-cli/vendor/fog/lib/fog/ninefold/models/storage/files.rb
brightbox-cli-0.17.0 lib/brightbox-cli/vendor/fog/lib/fog/ninefold/models/storage/files.rb