Sha256: bf6477d4b83fda031f769ab1c1d0bf2a9bbb07407961b3c695340d7c51ccec17

Contents?: true

Size: 831 Bytes

Versions: 2

Compression:

Stored size: 831 Bytes

Contents

class PgExport
  module Ftp
    class Adapter
      CHUNK_SIZE = (2**16).freeze

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

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

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

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

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

      def ftp
        connection.ftp
      end

      def to_s
        host
      end

      private

      attr_reader :connection, :host
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pg_export-0.6.1 lib/pg_export/ftp/adapter.rb
pg_export-0.6.0 lib/pg_export/ftp/adapter.rb