Class: Backy::S3Save

Inherits:
Object
  • Object
show all
Includes:
S3
Defined in:
lib/backy/s3_save.rb

Constant Summary collapse

DEFAULT_EXPIRE_AFTER =
1.month

Instance Method Summary collapse

Constructor Details

#initialize(file_name:, key: nil, expire_after: nil) ⇒ S3Save

Returns a new instance of S3Save.



7
8
9
10
11
# File 'lib/backy/s3_save.rb', line 7

def initialize(file_name:, key: nil, expire_after: nil)
  @file_name = file_name
  @key = key || file_name
  @expires = (expire_after || DEFAULT_EXPIRE_AFTER).from_now
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/backy/s3_save.rb', line 13

def call
  print "Sending #{file_name} to S3 ... "

  unless File.exist?(file_name)
    puts "error. #{file_name} does not exist"

    return
  end

  File.open(file_name, "rb") do |body|
    s3.put_object(key: key, body: body, bucket: bucket, expires: expires)
  end

  puts "done"
end