Class: Imap::Backup::Account::BackupFolders

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/imap/backup/account/backup_folders.rb

Overview

Iterates over the account folders that are to be backed up

Instance Method Summary collapse

Constructor Details

#initialize(client:, account:) ⇒ BackupFolders

Returns a new instance of BackupFolders.



12
13
14
15
# File 'lib/imap/backup/account/backup_folders.rb', line 12

def initialize(client:, account:)
  @client = client
  @account = 
end

Instance Method Details

#each(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/imap/backup/account/backup_folders.rb', line 17

def each(&block)
  return enum_for(:each) if !block

  all_names = client.list

  configured =
    case
    when .folders&.any?
      .folders
    when .folder_blacklist
      []
    else
      all_names
    end

  names =
    if .folder_blacklist
      all_names - configured
    else
      all_names & configured
    end

  names.each { |name| block.call(Account::Folder.new(client, name)) }
end

#map(&block) ⇒ Object



42
43
44
45
46
# File 'lib/imap/backup/account/backup_folders.rb', line 42

def map(&block)
  each.map do |folder|
    block.call(folder)
  end
end