Class: PgExport::Ftp::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_export/ftp/adapter.rb

Constant Summary collapse

CHUNK_SIZE =
(2**16).freeze

Instance Method Summary collapse

Constructor Details

#initialize(connection:) ⇒ Adapter

Returns a new instance of Adapter.



6
7
8
9
10
# File 'lib/pg_export/ftp/adapter.rb', line 6

def initialize(connection:)
  @connection = connection
  @host = connection.host
  ObjectSpace.define_finalizer(self, proc { connection.close })
end

Instance Method Details

#delete(filename) ⇒ Object



16
17
18
# File 'lib/pg_export/ftp/adapter.rb', line 16

def delete(filename)
  ftp.delete(filename)
end

#ftpObject



28
29
30
# File 'lib/pg_export/ftp/adapter.rb', line 28

def ftp
  connection.ftp
end

#get(path, timestamped_name) ⇒ Object



24
25
26
# File 'lib/pg_export/ftp/adapter.rb', line 24

def get(path, timestamped_name)
  ftp.getbinaryfile(timestamped_name, path, CHUNK_SIZE)
end

#list(regex_string) ⇒ Object



12
13
14
# File 'lib/pg_export/ftp/adapter.rb', line 12

def list(regex_string)
  ftp.list(regex_string).map { |item| item.split(' ').last }.sort.reverse
end

#persist(path, timestamped_name) ⇒ Object



20
21
22
# File 'lib/pg_export/ftp/adapter.rb', line 20

def persist(path, timestamped_name)
  ftp.putbinaryfile(path, timestamped_name, CHUNK_SIZE)
end

#to_sObject



32
33
34
# File 'lib/pg_export/ftp/adapter.rb', line 32

def to_s
  host
end