Class: Capriza::Aws::S3file

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

Instance Method Summary collapse

Constructor Details

#initialize(bucket, file_name, config) ⇒ S3file

Returns a new instance of S3file.



52
53
54
55
56
# File 'lib/capriza-aws.rb', line 52

def initialize(bucket, file_name, config)
  S3connect.new(config)
  s3 = AWS::S3.new()
  @obj = s3.buckets[bucket].objects[file_name]
end

Instance Method Details

#<=>(local_file) ⇒ Object



79
80
81
82
83
84
# File 'lib/capriza-aws.rb', line 79

def <=> (local_file)
  unless File.exist?(local_file)
    raise "File #{local_file} does not exist"
  end
  @obj.etag.gsub(/\"/, "") == Digest::MD5.hexdigest(File.read(local_file))
end

#downloadObject



67
68
69
# File 'lib/capriza-aws.rb', line 67

def download()
  @data = @obj.read
end

#get_metadata(key) ⇒ Object



75
76
77
# File 'lib/capriza-aws.rb', line 75

def (key)
  @obj.[key]
end

#set_metadata(key, value) ⇒ Object



71
72
73
# File 'lib/capriza-aws.rb', line 71

def (key, value)
  @obj.[key] = value
end

#upload(data, make_public = false) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/capriza-aws.rb', line 58

def upload(data, make_public = false)
  @data = data
  @obj.write(@data)
   = @obj.head[:metadata]
  content_type = "application/zip"
  @obj.copy_to(@obj.key, :metadata => , :content_type => content_type)
  @obj.acl = :public_read if make_public
end