Class: MysqlBackup::BackupConfig
- Inherits:
-
Object
- Object
- MysqlBackup::BackupConfig
- Defined in:
- lib/mysql_backup/backup_config.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_validate! ⇒ Object
- #app_config? ⇒ Boolean
- #database ⇒ Object
-
#initialize(config) ⇒ BackupConfig
constructor
A new instance of BackupConfig.
- #password ⇒ Object
- #password? ⇒ Boolean
- #save_to ⇒ Object
- #server ⇒ Object
- #tables ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(config) ⇒ BackupConfig
Returns a new instance of BackupConfig.
11 12 13 14 |
# File 'lib/mysql_backup/backup_config.rb', line 11 def initialize(config) @config = config _validate! end |
Class Method Details
.load_from(path) ⇒ Object
16 17 18 19 |
# File 'lib/mysql_backup/backup_config.rb', line 16 def self.load_from(path) data = YAML.load_file(path) BackupConfig.new data end |
Instance Method Details
#_validate! ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/mysql_backup/backup_config.rb', line 21 def _validate! raise 'config object required' if @config.nil? raise 'server required' if server.nil? raise 'username required' if username.nil? raise 'database required' if database.nil? raise 'backup destination required' if save_to.nil? end |
#app_config? ⇒ Boolean
60 61 62 |
# File 'lib/mysql_backup/backup_config.rb', line 60 def app_config? !!defined?(AppConfig) && !AppConfig.nil? && !AppConfig.db.nil? && AppConfig.db[:database] == self.database end |
#database ⇒ Object
43 44 45 |
# File 'lib/mysql_backup/backup_config.rb', line 43 def database @config['database'] end |
#password ⇒ Object
37 38 39 40 41 |
# File 'lib/mysql_backup/backup_config.rb', line 37 def password pw = @config['password'] || (app_config? ? AppConfig.db[:password] : nil) return nil if pw.nil? || pw.strip == '' return pw end |
#password? ⇒ Boolean
47 48 49 |
# File 'lib/mysql_backup/backup_config.rb', line 47 def password? !password.nil? end |
#save_to ⇒ Object
55 56 57 58 |
# File 'lib/mysql_backup/backup_config.rb', line 55 def save_to return ['.'] if @config['save_to'].nil? Array.from @config['save_to'] end |
#server ⇒ Object
29 30 31 |
# File 'lib/mysql_backup/backup_config.rb', line 29 def server @config['server'] end |
#tables ⇒ Object
51 52 53 |
# File 'lib/mysql_backup/backup_config.rb', line 51 def tables Array.from @config['tables'] end |
#username ⇒ Object
33 34 35 |
# File 'lib/mysql_backup/backup_config.rb', line 33 def username @config['username'] || (app_config? ? AppConfig.db[:username] : nil) end |