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.64 lib/fog/aws/models/s3/directories.rb
fog-0.0.63 lib/fog/aws/models/s3/directories.rb
fog-0.0.62 lib/fog/aws/models/s3/directories.rb
fog-0.0.61 lib/fog/aws/models/s3/directories.rb
fog-0.0.60 lib/fog/aws/models/s3/directories.rb