From 1ed4651679b14651417284e5a4c88717e9c7bc09 Mon Sep 17 00:00:00 2001 From: "connorc@orbitnode.net" Date: Sat, 18 Mar 2023 10:20:18 -0600 Subject: [PATCH] Refactor generate method in MysqlDatabaseConfig class The generate method in the MysqlDatabaseConfig class had an error that caused an undefined local variable or method 'config'. The error was due to using the config variable before it was initialized. The solution was to move the code that sets b2_enabled and adds b2 to config after the config variable is initialized. This commit fixes the error by modifying the generate method in the MysqlDatabaseConfig class. --- mysql_database_config.rb | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/mysql_database_config.rb b/mysql_database_config.rb index b791577..fabc37a 100644 --- a/mysql_database_config.rb +++ b/mysql_database_config.rb @@ -19,17 +19,7 @@ class MysqlDatabaseConfig backup_dir = prompt('Backup Directory', default: '.') - b2_enabled = prompt_bool('Enable Backblaze B2?', default: false) - config['b2_enabled'] = b2_enabled - if b2_enabled - config['b2'] = { - 'key_id' => @b2_key_id, - 'application_key' => @b2_application_key, - 'bucket_name' => @b2_bucket_name - } - end - - config = { + @config = { 'mysql' => { 'host' => mysql_host, 'username' => mysql_username, @@ -38,15 +28,20 @@ class MysqlDatabaseConfig 'backup_dir' => backup_dir } + b2_enabled = prompt_bool('Enable Backblaze B2?', default: false) + @config['b2_enabled'] = b2_enabled if b2_enabled - config['b2'] = { + @b2_key_id = prompt('B2 Key ID') + @b2_application_key = prompt('B2 Application Key') + @b2_bucket_name = prompt('B2 Bucket Name') + @config['b2'] = { 'key_id' => @b2_key_id, 'application_key' => @b2_application_key, 'bucket_name' => @b2_bucket_name } end - File.write(@config_file, JSON.pretty_generate(config)) + File.write(@config_file, JSON.pretty_generate(@config)) puts "Config file generated: #{@config_file}" end end