Sha256: dd67cc9e3cec88a59275e25fac97052a1d2089af356a5a4733f5ba4506d895db

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

class PgExport
  class Configuration
    DEFAULTS = {
      database: nil,
      keep_dumps: ENV['KEEP_DUMPS'] || 10,
      dump_encryption_key: ENV['DUMP_ENCRYPTION_KEY'],
      ftp_host: ENV['BACKUP_FTP_HOST'],
      ftp_user: ENV['BACKUP_FTP_USER'],
      ftp_password: ENV['BACKUP_FTP_PASSWORD']
    }.freeze

    attr_accessor *DEFAULTS.keys

    def initialize
      DEFAULTS.each_pair do |key, value|
        send("#{key}=", value)
      end
    end

    def validate
      DEFAULTS.keys.each do |field|
        raise InvalidConfigurationError, "Field #{field} is required" if send(field).nil?
      end
      raise InvalidConfigurationError, 'Dump password is to short. It should have at least 16 characters' if dump_encryption_key.length < 16
    end

    def ftp_params
      {
        host: ftp_host,
        user: ftp_user,
        password: ftp_password
      }
    end

    def to_s
      DEFAULTS.keys.map(&method(:print_attr))
    end

    private

    def print_attr(key)
      if %i(ftp_password dump_encryption_key).include?(key)
        if send(key)
          "#{key}: #{send(key)[0..2]}***\n"
        else
          "#{key}:\n"
        end
      else
        "#{key}: #{send(key)}\n"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pg_export-0.4.1 lib/pg_export/configuration.rb
pg_export-0.4.0 lib/pg_export/configuration.rb