Module: Imap::Backup::CLI::Helpers
- Included in:
- Imap::Backup::CLI, Backup, Local, Local::Check, Remote, Restore, Setup, Single, Stats, Transfer, Utils
- Defined in:
- lib/imap/backup/cli/helpers.rb
Overview
Provides helper methods for CLI classes
Class Method Summary collapse
Instance Method Summary collapse
-
#account(config, email) ⇒ Account
The Account information for the email address.
-
#load_config(**options) ⇒ Configuration
Loads the application configuration.
-
#options ⇒ Hash
Processes command-line parameters.
-
#requested_accounts(config) ⇒ Array<Account>
If email addresses have been specified returns the Account configurations for them.
Class Method Details
Instance Method Details
#account(config, email) ⇒ Account
Returns the Account information for the email address.
57 58 59 60 61 62 |
# File 'lib/imap/backup/cli/helpers.rb', line 57 def account(config, email) account = config.accounts.find { |a| a.username == email } raise "#{email} is not a configured account" if !account account end |
#load_config(**options) ⇒ Configuration
Loads the application configuration
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/imap/backup/cli/helpers.rb', line 42 def load_config(**) path = [:config] require_exists = .key?(:require_exists) ? [:require_exists] : true if require_exists exists = Configuration.exist?(path: path) if !exists expected = path || Configuration.default_pathname raise ConfigurationNotFound, "Configuration file '#{expected}' not found" end end Configuration.new(path: path) end |
#options ⇒ Hash
Processes command-line parameters
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/imap/backup/cli/helpers.rb', line 23 def @symbolized_options ||= # rubocop:disable Naming/MemoizedInstanceVariableName begin = super .each.with_object({}) do |(k, v), acc| key = if k.is_a?(String) k.gsub("-", "_").intern else k end acc[key] = v end end end |
#requested_accounts(config) ⇒ Array<Account>
If email addresses have been specified returns the Account configurations for them. If non have been specified, returns all account configurations
67 68 69 70 71 72 73 74 |
# File 'lib/imap/backup/cli/helpers.rb', line 67 def requested_accounts(config) emails = ([:accounts] || "").split(",") if emails.any? config.accounts.filter { |a| emails.include?(a.username) } else config.accounts end end |