Class: Capriza::AWS::S3Upload

Inherits:
Object
  • Object
show all
Defined in:
lib/capriza-aws-helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ S3Upload

Returns a new instance of S3Upload.



97
98
99
100
101
# File 'lib/capriza-aws-helper.rb', line 97

def initialize(options = {})
  @options = options
  ::AWS.config(@options[:config])
  @s3 = ::AWS::S3.new(:s3_endpoint => @options[:config]['s3_endpoint'])
end

Instance Method Details

#deleteObject



111
112
113
114
# File 'lib/capriza-aws-helper.rb', line 111

def delete
  puts "deleting #{@options['dir']}"
  @s3.buckets[@options[:bucket]].objects.with_prefix(@options[:dir] + '/').delete_all
end

#uploadObject



103
104
105
106
107
108
109
# File 'lib/capriza-aws-helper.rb', line 103

def upload
  Dir.glob("#{@options[:dir]}/**/*").each do |file|
    puts "starting upload of #{file} to #{@options[:bucket]}"
    @s3.buckets[@options[:bucket]].objects[file].write(File.read(file), @options[:file_options] || {} ) unless File.directory?(file)
    puts "completed upload of #{file} to #{@options[:bucket]}"
  end
end