Class: Vman::S3

Inherits:
Object
  • Object
show all
Defined in:
lib/vman/s3.rb

Instance Method Summary collapse

Constructor Details

#initialize(bucket_uri) ⇒ S3

Returns a new instance of S3.



6
7
8
# File 'lib/vman/s3.rb', line 6

def initialize(bucket_uri)
  @bucket ||= Aws::S3::Resource.new.bucket(bucket_uri[5..-1])
end

Instance Method Details

#find(key) ⇒ Object



14
15
16
# File 'lib/vman/s3.rb', line 14

def find(key)
  @bucket.objects({ prefix: key })
end

#listObject



10
11
12
# File 'lib/vman/s3.rb', line 10

def list
  @bucket.objects
end

#store(file_path, key) ⇒ Object



18
19
20
21
22
23
# File 'lib/vman/s3.rb', line 18

def store(file_path, key)
  @bucket.put_object({
    body: File.open(file_path),
    key: key
  })
end

#versions(key) ⇒ Object

TODO custom, more descriptive error class



26
27
28
29
30
31
32
33
34
# File 'lib/vman/s3.rb', line 26

def versions(key)
  _versions = @bucket.object_versions({ prefix: key })

  if _versions.count == 0
    raise "No object exists for supplied key: #{key}"
  end

  _versions
end