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.
86 87 88 89 90 91 92 93 |
# File 'lib/kamal_backup/config.rb', line 86 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.
84 85 86 |
# File 'lib/kamal_backup/config.rb', line 84 def missing_secrets @missing_secrets end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
84 85 86 |
# File 'lib/kamal_backup/config.rb', line 84 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
84 85 86 |
# File 'lib/kamal_backup/config.rb', line 84 def parent @parent end |
Instance Method Details
#app_name ⇒ Object
95 96 97 |
# File 'lib/kamal_backup/config.rb', line 95 def app_name parent.app_name end |
#database_adapter ⇒ Object
103 104 105 |
# File 'lib/kamal_backup/config.rb', line 103 def database_adapter @adapter || parent.send(:legacy_database_adapter) end |
#database_name ⇒ Object
99 100 101 |
# File 'lib/kamal_backup/config.rb', line 99 def database_name name.empty? ? "app" : name end |
#required_value(key) ⇒ Object
121 122 123 |
# File 'lib/kamal_backup/config.rb', line 121 def required_value(key) value(key) || raise(ConfigurationError, "#{key} is required for database #{database_name}") end |
#validate_database_restore_target(target) ⇒ Object
125 126 127 |
# File 'lib/kamal_backup/config.rb', line 125 def validate_database_restore_target(target) parent.validate_database_restore_target(target) end |
#validate_local_database_restore_target(target) ⇒ Object
129 130 131 |
# File 'lib/kamal_backup/config.rb', line 129 def validate_local_database_restore_target(target) parent.validate_local_database_restore_target(target) end |
#value(key) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/kamal_backup/config.rb', line 107 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 |