Sha256: 3af65e50320863b45bc8cea5b0b900c27c07a27dde65b60408ffbaa7b7834eb7

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

module Fog
  module Storage
    class Atmos
      class Directories < Fog::Collection
        model Fog::Storage::Atmos::Directory

        attribute :directory

        def all
          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
          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 = service.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::Atmos::NotFound
          nil
        end

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

Version data entries

6 entries across 4 versions & 3 rubygems

Version Path
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-atmos-0.1.0/lib/fog/storage/atmos/models/directories.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-atmos-0.1.0/lib/fog/storage/atmos/models/directories.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-atmos-0.1.0/lib/fog/storage/atmos/models/directories.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-atmos-0.1.0/lib/fog/storage/atmos/models/directories.rb
fog-atmos-0.1.0 lib/fog/storage/atmos/models/directories.rb
fog-atmos-0.0.1 lib/fog/storage/atmos/models/directories.rb