Class: Imap::Backup::Account::FolderMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/account/folder_mapper.rb

Overview

Implements a folder enumerator for backed-up accounts

Instance Method Summary collapse

Constructor Details

#initialize(account:, destination:, destination_delimiter: "/", destination_prefix: "", source_delimiter: "/", source_prefix: "") ⇒ FolderMapper

Returns a new instance of FolderMapper.

Parameters:

  • account (Account)

    the account whose local folders are being iterated

  • destination (Account)

    the destination account

  • destination_delimiter (String) (defaults to: "/")

    the delimiter to use for destination folder names

  • destination_prefix (String) (defaults to: "")

    a prefix applied to destination folder names

  • source_delimiter (String) (defaults to: "/")

    the delimiter used in the source account

  • source_prefix (String) (defaults to: "")

    a prefix applied to source folder names



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/imap/backup/account/folder_mapper.rb', line 20

def initialize(
  account:,
  destination:,
  destination_delimiter: "/",
  destination_prefix: "",
  source_delimiter: "/",
  source_prefix: ""
)
  @account = 
  @destination = destination
  @destination_delimiter = destination_delimiter
  @destination_prefix = destination_prefix
  @source_delimiter = source_delimiter
  @source_prefix = source_prefix
end

Instance Method Details

#each {|serializer, folder| ... } ⇒ Enumerator, void

Enumerates backed-up folders When called without a block, returns an Enumerator

Yield Parameters:

Returns:

  • (Enumerator, void)


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/imap/backup/account/folder_mapper.rb', line 41

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

  glob = File.join(source_local_path, "**", "*.imap")
  Pathname.glob(glob) do |path|
    name = source_folder_name(path)
    serializer = Serializer.new(source_local_path, name)
    folder = destination_folder_for_path(name)
    block.call(serializer, folder)
  end
end