Sha256: 2693105a8e94ce8f11a9a2b55b9eb861233508a3dc85761e04e2154e837b6d80

Contents?: true

Size: 638 Bytes

Versions: 2

Compression:

Stored size: 638 Bytes

Contents

require 'open3'
require 'pg_export/errors'

class PgExport
  module Bash
    class Adapter
      def get(path, db_name)
        popen("pg_dump -Fc --file #{path} #{db_name}") do |errors|
          raise PgDumpError, errors unless errors.empty?
        end
      end

      def persist(path, db_name)
        popen("pg_restore -c -d #{db_name} #{path}") do |errors|
          raise PgRestoreError, errors if /FATAL/ =~ errors
        end
      end

      private

      def popen(command)
        Open3.popen3(command) do |_, _, err|
          errors = err.read
          yield errors
        end

        self
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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