Class: PgExport::Ftp::Adapter
- Inherits:
-
Object
- Object
- PgExport::Ftp::Adapter
- Defined in:
- lib/pg_export/ftp/adapter.rb
Constant Summary collapse
- CHUNK_SIZE =
(2**16).freeze
Instance Method Summary collapse
- #delete(filename) ⇒ Object
- #ftp ⇒ Object
- #get(path, timestamped_name) ⇒ Object
-
#initialize(connection:) ⇒ Adapter
constructor
A new instance of Adapter.
- #list(regex_string) ⇒ Object
- #persist(path, timestamped_name) ⇒ Object
- #to_s ⇒ Object
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 |
#ftp ⇒ Object
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, ) ftp.getbinaryfile(, 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, ) ftp.putbinaryfile(path, , CHUNK_SIZE) end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/pg_export/ftp/adapter.rb', line 32 def to_s host end |