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

Instance Method Summary collapse

Instance Method Details

#account(config, email) ⇒ Object



105
106
107
108
109
110
# File 'lib/imap/backup/cli/helpers.rb', line 105

def (config, email)
   = config.accounts.find { |a| a.username == email }
  raise "#{email} is not a configured account" if !

  
end

#load_config(**options) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/imap/backup/cli/helpers.rb', line 92

def load_config(**options)
  path = options[:config]
  require_exists = options.key?(:require_exists) ? options[: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

#optionsObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/imap/backup/cli/helpers.rb', line 76

def options
  @symbolized_options ||= # rubocop:disable Naming/MemoizedInstanceVariableName
    begin
      options = super()
      options.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) ⇒ Object



112
113
114
115
116
117
118
119
# File 'lib/imap/backup/cli/helpers.rb', line 112

def requested_accounts(config)
  emails = (options[:accounts] || "").split(",")
  if emails.any?
    config.accounts.filter { |a| emails.include?(a.username) }
  else
    config.accounts
  end
end