Class: KamalBackup::Config::DatabaseSource
- Inherits:
-
Object
- Object
- KamalBackup::Config::DatabaseSource
- Defined in:
- lib/kamal_backup/config.rb
Constant Summary collapse
- CONNECTION_KEYS =
%w[ DATABASE_URL SQLITE_DATABASE_PATH PGHOST PGPORT PGUSER PGPASSWORD PGDATABASE PGSSLMODE PGSSLROOTCERT PGSSLCERT PGSSLKEY PGCONNECT_TIMEOUT PGSERVICE PGPASSFILE MYSQL_HOST MYSQL_PORT MYSQL_USER MYSQL_PWD MYSQL_PASSWORD MYSQL_DATABASE MARIADB_HOST MARIADB_PORT MARIADB_USER MARIADB_PASSWORD MARIADB_DATABASE ].freeze
Instance Attribute Summary collapse
-
#missing_secrets ⇒ Object
readonly
Returns the value of attribute missing_secrets.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #app_name ⇒ Object
- #database_adapter ⇒ Object
- #database_name ⇒ Object
-
#initialize(parent:, name:, adapter:, env:, structured:, missing_secrets: []) ⇒ DatabaseSource
constructor
A new instance of DatabaseSource.
- #required_value(key) ⇒ Object
- #validate_database_restore_target(target) ⇒ Object
- #validate_local_database_restore_target(target) ⇒ Object
- #value(key) ⇒ Object
Constructor Details
#initialize(parent:, name:, adapter:, env:, structured:, missing_secrets: []) ⇒ DatabaseSource
Returns a new instance of DatabaseSource.
55 56 57 58 59 60 61 62 |
# File 'lib/kamal_backup/config.rb', line 55 def initialize(parent:, name:, adapter:, env:, structured:, missing_secrets: []) @parent = parent @name = name.to_s @adapter = adapter @env = env.transform_keys(&:to_s) @structured = structured @missing_secrets = Array(missing_secrets) end |
Instance Attribute Details
#missing_secrets ⇒ Object (readonly)
Returns the value of attribute missing_secrets.
53 54 55 |
# File 'lib/kamal_backup/config.rb', line 53 def missing_secrets @missing_secrets end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
53 54 55 |
# File 'lib/kamal_backup/config.rb', line 53 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
53 54 55 |
# File 'lib/kamal_backup/config.rb', line 53 def parent @parent end |
Instance Method Details
#app_name ⇒ Object
64 65 66 |
# File 'lib/kamal_backup/config.rb', line 64 def app_name parent.app_name end |
#database_adapter ⇒ Object
72 73 74 |
# File 'lib/kamal_backup/config.rb', line 72 def database_adapter @adapter end |
#database_name ⇒ Object
68 69 70 |
# File 'lib/kamal_backup/config.rb', line 68 def database_name name.empty? ? 'app' : name end |
#required_value(key) ⇒ Object
90 91 92 |
# File 'lib/kamal_backup/config.rb', line 90 def required_value(key) value(key) || raise(ConfigurationError, "#{key} is required for database #{database_name}") end |
#validate_database_restore_target(target) ⇒ Object
94 95 96 |
# File 'lib/kamal_backup/config.rb', line 94 def validate_database_restore_target(target) parent.validate_database_restore_target(target) end |
#validate_local_database_restore_target(target) ⇒ Object
98 99 100 |
# File 'lib/kamal_backup/config.rb', line 98 def validate_local_database_restore_target(target) parent.validate_local_database_restore_target(target) end |
#value(key) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/kamal_backup/config.rb', line 76 def value(key) raw = if @env.key?(key) @env[key] elsif @structured && CONNECTION_KEYS.include?(key) nil else parent.value(key) end stripped = raw.to_s.strip stripped.empty? ? nil : stripped end |