Sha256: 7dd71e323c1b0b01d7053a085aeb35987053faf0049cdbe0d8a8ac5f29da377a

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require 'dry-types'
require 'dry-struct'

class PgExport
  class Configuration < Dry::Struct
    include Dry::Types.module

    attribute :dump_encryption_key, Strict::String.constrained(size: 16)
    attribute :ftp_host,            Strict::String
    attribute :ftp_user,            Strict::String
    attribute :ftp_password,        Strict::String
    attribute :logger_format,       Coercible::String.enum('plain', 'timestamped', 'muted')
    attribute :keep_dumps,          Coercible::Integer.constrained(gteq: 0)

    def self.build(env)
      new(
        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'],
        logger_format: env['LOGGER_FORMAT'] || 'plain',
        keep_dumps: env['KEEP_DUMPS'] || 10
      )
    rescue Dry::Struct::Error => e
      raise PgExport::InitializationError, e.message.gsub('[PgExport::Configuration.new] ', '')
    end

    def logger_muted?
      logger_format == 'muted'
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pg_export-0.7.4 lib/pg_export/configuration.rb
pg_export-0.7.3 lib/pg_export/configuration.rb
pg_export-0.7.2 lib/pg_export/configuration.rb
pg_export-0.7.1 lib/pg_export/configuration.rb
pg_export-0.7.0 lib/pg_export/configuration.rb