Sha256: d47dec4d8a0b1ad6da0cae7b27a105d142cb516df35fe64e3ea43ecd35790946

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Imap::Backup
  module Configuration; end

  class Configuration::List
    attr_reader :required_accounts

    def initialize(required_accounts = nil)
      @required_accounts = required_accounts
    end

    def setup_logging
      return if !config_exists?

      Imap::Backup.setup_logging config
      Net::IMAP.debug = config.debug?
    end

    def each_connection
      accounts.each do |account|
        connection = Account::Connection.new(account)
        yield connection
        connection.disconnect
      end
    end

    private

    def config
      return @config if @config

      if !config_exists?
        path = Configuration::Store.default_pathname
        raise ConfigurationNotFound, "Configuration file '#{path}' not found"
      end
      @config = Configuration::Store.new
    end

    def config_exists?
      Configuration::Store.exist?
    end

    def accounts
      @accounts ||=
        if required_accounts.nil?
          config.accounts
        else
          config.accounts.select do |account|
            required_accounts.include?(account[:username])
          end
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
imap-backup-3.4.1 lib/imap/backup/configuration/list.rb