Sha256: ca70e5f8a95022c6ffe114c2a44102862e3a9c9596508775d697b459aa2247e2

Contents?: true

Size: 831 Bytes

Versions: 3

Compression:

Stored size: 831 Bytes

Contents

require 'fog'

module Hillary
  class Slug
    class Bucket
      attr_reader :name

      def initialize(name = ENV['SLUG_BUCKET'], access_key = ENV['AWS_S3_KEY_ID'], secret_key = ENV['AWS_S3_KEY_SECRET'])
        @name = name
        @storage = Fog::Storage.new(
          provider: 'AWS',
          aws_access_key_id: access_key,
          aws_secret_access_key: secret_key
        )
        @directory = @storage.directories.get(name)
      end

      def exists?(name)
        @directory.files.head(name)
      end

      def write(name, file)
        @directory.files.create(
          key: name,
          body: File.open(file),
          public: false
        )
      end

      def copy(source, target)
        source_file = @directory.files.get(source)
        source_file.copy(@name, target)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hillary-0.0.6 lib/hillary/slug/bucket.rb
hillary-0.0.5 lib/hillary/slug/bucket.rb
hillary-0.0.4 lib/hillary/slug/bucket.rb