Sha256: fd3bfc3610d0d538a715d17f6d7b3e32535cee9da1ae20fd5c615823ede527fe

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

require 'ostruct'
require 'fileutils'
require 'json'
require 'yaml'
require 'time'

require 'mysql_backup/extensions'

module MysqlBackup
	class BackupConfig
		def initialize(config)
			@config = config
			_validate!
		end

		def self.load_from(path)
			data = YAML.load_file(path)
			BackupConfig.new data
		end

		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

		def server
			@config['server']
		end

		def username
			@config['username'] || (app_config? ? AppConfig.db[:username] : nil)
		end

		def password
			pw = @config['password'] || (app_config? ? AppConfig.db[:password] : nil)
			return nil if pw.nil? || pw.strip == ''
			return pw
		end

		def database
			@config['database']
		end

		def password?
			!password.nil?
		end

		def tables
			Array.from @config['tables']
		end

		def save_to
			return ['.'] if @config['save_to'].nil?
			Array.from @config['save_to']
		end

		def app_config?
			!!defined?(AppConfig) && !AppConfig.nil? && !AppConfig.db.nil? && AppConfig.db[:database] == self.database
		end

	end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mysql_backups-1.1.4 lib/mysql_backup/backup_config.rb
mysql_backups-1.1.2 lib/mysql_backup/backup_config.rb
mysql_backups-1.1.0 lib/mysql_backup/backup_config.rb