Class: Pgchief::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/pgchief/config.rb,
lib/pgchief/config/s3.rb

Overview

Class to store configuration settings

Defined Under Namespace

Classes: S3

Constant Summary collapse

DEFAULT_CONFIG =
"#{Dir.home}/.config/pgchief/config.toml".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.backup_dirObject

Returns the value of attribute backup_dir.



20
21
22
# File 'lib/pgchief/config.rb', line 20

def backup_dir
  @backup_dir
end

.credentials_fileObject

Returns the value of attribute credentials_file.



20
21
22
# File 'lib/pgchief/config.rb', line 20

def credentials_file
  @credentials_file
end

.pgurlObject

explicitly define getter so that pgurl is always available if load_config! is not run.



28
29
30
# File 'lib/pgchief/config.rb', line 28

def pgurl
  ENV.fetch('DATABASE_URL', ENV.fetch('DB_URL', @pgurl))
end

.remote_backupObject

Returns the value of attribute remote_backup.



11
12
13
# File 'lib/pgchief/config.rb', line 11

def remote_backup
  @remote_backup
end

.remote_restoreObject

Returns the value of attribute remote_restore.



11
12
13
# File 'lib/pgchief/config.rb', line 11

def remote_restore
  @remote_restore
end

.s3_keyObject

Returns the value of attribute s3_key.



11
12
13
# File 'lib/pgchief/config.rb', line 11

def s3_key
  @s3_key
end

.s3_objects_pathObject

Returns the value of attribute s3_objects_path.



20
21
22
# File 'lib/pgchief/config.rb', line 20

def s3_objects_path
  @s3_objects_path
end

.s3_regionObject

Returns the value of attribute s3_region.



11
12
13
# File 'lib/pgchief/config.rb', line 11

def s3_region
  @s3_region
end

.s3_secretObject

Returns the value of attribute s3_secret.



11
12
13
# File 'lib/pgchief/config.rb', line 11

def s3_secret
  @s3_secret
end

.toml_fileObject (readonly)

Returns the value of attribute toml_file.



20
21
22
# File 'lib/pgchief/config.rb', line 20

def toml_file
  @toml_file
end

Class Method Details

.load_config!(params, toml_file = DEFAULT_CONFIG) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pgchief/config.rb', line 32

def load_config!(params, toml_file = DEFAULT_CONFIG)
  @toml_file            = toml_file
  config                = toml_config || env_config
  self.backup_dir       = config[:backup_dir]
  self.credentials_file = config[:credentials_file]
  self.pgurl            = config[:pgurl]
  self.s3_key           = config[:s3_key]
  self.s3_secret        = config[:s3_secret]
  self.s3_region        = config[:s3_region]
  self.s3_objects_path  = config[:s3_objects_path] || config[:s3_path_prefix]
  self.remote_restore   = params[:'remote-restore'] == true ||
                          params[:'local-restore'] == false ||
                          config[:remote_restore]
  self.remote_backup    = params[:'remote-backup']  == true ||
                          params[:'local-backup'] == false ||
                          config[:remote_backup]
rescue Pgchief::Errors::ConfigMissingError
  puts config_missing_error(toml_file)
end

.s3Object



52
53
54
# File 'lib/pgchief/config.rb', line 52

def s3
  @s3 ||= Pgchief::Config::S3.new(self)
end

.set_up_file_structure!Object



68
69
70
71
72
73
# File 'lib/pgchief/config.rb', line 68

def set_up_file_structure!
  FileUtils.mkdir_p(backup_dir)
  return unless credentials_file && !File.exist?(credentials_file)

  FileUtils.touch(credentials_file)
end