Class: SimpleS3::S3

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_key, secret_key) ⇒ S3

Returns a new instance of S3.



9
10
11
# File 'lib/simple_s3.rb', line 9

def initialize(access_key, secret_key)
  connect! access_key, secret_key
end

Instance Attribute Details

#verboseObject

Returns the value of attribute verbose.



7
8
9
# File 'lib/simple_s3.rb', line 7

def verbose
  @verbose
end

Instance Method Details

#store(local, remote_dir, bucket, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simple_s3.rb', line 13

def store(local, remote_dir, bucket, options = {})
  # TODO better error handling
  return unless File.exists?(local)

  paths = File.directory?(local) ? paths = paths(local) : paths = [local]
  paths.each do |path|
    destination = remote_path_for(path, remote_dir, options[:baseline])
    unless AWS::S3::S3Object.exists?(destination, bucket) || options[:test]
      log "Storing #{destination}" if verbose 
      
      AWS::S3::S3Object.store(destination, open(path), bucket) 
      if options[:delete_source] && AWS::S3::S3Object.exists?(destination, bucket)
        File.delete(path)
      end
    end
  end  
end