Class: Ploy::S3Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/ploy/s3storage.rb

Instance Method Summary collapse

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

#listObject



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, meta = {})
  AWS::S3.new.buckets[@bucketname].objects[name].write(
    Pathname.new(path),
    { :metadata => meta }
  )
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