Class: Ploy::S3Storage
- Inherits:
-
Object
- Object
- Ploy::S3Storage
- Defined in:
- lib/ploy/s3storage.rb
Instance Method Summary collapse
- #copy(from, to) ⇒ Object
- #get(from, fileio) ⇒ Object
-
#initialize(bucket) ⇒ S3Storage
constructor
A new instance of S3Storage.
- #list ⇒ Object
- #metadata(loc) ⇒ Object
- #put(path, name, meta = {}) ⇒ Object
- #read(from) ⇒ Object
Constructor Details
#initialize(bucket) ⇒ S3Storage
Returns a new instance of S3Storage.
5 6 7 |
# File 'lib/ploy/s3storage.rb', line 5 def initialize(bucket) @bucketname = bucket end |
Instance Method Details
#copy(from, to) ⇒ Object
16 17 18 |
# File 'lib/ploy/s3storage.rb', line 16 def copy(from, to) AWS::S3.new.buckets[@bucketname].objects[from].copy_to(to) end |
#get(from, fileio) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/ploy/s3storage.rb', line 24 def get(from, fileio) AWS::S3.new.buckets[@bucketname].objects[from].read do |chunk| fileio.write(chunk) end fileio.flush end |
#list ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ploy/s3storage.rb', line 40 def list tree = AWS::S3.new.buckets[@bucketname].as_tree dirs = tree.children.select(&:branch?).collect(&:prefix) package_names = [] dirs.each do |dir| dir.chop! if dir != 'hub' && dir != 'blessed' && dir != 'staging' package_names.push(dir) end end return package_names end |
#metadata(loc) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/ploy/s3storage.rb', line 31 def (loc) o = AWS::S3.new.buckets[@bucketname].objects[loc] if (o.exists?) then return o. else return {} end end |
#put(path, name, meta = {}) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/ploy/s3storage.rb', line 9 def put(path, name, = {}) AWS::S3.new.buckets[@bucketname].objects[name].write( Pathname.new(path), { :metadata => } ) end |
#read(from) ⇒ Object
20 21 22 |
# File 'lib/ploy/s3storage.rb', line 20 def read(from) AWS::S3.new.buckets[@bucketname].objects[from].read end |