class ActiveRecord::Snapshot::S3

Attributes

connection[R]
directory[R]

Public Class Methods

new(directory:) click to toggle source
# File lib/active_record/snapshot/commands/s3.rb, line 6
def initialize(directory:)
  @connection = create_connection
  @directory = directory
end

Public Instance Methods

download_to(path) click to toggle source
# File lib/active_record/snapshot/commands/s3.rb, line 15
def download_to(path)
  File.open(path, "wb") { |f| f.write(read(path)) }
end
read(path) click to toggle source
# File lib/active_record/snapshot/commands/s3.rb, line 19
def read(path)
  connection.get_object(config.bucket, aws_key(path)).body
end
upload(path) click to toggle source
# File lib/active_record/snapshot/commands/s3.rb, line 11
def upload(path)
  connection.put_object(config.bucket, aws_key(path), File.open(path))
end

Private Instance Methods

aws_key(path) click to toggle source
# File lib/active_record/snapshot/commands/s3.rb, line 31
def aws_key(path)
  File.join(directory, File.basename(path))
end
config() click to toggle source
# File lib/active_record/snapshot/commands/s3.rb, line 27
def config
  ActiveRecord::Snapshot.config.s3
end
create_connection() click to toggle source
# File lib/active_record/snapshot/commands/s3.rb, line 35
def create_connection
  ::Fog::Storage.new(
    provider: "AWS",
    region: config.region,
    aws_access_key_id: config.access_key_id,
    aws_secret_access_key: config.secret_access_key
  )
end