Class: Rbk::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/rbk/uploader.rb

Instance Method Summary collapse

Constructor Details

#initialize(bucket, shell, date = Date.today) ⇒ Uploader

Returns a new instance of Uploader.



5
6
7
8
9
# File 'lib/rbk/uploader.rb', line 5

def initialize(bucket, shell, date=Date.today)
  @bucket = bucket
  @shell = shell
  @date_prefix = (date || Date.today).strftime('%Y%m%d')
end

Instance Method Details

#upload(path) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/rbk/uploader.rb', line 11

def upload(path)
  s3_object = @bucket.objects[[@date_prefix, path].join('/')]
  if s3_object.exists?
    @shell.puts(%(s3://#{@bucket.name}/#{s3_object.key} already exists, skipping...))
  else
    @shell.puts(%(Writing #{path} to s3://#{@bucket.name}/#{s3_object.key}))
    s3_object.write(Pathname.new(path))
  end
end