Class: Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/eops/storage.rb

Instance Method Summary collapse

Constructor Details

#initializeStorage

Returns a new instance of Storage.



3
4
5
# File 'lib/eops/storage.rb', line 3

def initialize
  @s3 = AWS::S3.new
end

Instance Method Details

#copy(bucket, key, desired_key) ⇒ Object



7
8
9
# File 'lib/eops/storage.rb', line 7

def copy(bucket, key, desired_key)
  @s3.buckets[bucket].objects[key].copy_to(desired_key)
end

#download(bucket, key, output_directory) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/eops/storage.rb', line 15

def download(bucket, key, output_directory)
  obj = @s3.buckets[bucket].objects[key]

  base = Pathname.new("#{obj.key}").basename

  Dir.mkdir(output_directory) unless File.exists?(output_directory)

  File.open("#{output_directory}/#{base}", 'w') do |file|
    file.write(obj.read)
  end
end

#upload(file, bucket, key) ⇒ Object



11
12
13
# File 'lib/eops/storage.rb', line 11

def upload(file, bucket, key)
  @s3.buckets[bucket].objects[key].write(:file => file)
end