Sha256: 387f543c79e72de89cc227fe90578f68cdfa779b40179634806b03d7af560bb9

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(name, options = {})
          remap_attributes(options, {
            :delimiter  => 'delimiter',
            :marker     => 'marker',
            :max_keys   => 'max-keys',
            :prefix     => 'prefix'
          })
          data = connection.get_bucket(name, options).body
          directory = new(:name => 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(name, 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.0.84 lib/fog/aws/models/s3/directories.rb
fog-0.0.83 lib/fog/aws/models/s3/directories.rb
fog-0.0.82 lib/fog/aws/models/s3/directories.rb
fog-0.0.81 lib/fog/aws/models/s3/directories.rb
fog-0.0.80 lib/fog/aws/models/s3/directories.rb
fog-0.0.79 lib/fog/aws/models/s3/directories.rb
fog-0.0.78 lib/fog/aws/models/s3/directories.rb
fog-0.0.77 lib/fog/aws/models/s3/directories.rb
fog-0.0.76 lib/fog/aws/models/s3/directories.rb
fog-0.0.75 lib/fog/aws/models/s3/directories.rb
fog-0.0.74 lib/fog/aws/models/s3/directories.rb
fog-0.0.73 lib/fog/aws/models/s3/directories.rb
fog-0.0.72 lib/fog/aws/models/s3/directories.rb
fog-0.0.71 lib/fog/aws/models/s3/directories.rb
fog-0.0.70 lib/fog/aws/models/s3/directories.rb
fog-0.0.69 lib/fog/aws/models/s3/directories.rb
fog-0.0.68 lib/fog/aws/models/s3/directories.rb
fog-0.0.67 lib/fog/aws/models/s3/directories.rb
fog-0.0.66 lib/fog/aws/models/s3/directories.rb
fog-0.0.65 lib/fog/aws/models/s3/directories.rb