Class: Imap::Backup::CLI::Backup
- Inherits:
-
Thor
- Object
- Thor
- Imap::Backup::CLI::Backup
- Includes:
- Helpers, Thor::Actions
- Defined in:
- lib/imap/backup/cli/backup.rb
Overview
Runs backups of configured accounts
Constant Summary
Constants included from Helpers
Helpers::NAMESPACE_CONFIGURATION_DESCRIPTION
Instance Method Summary collapse
-
#initialize(options) ⇒ Backup
constructor
A new instance of Backup.
- #run ⇒ void
Methods included from Helpers
#account, included, #load_config, #requested_accounts
Constructor Details
#initialize(options) ⇒ Backup
Returns a new instance of Backup.
22 23 24 25 |
# File 'lib/imap/backup/cli/backup.rb', line 22 def initialize() super([]) @options = end |
Instance Method Details
#run ⇒ void
This method returns an undefined value.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/imap/backup/cli/backup.rb', line 29 no_commands do def run Logger.logger.debug "Loading configuration" config = load_config(**) exit_code = nil accounts = requested_accounts(config) # Filter to only include accounts available for backup accounts = accounts.select(&:available_for_backup?) if accounts.none? Logger.logger.warn "No matching accounts found to backup" return end Logger.logger.debug "Starting backup of #{accounts.count} accounts" accounts.each do |account| backup = Account::Backup.new(account: account, refresh: refresh) backup.run rescue StandardError => e exit_code ||= choose_exit_code(e) = <<~ERROR Backup for account '#{account.username}' failed with error #{e} #{e.backtrace.join("\n")} ERROR Logger.logger.error next end Logger.logger.debug "Backup complete" exit(exit_code) if exit_code end end |