Class: FRM::S3
Instance Method Summary
collapse
Methods inherited from Base
#compute_md5, #compute_sha1, #compute_sha2, #generate_gzip_pipe, #gpg_clearsign, #gpg_detached, #gpg_export_pubkey, #gunzip_pipe, #handle_errors, #run
Constructor Details
#initialize(opts = {}) ⇒ S3
Returns a new instance of S3.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/frm/s3.rb', line 6
def initialize(opts={})
super()
@opts = opts
@opts[:public_repo] ||= false
@opts[:acl] = @opts[:public_repo] ? :public_read : :private
@opts[:aws_access_key] ||= ENV['AWS_ACCESS_KEY_ID']
@opts[:aws_secret_key] ||= ENV['AWS_SECRET_ACCESS_KEY']
raise "you either need to pass an aws_access_key option or set the AWS_ACCESS_KEY environment variable" \
if @opts[:aws_access_key].nil?
raise "you either need to pass an aws_secret_key option or set the AWS_SECRET_KEY environment variable" \
if @opts[:aws_secret_key].nil?
raise "you need to pass in a bucket param" unless @opts[:bucket]
raise "you need to pass in a prefix param" unless @opts[:prefix]
@opts[:prefix] << '/' unless @opts[:prefix][-1] == '/'
AWS.config(:access_key_id => @opts[:access_key_id],
:secret_access_key => @opts[:secret_access_key])
@s3 = AWS::S3.new
end
|
Instance Method Details
#delete(relative_path) ⇒ Object
54
55
56
57
58
59
|
# File 'lib/frm/s3.rb', line 54
def delete(relative_path)
handle_errors do
@s3.buckets[@opts[:bucket]].objects[full_path(relative_path)].delete
end
return true
end
|
#etag(relative_path) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/frm/s3.rb', line 31
def etag(relative_path)
quoted_etag = ""
handle_errors do
quoted_etag = @s3.buckets[@opts[:bucket]].objects[full_path(relative_path)].etag
end
return quoted_etag.gsub(/"/,'')
end
|
#exists?(relative_path) ⇒ Boolean
25
26
27
28
29
|
# File 'lib/frm/s3.rb', line 25
def exists?(relative_path)
handle_errors do
return @s3.buckets[@opts[:bucket]].objects[full_path(relative_path)].exists?
end
end
|
#get(relative_path) ⇒ Object
48
49
50
51
52
|
# File 'lib/frm/s3.rb', line 48
def get(relative_path)
handle_errors do
return @s3.buckets[@opts[:bucket]].objects[full_path(relative_path)].read
end
end
|
#move(old_relative_path, new_relative_path) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/frm/s3.rb', line 61
def move(old_relative_path,new_relative_path)
handle_errors do
@s3.buckets[@opts[:bucket]].objects[full_path(old_relative_path)].move_to(new_relative_path)
end
return true
end
|
#put(relative_path, value) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/frm/s3.rb', line 41
def put(relative_path,value)
handle_errors do
@s3.buckets[@opts[:bucket]].objects[full_path(relative_path)].write(value,acl: @opts[:acl])
end
return true
end
|