Class: Pgchief::Config
- Inherits:
-
Object
- Object
- Pgchief::Config
- 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
-
.backup_dir ⇒ Object
Returns the value of attribute backup_dir.
-
.credentials_file ⇒ Object
Returns the value of attribute credentials_file.
-
.pgurl ⇒ Object
explicitly define getter so that pgurl is always available if load_config! is not run.
-
.remote_backup ⇒ Object
Returns the value of attribute remote_backup.
-
.remote_restore ⇒ Object
Returns the value of attribute remote_restore.
-
.s3_key ⇒ Object
Returns the value of attribute s3_key.
-
.s3_objects_path ⇒ Object
Returns the value of attribute s3_objects_path.
-
.s3_region ⇒ Object
Returns the value of attribute s3_region.
-
.s3_secret ⇒ Object
Returns the value of attribute s3_secret.
-
.toml_file ⇒ Object
readonly
Returns the value of attribute toml_file.
Class Method Summary collapse
- .load_config!(params, toml_file = DEFAULT_CONFIG) ⇒ Object
- .s3 ⇒ Object
- .set_up_file_structure! ⇒ Object
Class Attribute Details
.backup_dir ⇒ Object
Returns the value of attribute backup_dir.
20 21 22 |
# File 'lib/pgchief/config.rb', line 20 def backup_dir @backup_dir end |
.credentials_file ⇒ Object
Returns the value of attribute credentials_file.
20 21 22 |
# File 'lib/pgchief/config.rb', line 20 def credentials_file @credentials_file end |
.pgurl ⇒ Object
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_backup ⇒ Object
Returns the value of attribute remote_backup.
11 12 13 |
# File 'lib/pgchief/config.rb', line 11 def remote_backup @remote_backup end |
.remote_restore ⇒ Object
Returns the value of attribute remote_restore.
11 12 13 |
# File 'lib/pgchief/config.rb', line 11 def remote_restore @remote_restore end |
.s3_key ⇒ Object
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_path ⇒ Object
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_region ⇒ Object
Returns the value of attribute s3_region.
11 12 13 |
# File 'lib/pgchief/config.rb', line 11 def s3_region @s3_region end |
.s3_secret ⇒ Object
Returns the value of attribute s3_secret.
11 12 13 |
# File 'lib/pgchief/config.rb', line 11 def s3_secret @s3_secret end |
.toml_file ⇒ Object (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 |
.s3 ⇒ Object
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 |