Class: GitMedia::Transport::S3
- Defined in:
- lib/git-media/transport/s3.rb
Instance Method Summary collapse
- #get_file(sha, to_file) ⇒ Object
- #get_unpushed(files) ⇒ Object
-
#initialize(bucket, access_key_id = nil, secret_access_key = nil) ⇒ S3
constructor
A new instance of S3.
- #put_file(sha, from_file) ⇒ Object
- #read? ⇒ Boolean
- #write? ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(bucket, access_key_id = nil, secret_access_key = nil) ⇒ S3
Returns a new instance of S3.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/git-media/transport/s3.rb', line 13 def initialize(bucket, access_key_id = nil, secret_access_key = nil) @s3 = RightAws::S3Interface.new(access_key_id, secret_access_key, {:multi_thread => true, :logger => Logger.new('/tmp/s3.log')}) @bucket = bucket @buckets = @s3.list_all_my_buckets.map { |a| a[:name] } if !@buckets.include?(bucket) puts "Creating New Bucket" if @s3.create_bucket(bucket) @buckets << bucket end end end |
Instance Method Details
#get_file(sha, to_file) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/git-media/transport/s3.rb', line 30 def get_file(sha, to_file) to = File.new(to_file, File::CREAT|File::RDWR) @s3.get(@bucket, sha) do |chunk| to.write(chunk) end to.close end |
#get_unpushed(files) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/git-media/transport/s3.rb', line 46 def get_unpushed(files) keys = @s3.list_bucket(@bucket).map { |f| f[:key] } files.select do |f| !keys.include?(f) end end |
#put_file(sha, from_file) ⇒ Object
42 43 44 |
# File 'lib/git-media/transport/s3.rb', line 42 def put_file(sha, from_file) @s3.put(@bucket, sha, File.open(from_file)) end |
#read? ⇒ Boolean
26 27 28 |
# File 'lib/git-media/transport/s3.rb', line 26 def read? @buckets.size > 0 end |
#write? ⇒ Boolean
38 39 40 |
# File 'lib/git-media/transport/s3.rb', line 38 def write? @buckets.size > 0 end |