Sha256: a2eae8f547698d87e29b162804d70f025b4f8165488f7796bfa0fb8e5b17e151

Contents?: true

Size: 1.45 KB

Versions: 31

Compression:

Stored size: 1.45 KB

Contents

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

module Fog
  module Storage
    class Ninefold

      class Directories < Fog::Collection

        attribute :directory

        model Fog::Storage::Ninefold::Directory

        def all
          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
          dirs = data[:DirectoryEntry].select {|de| de[:FileType] == 'directory'}
          dirs.each do |d|
            d[:Filename] = ns + d[:Filename] if directory
            d[:Filename] += '/' unless d[:Filename] =~ /\/$/
          end
          load(dirs)
        end

        def get(key, options = {})
          return nil if key == '' # Root dir shouldn't be retrieved like this.
          key =~ /\/$/ ? ns = key : ns = key + '/'
          res = connection.get_namespace ns
          emc_meta = res.headers['x-emc-meta']
          obj_id = emc_meta.scan(/objectid=(\w+),/).flatten[0]
          new(:objectid => obj_id, :key => ns)
        rescue Fog::Storage::Ninefold::NotFound
          nil
        end

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

      end

    end
  end
end

Version data entries

31 entries across 31 versions & 9 rubygems

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