Sha256: b745adc95aabad2fb90e22075ab7139c2105999a14ecd61a5ef5bf8bcee7ca77

Contents?: true

Size: 1.77 KB

Versions: 8

Compression:

Stored size: 1.77 KB

Contents

require 'uri'

module Aws
  module S3
    class Bucket

      # Deletes all objects and versioned objects from this bucket
      #
      # @example
      #
      #   bucket.clear!
      #
      # @return [void]
      def clear!
        object_versions.delete
      end

      # Deletes all objects and versioned objects from this bucket and
      # then deletes the bucket.
      #
      # @example
      #
      #   bucket.delete!
      #
      # @return [void]
      def delete!
        clear!
        delete
      end

      # @return [String] the URL for this bucket.
      def url
        url = URI.parse(client.config.endpoint.to_s)
        if dns_compatible?(url.scheme) && !client.config.force_path_style
          url.host = "#{name}.#{url.host}"
        else
          url.path = "/#{name}"
        end
        url.to_s
      end

      # Creates a {PresignedPost} that makes it easy to upload a file from
      # a web browser direct to Amazon S3 using an HTML post form with
      # a file field.
      #
      # See the {PresignedPost} documentation for more information.
      # @note You must specify `:key` or `:key_starts_with`. All other options
      #   are optional.
      # @option (see PresignedPost#initialize)
      # @return [PresignedPost]
      # @see PresignedPost
      def presigned_post(options = {})
        PresignedPost.new(
          client.config.credentials,
          client.config.region,
          name,
          options)
      end

      # @api private
      def load
        @data = client.list_buckets.buckets.find { |b| b.name == name }
        raise "unable to load bucket #{name}" if @data.nil?
        self
      end

      private

      def dns_compatible?(scheme)
        Plugins::S3BucketDns.dns_compatible?(name, scheme == 'https')
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
aws-sdk-resources-2.1.10 lib/aws-sdk-resources/services/s3/bucket.rb
aws-sdk-resources-2.1.9 lib/aws-sdk-resources/services/s3/bucket.rb
aws-sdk-resources-2.1.8 lib/aws-sdk-resources/services/s3/bucket.rb
aws-sdk-resources-2.1.7 lib/aws-sdk-resources/services/s3/bucket.rb
aws-sdk-resources-2.1.5 lib/aws-sdk-resources/services/s3/bucket.rb
aws-sdk-resources-2.1.4 lib/aws-sdk-resources/services/s3/bucket.rb
aws-sdk-resources-2.1.3 lib/aws-sdk-resources/services/s3/bucket.rb
aws-sdk-resources-2.1.2 lib/aws-sdk-resources/services/s3/bucket.rb