Sha256: 032ed4eac46a618fe4d5576ba4fdf28488c2407cc137ec720002a296da0349a2

Contents?: true

Size: 1.49 KB

Versions: 25

Compression:

Stored size: 1.49 KB

Contents

require 'fog/collection'
require 'fog/aws/models/s3/directory'

module Fog
  module AWS
    module S3

      class Real
        def directories
          Fog::AWS::S3::Directories.new(:connection => self)
        end
      end

      class Mock
        def directories
          Fog::AWS::S3::Directories.new(:connection => self)
        end
      end

      class Directories < Fog::Collection

        model Fog::AWS::S3::Directory

        def all
          data = connection.get_service.body['Buckets']
          load(data)
        end

        def get(key, options = {})
          remap_attributes(options, {
            :delimiter  => 'delimiter',
            :marker     => 'marker',
            :max_keys   => 'max-keys',
            :prefix     => 'prefix'
          })
          data = connection.get_bucket(key, options).body
          directory = new(:key => data['Name'])
          options = {}
          for key, value in data
            if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
              options[key] = value
            end
          end
          directory.files.merge_attributes(options)
          files = data['Contents']
          while data['IsTruncated']
            data = connection.get_bucket(key, options.merge!('marker' => files.last['Key'])).body
            files.concat(data['Contents'])
          end
          directory.files.load(files)
          directory
        rescue Excon::Errors::NotFound
          nil
        end

      end

    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
fog-0.1.8 lib/fog/aws/models/s3/directories.rb
fog-0.1.7 lib/fog/aws/models/s3/directories.rb
fog-0.1.6 lib/fog/aws/models/s3/directories.rb
fog-0.1.5 lib/fog/aws/models/s3/directories.rb
fog-0.1.4 lib/fog/aws/models/s3/directories.rb
fog-0.1.3 lib/fog/aws/models/s3/directories.rb
fog-0.1.2 lib/fog/aws/models/s3/directories.rb
fog-0.1.1 lib/fog/aws/models/s3/directories.rb
fog-0.1.0 lib/fog/aws/models/s3/directories.rb
fog-0.0.100 lib/fog/aws/models/s3/directories.rb
fog-0.0.99 lib/fog/aws/models/s3/directories.rb
fog-0.0.98 lib/fog/aws/models/s3/directories.rb
fog-0.0.97 lib/fog/aws/models/s3/directories.rb
fog-0.0.96 lib/fog/aws/models/s3/directories.rb
fog-0.0.95 lib/fog/aws/models/s3/directories.rb
fog-0.0.94 lib/fog/aws/models/s3/directories.rb
fog-0.0.93 lib/fog/aws/models/s3/directories.rb
fog-0.0.92 lib/fog/aws/models/s3/directories.rb
fog-0.0.91 lib/fog/aws/models/s3/directories.rb
fog-0.0.90 lib/fog/aws/models/s3/directories.rb