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
|
# File 'lib/frm/s3.rb', line 6
def initialize(opts={})
super()
@opts = opts.dup
puts "@opts.inspect is #{@opts.inspect}"
@opts[:public_repo] ||= false
@opts[:acl] = @opts[:public_repo] ? :public_read : :private
@opts[:access_key_id] ||= ENV['AWS_ACCESS_KEY_ID']
@opts[:secret_access_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[:access_key_id].nil?
raise "you either need to pass an aws_secret_key option or set the AWS_SECRET_KEY environment variable" if @opts[:secret_access_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] = @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
53
54
55
56
57
58
|
# File 'lib/frm/s3.rb', line 53
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
30
31
32
33
34
35
36
37
38
|
# File 'lib/frm/s3.rb', line 30
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
24
25
26
27
28
|
# File 'lib/frm/s3.rb', line 24
def exists?(relative_path)
handle_errors do
return @s3.buckets[@opts[:bucket]].objects[full_path(relative_path)].exists?
end
end
|
#get(relative_path) ⇒ Object
47
48
49
50
51
|
# File 'lib/frm/s3.rb', line 47
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
60
61
62
63
64
65
|
# File 'lib/frm/s3.rb', line 60
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
40
41
42
43
44
45
|
# File 'lib/frm/s3.rb', line 40
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
|